Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustix recompiles every time switching between Intellij and CLI #562

Closed
howardjohn opened this issue Mar 10, 2023 · 12 comments
Closed

Rustix recompiles every time switching between Intellij and CLI #562

howardjohn opened this issue Mar 10, 2023 · 12 comments

Comments

@howardjohn
Copy link

This is maybe not even a rustix bug, but may help someone else seeing the same issue.

Rustix's build.rs has cargo:rerun-if-env-changed=RUSTC.

When I run cargo check from my terminal, I see RUSTC=rustc. When I run it from intellij, I get RUSTC=$HOME/.cargo/bin/rustc. This means each time the build is invalidated.

For now I am just doing export RUSTC=$HOME/.cargo/bin/rustc to work around this

@sunfishcode
Copy link
Member

Rustix needs to autodetect features from the rustc, in particular to know whether it can used OwnedFd from std or whether it needs to use its own copy. If it's possible that cargo check in your terminal could use a different version of rustc than what intellij uses, then rustix does need to rerun its build script.

Another consideration here is that intellij-rust/intellij-rust#10186 is a report where rustix may not be running its build script in a situation where it should. It's not yet clear what the problem is.

Also relevant in this space is that my earlier fix had a bug, which I'm now fixing in #563.

@sunfishcode
Copy link
Member

In Rust 1.68, cargo build --verbose now includes a Dirty message the indicates why it triggered a rebuild, which would be useful to see when this happens.

@Nutomic
Copy link

Nutomic commented Mar 29, 2023

Im have the same problem described in this issue, this is the output for rustix from cargo check --verbose:

Running `/usr/bin/sccache rustc --crate-name rustix --edition=2018 /home/felix/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustix-0.36.9/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=153 --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=0 --cfg 'feature="default"' --cfg 'feature="fs"' --cfg 'feature="io-lifetimes"' --cfg 'feature="libc"' --cfg 'feature="mm"' --cfg 'feature="std"' --cfg 'feature="use-libc-auxv"' -C metadata=fe6d77cbb4767f55 -C extra-filename=-fe6d77cbb4767f55 --out-dir /home/felix/workspace/webb/relayer/target/debug/deps -C strip=symbols -L dependency=/home/felix/workspace/webb/relayer/target/debug/deps --extern bitflags=/home/felix/workspace/webb/relayer/target/debug/deps/libbitflags-d53a0f852625ca18.rmeta --extern io_lifetimes=/home/felix/workspace/webb/relayer/target/debug/deps/libio_lifetimes-1327a00c9e419885.rmeta --extern libc=/home/felix/workspace/webb/relayer/target/debug/deps/liblibc-6ce3c9449f468f7a.rmeta --extern linux_raw_sys=/home/felix/workspace/webb/relayer/target/debug/deps/liblinux_raw_sys-d6534f431c32c99e.rmeta --cap-lints allow --cfg rustc_attrs --cfg linux_raw --cfg core_intrinsics --cfg asm`
Running `/usr/bin/sccache rustc --crate-name rustix --edition=2018 /home/felix/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustix-0.36.9/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=153 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no --cfg 'feature="default"' --cfg 'feature="fs"' --cfg 'feature="io-lifetimes"' --cfg 'feature="libc"' --cfg 'feature="mm"' --cfg 'feature="std"' --cfg 'feature="use-libc-auxv"' -C metadata=2b984a9b6c932294 -C extra-filename=-2b984a9b6c932294 --out-dir /home/felix/workspace/webb/relayer/target/debug/deps -C strip=symbols -L dependency=/home/felix/workspace/webb/relayer/target/debug/deps --extern bitflags=/home/felix/workspace/webb/relayer/target/debug/deps/libbitflags-c672ab23fb67ebd2.rmeta --extern io_lifetimes=/home/felix/workspace/webb/relayer/target/debug/deps/libio_lifetimes-c416a3d2a8a68533.rmeta --extern libc=/home/felix/workspace/webb/relayer/target/debug/deps/liblibc-f5cd561e13a0f6ad.rmeta --extern linux_raw_sys=/home/felix/workspace/webb/relayer/target/debug/deps/liblinux_raw_sys-bbd9f11733e8abe5.rmeta --cap-lints allow --cfg rustc_attrs --cfg linux_raw --cfg core_intrinsics --cfg asm`

@sunfishcode
Copy link
Member

@Nutomic Are you using Rust 1.68, which has the new Dirty output?

@OvermindDL1
Copy link

I am on:

❯ rustc --version
rustc 1.68.2 (9eb3afe9e 2023-03-27)

❯ cargo --version
cargo 1.68.2 (6feb7c9cf 2023-03-26)

And I'm constantly having this issue as well. Running cargo build --verbose and I see this Dirty message

Dirty rustix v0.37.4: the env variable RUSTC changed

Rustix version is 0.37.4 (required by is-terminal 0.4.6, which is required by anstream 0.2.6, which is required by clap_builder 4.2.0, which is required by clap 4.2.0, which is required by my projects).

Every time I cargo build it's having to recompile rustix.

@OvermindDL1
Copy link

Just for completion, here's the output of a cargo build --verbose that contains rustix on each line:

       Dirty rustix v0.37.4: the env variable RUSTC changed
   Compiling rustix v0.37.4
     Running `/home/overminddl1/rust/testing_constant_recompiling/target/debug/build/rustix-b26a51cba84e394d/build-script-build`
     Running `rustc --crate-name rustix --edition=2018 /home/overminddl1/.cargo/registry/src/github.com-1ecc6299db9ec823/rustix-0.37.4/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=132 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="io-lifetimes"' --cfg 'feature="libc"' --cfg 'feature="std"' --cfg 'feature="termios"' --cfg 'feature="use-libc-auxv"' -C metadata=60d941d26896765e -C extra-filename=-60d941d26896765e --out-dir /home/overminddl1/rust/testing_constant_recompiling/target/debug/deps -L dependency=/home/overminddl1/rust/testing_constant_recompiling/target/debug/deps --extern bitflags=/home/overminddl1/rust/testing_constant_recompiling/target/debug/deps/libbitflags-f255a966af175049.rmeta --extern io_lifetimes=/home/overminddl1/rust/testing_constant_recompiling/target/debug/deps/libio_lifetimes-0861c285f6a9ecc3.rmeta --extern libc=/home/overminddl1/rust/testing_constant_recompiling/target/debug/deps/liblibc-9de7ca31dbbda4df.rmeta --extern linux_raw_sys=/home/overminddl1/rust/testing_constant_recompiling/target/debug/deps/liblinux_raw_sys-10a54ce77ae265d4.rmeta --cap-lints allow --cfg linux_raw --cfg asm --cfg linux_like`

@OvermindDL1
Copy link

Also note, this happens between intellij and cli as well as rust-analyzer (via emacs) and cli.

@OvermindDL1
Copy link

Just testing an older version of rustix and it didn't have this issue, but rather if it was cargo clean'd first and then built in intellij then it would give errors about using nightly features on stable, yet worked when it was built in the cli first, which is odd as I don't even have the nightly compiler installed at all...

@OvermindDL1
Copy link

Just to remark on its impact, it's adding about 12.6s of time to running the tests (of which they themselves take less than 2 seconds), and this is every time they are run (which I do on-the-fly via cargo-watch), it's quite an added delay compared to the usual compiling time of just my code of less than 2 seconds to compile as well when rustix isn't recompiling.

sunfishcode added a commit that referenced this issue Mar 29, 2023
Now that we appear to have a known-working fix for #526, we can
investigate relaxing the fix. If #526 reappears, we now have a
known-working state we can quickly revert to.

Reports in #562 and #575 are that having rerun-if-env-changed=RUSTC
and rerun-if-env-changed=RUSTC_WRAPPER are triggering spurious rebuilds
in some situations, so remove these. In theory, cargo should already be
aware of these environment variables. In practice, there were reports of
build failures which had the appearance of using an older version of
rustc with build.rs output from a newer version of rustc, and it wasn't
clear what was happening. But, it's possible that #563 fixes the issue
properly. So let's try removing these rerun-if-env-changed lines, and
see if the problem resurfaces.

And, rerun-if-env-changed=TARGET is explicitly documented as being
unnecessary [here].

[here]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
sunfishcode added a commit that referenced this issue Mar 29, 2023
Now that we appear to have a known-working fix for #526, we can
investigate relaxing the fix. If #526 reappears, we now have a
known-working state we can quickly revert to.

Reports in #562 and #575 are that having rerun-if-env-changed=RUSTC
and rerun-if-env-changed=RUSTC_WRAPPER are triggering spurious rebuilds
in some situations, so remove these. In theory, cargo should already be
aware of these environment variables. In practice, there were reports of
build failures which had the appearance of using an older version of
rustc with build.rs output from a newer version of rustc, and it wasn't
clear what was happening. But, it's possible that #563 fixes the issue
properly. So let's try removing these rerun-if-env-changed lines, and
see if the problem resurfaces.

And, rerun-if-env-changed=TARGET is explicitly documented as being
unnecessary [here].

[here]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
@Nutomic
Copy link

Nutomic commented Mar 30, 2023

Are you using Rust 1.68, which has the new Dirty output?

Yes Im using 1.68.0

sunfishcode added a commit that referenced this issue May 19, 2023
Now that we appear to have a known-working fix for #526, we can
investigate relaxing the fix. If #526 reappears, we now have a
known-working state we can quickly revert to.

Reports in #562 and #575 are that having rerun-if-env-changed=RUSTC
and rerun-if-env-changed=RUSTC_WRAPPER are triggering spurious rebuilds
in some situations, so remove these. In theory, cargo should already be
aware of these environment variables. In practice, there were reports of
build failures which had the appearance of using an older version of
rustc with build.rs output from a newer version of rustc, and it wasn't
clear what was happening. But, it's possible that #563 fixes the issue
properly. So let's try removing these rerun-if-env-changed lines, and
see if the problem resurfaces.

And, rerun-if-env-changed=TARGET is explicitly documented as being
unnecessary [here].

[here]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
sunfishcode added a commit that referenced this issue May 19, 2023
Now that we appear to have a known-working fix for #526, we can
investigate relaxing the fix. If #526 reappears, we now have a
known-working state we can quickly revert to.

Reports in #562 and #575 are that having rerun-if-env-changed=RUSTC
and rerun-if-env-changed=RUSTC_WRAPPER are triggering spurious rebuilds
in some situations, so remove these. In theory, cargo should already be
aware of these environment variables. In practice, there were reports of
build failures which had the appearance of using an older version of
rustc with build.rs output from a newer version of rustc, and it wasn't
clear what was happening. But, it's possible that #563 fixes the issue
properly. So let's try removing these rerun-if-env-changed lines, and
see if the problem resurfaces.

And, rerun-if-env-changed=TARGET is explicitly documented as being
unnecessary [here].

[here]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
@sunfishcode
Copy link
Member

I've now backported the #576 fix to the 0.36 branch, and made a 0.36.14 release with it. It's also in 0.37.5 and later 0.37 releases.

@sunfishcode
Copy link
Member

#576 seems to have fixed this, as I haven't heard of any further reports of this problem since then. If anyone does see this happen again, please file a new issue!

sunfishcode added a commit that referenced this issue Oct 12, 2023
Now that we appear to have a known-working fix for #526, we can
investigate relaxing the fix. If #526 reappears, we now have a
known-working state we can quickly revert to.

Reports in #562 and #575 are that having rerun-if-env-changed=RUSTC
and rerun-if-env-changed=RUSTC_WRAPPER are triggering spurious rebuilds
in some situations, so remove these. In theory, cargo should already be
aware of these environment variables. In practice, there were reports of
build failures which had the appearance of using an older version of
rustc with build.rs output from a newer version of rustc, and it wasn't
clear what was happening. But, it's possible that #563 fixes the issue
properly. So let's try removing these rerun-if-env-changed lines, and
see if the problem resurfaces.

And, rerun-if-env-changed=TARGET is explicitly documented as being
unnecessary [here].

[here]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
sunfishcode added a commit that referenced this issue Oct 12, 2023
Now that we appear to have a known-working fix for #526, we can
investigate relaxing the fix. If #526 reappears, we now have a
known-working state we can quickly revert to.

Reports in #562 and #575 are that having rerun-if-env-changed=RUSTC
and rerun-if-env-changed=RUSTC_WRAPPER are triggering spurious rebuilds
in some situations, so remove these. In theory, cargo should already be
aware of these environment variables. In practice, there were reports of
build failures which had the appearance of using an older version of
rustc with build.rs output from a newer version of rustc, and it wasn't
clear what was happening. But, it's possible that #563 fixes the issue
properly. So let's try removing these rerun-if-env-changed lines, and
see if the problem resurfaces.

And, rerun-if-env-changed=TARGET is explicitly documented as being
unnecessary [here].

[here]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
sunfishcode added a commit that referenced this issue Oct 12, 2023
Now that we appear to have a known-working fix for #526, we can
investigate relaxing the fix. If #526 reappears, we now have a
known-working state we can quickly revert to.

Reports in #562 and #575 are that having rerun-if-env-changed=RUSTC
and rerun-if-env-changed=RUSTC_WRAPPER are triggering spurious rebuilds
in some situations, so remove these. In theory, cargo should already be
aware of these environment variables. In practice, there were reports of
build failures which had the appearance of using an older version of
rustc with build.rs output from a newer version of rustc, and it wasn't
clear what was happening. But, it's possible that #563 fixes the issue
properly. So let's try removing these rerun-if-env-changed lines, and
see if the problem resurfaces.

And, rerun-if-env-changed=TARGET is explicitly documented as being
unnecessary [here].

[here]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
sunfishcode added a commit that referenced this issue Oct 12, 2023
Now that we appear to have a known-working fix for #526, we can
investigate relaxing the fix. If #526 reappears, we now have a
known-working state we can quickly revert to.

Reports in #562 and #575 are that having rerun-if-env-changed=RUSTC
and rerun-if-env-changed=RUSTC_WRAPPER are triggering spurious rebuilds
in some situations, so remove these. In theory, cargo should already be
aware of these environment variables. In practice, there were reports of
build failures which had the appearance of using an older version of
rustc with build.rs output from a newer version of rustc, and it wasn't
clear what was happening. But, it's possible that #563 fixes the issue
properly. So let's try removing these rerun-if-env-changed lines, and
see if the problem resurfaces.

And, rerun-if-env-changed=TARGET is explicitly documented as being
unnecessary [here].

[here]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants