-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Inform build scripts of rustc compiler context #9601
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
Tests and documentation coming shortly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How feasible would it be to fold all of this into the existing RUSTC
env var? Cargo can emit a wrapper script that functions like rustc but passes the right additional rustc flags to the right rustc wrapper. Basically I would prefer if all existing uses of Command::new(var_os("RUSTC").unwrap())
could just work correctly, without needing additional logic to handle two more env vars.
Pseudocode when Cargo's caller invokes Cargo with CARGO_BUILD_RUSTC_WRAPPER=/path/to/wrapper
and CARGO_BUILD_RUSTFLAGS=--foo
:
#!/bin/bash
/path/to/wrapper /path/to/rustc --foo "$@"
Then Cargo would make the env::var_os("RUSTC")
seen by the build script refer to this wrapper script.
Yeah, I've wanted this too. My guess is that it's a bit of a pain since we'd need such a wrapper for every target. And furthermore, it likely shouldn't take any new dependencies (like |
I'm not sure which is the best way to go on this (generating a wrapper script vs just passing a bunch of env vars). I've got some experience with the Basically I think there's two possible routes for this:
I could see this going either way, personally, although naturally it's much easier from an implementation perspective to just pass down the components and let the build script to figure it out. I don't get the feeling that it's super common to want to invoke rustc with flags/wrappers that it's worth going out of our way to inject a wrapper script. You're right in that we naturally can't pick up |
I think my personal preference is the envvars, since it gives the recipient the choice of whether to use the flags or not. For example, I could maybe imagine an intermediate that wants to use RUSTC_WRAPPER, but not RUSTFLAGS. |
@dtolnay do you have reason to believe that reading |
Well certainly |
That serde build script makes me wonder how common it is to have a rustc wrapper that changes the Rust version that is available 🤔 |
Presumably though the logic that you're implementing for anyhow is already centralized in other crates like So, personally, I remain convinced that this should be communicated through separate env vars. I still feel, though, that the env vars should not have the |
Makes sense, I am on board with that. |
My hesitation with reusing unprefixed But if I must check the version, would you consider setting |
Oh I tried to address the trustworthiness part above, but I think it'd be fine to export version env vars too. We could even break it down into major/minor/patch most likely since we're already parsing with semver. |
Okay, I pushed two new commits that remove the |
Update cargo 6 commits in 27277d966b3cfa454d6dea7f724cb961c036251c..4e143fd131e0c16cefd008456e974236ca54e62e 2021-07-16 00:50:39 +0000 to 2021-07-20 21:55:45 +0000 - Named profile updates (rust-lang/cargo#9685) - Inform build scripts of rustc compiler context (rust-lang/cargo#9601) - Factor version preferences into a struct (rust-lang/cargo#9703) - docs: Fix sentence & update link for GitLab CI docs (rust-lang/cargo#9704) - Deduplicate compiler diagnostics. (rust-lang/cargo#9675) - Re-enable future-incompatible tests. (rust-lang/cargo#9698)
Update cargo 6 commits in 27277d966b3cfa454d6dea7f724cb961c036251c..4e143fd131e0c16cefd008456e974236ca54e62e 2021-07-16 00:50:39 +0000 to 2021-07-20 21:55:45 +0000 - Named profile updates (rust-lang/cargo#9685) - Inform build scripts of rustc compiler context (rust-lang/cargo#9601) - Factor version preferences into a struct (rust-lang/cargo#9703) - docs: Fix sentence & update link for GitLab CI docs (rust-lang/cargo#9704) - Deduplicate compiler diagnostics. (rust-lang/cargo#9675) - Re-enable future-incompatible tests. (rust-lang/cargo#9698)
Without this, environments that configure `RUSTFLAGS` or the `RUSTC_WRAPPER` in ways that break compilation with `backtrace` will fail to compile anyhow (see dtolnay#156). With this, the compiler probe takes into account that Cargo configuration, and thus (more) accurately represents whether the `backtrace` feature can be safely enabled. Requires rust-lang/cargo#9601, but does not break without. Fixes dtolnay#156.
Without this, environments that configure `RUSTFLAGS` or the `RUSTC_WRAPPER` in ways that break compilation with `backtrace` will fail to compile anyhow (see dtolnay#156). With this, the compiler probe takes into account that Cargo configuration, and thus (more) accurately represents whether the `backtrace` feature can be safely enabled. Requires rust-lang/cargo#9601, but does not break without. Fixes dtolnay#156.
159: build.rs: Migrate to CARGO_ENCODED_RUSTFLAGS r=stlankes a=mkroening Fixes #158. Cargo introduced `CARGO_ENCODED_RUSTFLAGS` in rust-lang/cargo#9601 to make setting flags less error prone – it encodes arguments separated by `0x1f` (ASCII Unit Separator), instead of white spaces (old `RUSTFLAGS`). `CARGO_ENCODED_RUSTFLAGS` are preferred over the old `RUSTFLAGS` in cargo. For build scripts, cargo converts its `RUSTFLAGS` to `CARGO_ENCODED_RUSTFLAGS`. For unset `RUSTFLAGS` it is set to an empty string. Thus our build script would call cargo for building libhermit-rs with a set – but empty – `CARGO_ENCODED_RUSTFLAGS`, which takes precedence over our prepared `RUSTFLAGS`. Specifically this caused our `-Zmutable-noalias=no` flag to be ignored, causing the same network issue as #128 again. This PR adjusts our build script to make direct use of `CARGO_ENCODED_RUSTFLAGS`, the new and preferred way of handling flags in build scripts. This causes our flags to be correctly handled again. Co-authored-by: Martin Kröning <mkroening@posteo.net>
@jonhoo or @alexcrichton, a problem came up with this in #10111 where this broke previous behavior, where RUSTFLAGS is no longer set at all. I didn't catch that, and was wondering what the reasoning was behind that change? |
Ah, so, Cargo never explicitly set So the short of it is that relying on |
Add note about RUSTFLAGS removal from build scripts. The RUSTFLAGS environment variable was removed from build scripts in #9601, but the release notes did not make a note of this change. This adds a highlight to this potentially breaking change.
Fixes #9600.