-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
The no-op always-success RUSTC_WRAPPER breaks build scripts #12973
Comments
This was never reported before. Skimming Specifically about It would be nice for |
This wrapper might also be responsible for rust-lang/rust#99538; at least I have not seen that problem since I disabled proc macros and build scripts.
Oh, good point. anyhow was specifically asked to use RUSTC_WRAPPER in dtolnay/anyhow#157. And I tend to agree with the author that using RUSTC_WRAPPER is more correct. But neither eyre nor autocfg are using RUSTC_WRAPPER so they happen to not hit this problem. I think that is an accident though, and arguments could be made that they should use RUSTC_WRAPPER.
Well, the probe needs updating to latest nightly, yeah. And soon the feature will be stable and this will only be relevant for old compilers. But that doesn't really help with the general problem. |
One solution might be to detect nested invocations of our wrapper: if we're not the outer one, we could pass through the call to |
Build scripts don't cause nested invocations of the wrapper. |
Doesn't the |
Yes, it does. |
Anyhow's build script invokes the wrapper, but the build script doesn't run underneath the wrapper, but directly under cargo. As such the wrapper invocation is not nested within the wrapper. |
Am I missing something here?
|
That is correct. But how do we detect that anyhow's build script invoked the wrapper rather than cargo itself? Both use pretty much the same env vars and because at step 4 the wrapper isn't used to run the build script, we can't set an env var either to signal that a build script ran rustc with the wrapper as opposed to cargo. |
Can't we set |
How do you make sure that it doesn't run for rustc invoked by cargo then? |
I think we can check env vars like |
Yeah, fundamentally this is a hack to work-around not being able to tell cargo what you really want to do. Is that being tracked on the cargo side somewhere, are the cargo devs aware of this? |
Hmm...
I suppose not, but a request for |
We could use a file to pass information from one invocation to another, but I don't think we can figure out when all the build scripts finished compiling (multiple crates in the workspace might have one). Adding @vlad20012, since IntelliJ Rust might be interested in this too. |
In #12973 (comment) I suggested checking NUM_JOBS or PROFILE. Those are only set for build scripts. |
Hi! This issue is not the only problem with RUSTC_WRAPPER approach. A more common problem that I run into regularly - cargo stops the build immediately if one rustc instance or buildscript instance fails, even if it would be possible to compile other crates that does not depends on the error crate. Consider a project that has a buildscript in its workspace that compiles some C dependency using GCC, and also uses a bunch of proc macros. When a user downloads this project and opens it in an IDE, the IDE invokes |
There is the unstable |
Wow, this seems like exactly what we need! |
Use `--keep-going` cargo flag when building build scripts See #12973 (comment)
🤔 I think |
A quick test seems to not really change the times for me when running with and without the wrapper (though that might be because |
I think it's going to matter a lot for people who disable |
Opened a zulip topic in the t-cargo stream to see if we can work on this from the cargo side of things as our own options here are rather limited and to me it sounds like it would make more sense to just push rust-lang/cargo#7178 forward |
#12973 (comment) sounds the most promising to me. Here are Cargo's build script environment variables: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts. The criteria for selecting one for this purpose are:
These are the ones that I see fit the bill:
So the plan would be for rustc_wrapper.rs to do its early return thing only if |
Picking one of the |
PR #13010 is up, though I can't test whether it works as I am actually not running into the issue with |
This comment was marked as duplicate.
This comment was marked as duplicate.
This has been fixed by #13010. |
9235: Do not unconditionally succeed RUSTC_WRAPPER when run by build scripts r=Undin a=vlad20012 Fixes #9198, fixes #9227. Based on rust-lang/rust-analyzer#13010 and discussion in rust-lang/rust-analyzer#12973. intellij-rust-native-helper in `RUSTC_WRAPPER` role unconditionally succeeds `cargo check` invocations tripping up build scripts using `cargo check` to probe for successful compilations. To prevent this from happening the `RUSTC_WRAPPER` now checks if it's run from a build script by looking for the `CARGO_CFG_TARGET_ARCH` env var that cargo sets only when running build scripts. changelog: Fix broken `anyhow` compilation when `org.rust.cargo.evaluate.build.scripts` [experimental feature](https://plugins.jetbrains.com/plugin/8182-rust/docs/rust-faq.html#experimental-features) is enabled Co-authored-by: vlad20012 <[email protected]>
It is not an uncommon pattern for build scripts to invoke rustc to detect whether some features are available. Popular crates like anyhow and eyre do that, and the autocfg crate (14 million "recent" downloads, >100 million all-time downloads) even provides a convenient interface to write such build scripts.
RA entirely breaks that by having a RUSTC_WRAPPER that always returns success. I think that is a bug in RA.
The text was updated successfully, but these errors were encountered: