-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Overhaul RUSTFLAGS handling for compiler/
crates
#138035
Overhaul RUSTFLAGS handling for compiler/
crates
#138035
Conversation
Currently they are passed to the ones satisfying `Mode::Rustc` via RUSTFLAGS. But RUSTFLAGS is ignored for proc macro crates. This commit makes those flags get added directly to the command for proc macro crates.
And fix the new errors in the handful of crates that didn't have a `#![warn(unreachable_pub)]`.
It's no longer necessary now that `-Wunreachable_pub` is being passed.
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in exhaustiveness checking cc @Nadrieril
cc @davidtwco, @compiler-errors, @TaKO8Ki Some changes occurred in diagnostic error codes Some changes occurred in compiler/rustc_attr_data_structures Some changes occurred to the CTFE machinery Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in compiler/rustc_sanitizers cc @rust-lang/project-exploit-mitigations, @rcvalle |
Best reviewed one commit at a time. |
#137930 is another PR where this new functionality will immediately be useful. |
The job Click to see the possible cause of the failure (guessed by this bot)
|
r? @onur-ozkan (for the rustc wrapper bit, I'd appreciate a second pair of eyes, or reroll |
@@ -145,6 +145,35 @@ fn main() { | |||
cmd.arg("-Z").arg("on-broken-pipe=kill"); | |||
} | |||
|
|||
// In `cargo.rs` we add the `FLAGS_FOR_RUSTC` flags for all `compiler/` | |||
// crates to RUSTFLAGS. However, RUSTFLAGS is ignored for `compiler/` proc | |||
// macro crates, because RUSTFLAGS is ignored when `--target` is given. So, |
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.
RUSTFLAGS is ignored when
--target
is given
That's not quite true, it is not ignored. But it only applies to target crates, not to host crates.
let crate_type = parse_value_from_args(&orig_args, "--crate-type"); | ||
if crate_type == Some("proc-macro") { | ||
if let Ok(rustflags) = env::var("RUSTFLAGS") { | ||
// Count how many of flags from `FLAGS_FOR_RUSTC` are in RUSTFLAGS. |
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.
Why do we have to use a fragile hacky heuristic like that? That shouldn't be needed. Bootstrap should clearly tell the wrapper what to add where, we should never do guesswork like this.
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.
I know very little about bootstrap and this was something I managed to get working. I'm happy to hear other ideas and implement them but I'll need a more detailed explanation than "bootstrap should clearly tell the wrapper" - how and where would this be done? :)
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.
I was imagining something like this, which already exists:
rust/src/bootstrap/src/bin/rustc.rs
Lines 138 to 140 in c85d3f6
if let Ok(lint_flags) = env::var("RUSTC_LINT_FLAGS") { | |
cmd.args(lint_flags.split_whitespace()); | |
} |
From some of the other discussion it sounds like what you dislike about this approach is that it will pass the flags to all invocations, not just the ones for workspace crates. However, non-workspace crates run with --cap-lints
so that should be entirely non-consequential?
The discussion about this seems to be spread across multiple Zulip topics, issues, and PRs, so I have no idea which options have been considered. Has RUSTC_LINT_FLAGS
been discarded for some reason?
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.
This thread has most of the discussion.
I didn't even know RUSTC_LINT_FLAGS was a thing until just now. Like I said above (and in the thread), I know very little about bootstrap and I've tried several different approaches based on suggestions people have made at different times.
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.
That's fair -- I just thought bootstrap people were involved in the discussion / review so I'm a bit surprised it took so long for someone to suggest this. Let's make sure to include bootstrap people in the next PR.
I didn't know this env var existed either, but adding something like it was literally the first thing that came to my mind ("bootstrap should tell the wrapper to add some flags"), and then going over the rustc.rs
file it took no time to see that flag. I guess I am underestimating how fragmented bootstrap knowledge is.
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.
@jieyouxu, @onur-ozkan, and @Kobzol have all been involved in the various discussions and PRs. That's half the bootstrap reviewers listed in triagebot.toml
. @jieyouxu also started a thread last week on t-infra/bootstrap to ask for additional ideas.
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.
I guess I am indeed underestimating how fragmented bootstrap knowledge is.
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.
I also had no idea about the flag :) bootstrap's build logic is distributed amongst several places, it's full of hacks and edge cases, and hidden invariants that can break when you modify completely unrelated code.
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.
As I said, I didn't know about the flag either. I was about to suggest to add something like this flag (it seemed a lot cleaner than what this PR does), went looking to the sources for inspiration on how to call it, and then saw that it already existed.
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.
Same 😆
The rustc wrapper approach seems okay to me, but would appreicate a double-check since last time I thought it was okay to do some RUSTFLAGS adjustments in the wrapper I broke things :D |
IIRC, this was done several times already (I personally did it at least once), but it always gets broken after some time by bootstrap changes - for proc macros, for build scripts, for |
One way to do this is by unconditionally passing an arbitrary flag and asserting its presence in each compiler crate. Ugly, but it could work I think. |
☔ The latest upstream changes (presumably #138267) made this pull request unmergeable. Please resolve the merge conflicts. |
After the failure of the workspace lints approach (merged in #138084, reverted in #138304 for breaking miri and other external tools) I have implemented a |
Currently some flags are put into RUSTFLAGS for all
compiler/
crates, but RUSTFLAGS is ignored for proc macro crates.Also, most compiler crates have
#![warn(unreachable_pub)]
in them, but a few are missing, and it's easy to overlook if a new crate is added.This PR introduces a neat way to apply a flag to all
compiler/
crates, and uses it to replace all the#![warn(unreachable_pub)]
attributes with a single-Wunreachable-pub
mention.r? @jieyouxu