Skip to content

Commit e0750a1

Browse files
committed
Flags from env variables like RUSTFLAGS now have precedence over bootstrap own flags and not the other way around.
1 parent d682af8 commit e0750a1

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ struct Rustflags(String, TargetSelection);
2525

2626
impl Rustflags {
2727
fn new(target: TargetSelection) -> Rustflags {
28-
let mut ret = Rustflags(String::new(), target);
29-
ret.propagate_cargo_env("RUSTFLAGS");
30-
ret
28+
Rustflags(String::new(), target)
3129
}
3230

3331
/// By default, cargo will pick up on various variables in the environment. However, bootstrap
@@ -60,6 +58,16 @@ impl Rustflags {
6058
self.0.push_str(arg);
6159
self
6260
}
61+
62+
fn propagate_rustflag_envs(&mut self, build_compiler_stage: u32) {
63+
self.propagate_cargo_env("RUSTFLAGS");
64+
if build_compiler_stage != 0 {
65+
self.env("RUSTFLAGS_NOT_BOOTSTRAP");
66+
} else {
67+
self.env("RUSTFLAGS_BOOTSTRAP");
68+
self.arg("--cfg=bootstrap");
69+
}
70+
}
6371
}
6472

6573
/// Flags that are passed to the `rustc` shim binary. These flags will only be applied when
@@ -601,18 +609,6 @@ impl Builder<'_> {
601609
}
602610

603611
let mut rustflags = Rustflags::new(target);
604-
if build_compiler_stage != 0 {
605-
if let Ok(s) = env::var("CARGOFLAGS_NOT_BOOTSTRAP") {
606-
cargo.args(s.split_whitespace());
607-
}
608-
rustflags.env("RUSTFLAGS_NOT_BOOTSTRAP");
609-
} else {
610-
if let Ok(s) = env::var("CARGOFLAGS_BOOTSTRAP") {
611-
cargo.args(s.split_whitespace());
612-
}
613-
rustflags.env("RUSTFLAGS_BOOTSTRAP");
614-
rustflags.arg("--cfg=bootstrap");
615-
}
616612

617613
if cmd_kind == Kind::Clippy {
618614
// clippy overwrites sysroot if we pass it to cargo.
@@ -711,6 +707,7 @@ impl Builder<'_> {
711707
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
712708
// #71458.
713709
let mut rustdocflags = rustflags.clone();
710+
rustdocflags.propagate_rustflag_envs(build_compiler_stage);
714711
rustdocflags.propagate_cargo_env("RUSTDOCFLAGS");
715712
if build_compiler_stage == 0 {
716713
rustdocflags.env("RUSTDOCFLAGS_BOOTSTRAP");
@@ -1360,6 +1357,15 @@ impl Builder<'_> {
13601357
rustflags.arg("-Zmir_strip_debuginfo=locals-in-tiny-functions");
13611358
}
13621359

1360+
rustflags.propagate_rustflag_envs(build_compiler_stage);
1361+
if build_compiler_stage != 0 {
1362+
if let Ok(s) = env::var("CARGOFLAGS_NOT_BOOTSTRAP") {
1363+
cargo.args(s.split_whitespace());
1364+
}
1365+
} else if let Ok(s) = env::var("CARGOFLAGS_BOOTSTRAP") {
1366+
cargo.args(s.split_whitespace());
1367+
}
1368+
13631369
let release_build = self.config.rust_optimize.is_release() &&
13641370
// cargo bench/install do not accept `--release` and miri doesn't want it
13651371
!matches!(cmd_kind, Kind::Bench | Kind::Install | Kind::Miri | Kind::MiriSetup | Kind::MiriTest);

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,4 +581,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
581581
severity: ChangeSeverity::Info,
582582
summary: "The `build.python` option is now respected on macOS (previously ignored and forced to be /usr/bin/python3).",
583583
},
584+
ChangeInfo {
585+
change_id: 148911,
586+
severity: ChangeSeverity::Warning,
587+
summary: "Flags from env variables like `RUSTFLAGS` now have precedence over bootstrap own flags and not the other way around.",
588+
},
584589
];

0 commit comments

Comments
 (0)