Skip to content

Commit

Permalink
Pass more host flags using RUSTC_HOST_FLAGS
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Oct 9, 2023
1 parent 4ea6e7f commit 3f9ab7a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/bootstrap/bin/_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fn parse_rustc_verbose() -> usize {
/// Parses the value of the "RUSTC_STAGE" environment variable and returns it as a `String`.
///
/// If "RUSTC_STAGE" was not set, the program will be terminated with 101.
#[allow(unused)]
fn parse_rustc_stage() -> String {
std::env::var("RUSTC_STAGE").unwrap_or_else(|_| {
// Don't panic here; it's reasonable to try and run these shims directly. Give a helpful error instead.
Expand Down
15 changes: 0 additions & 15 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fn main() {
let args = env::args_os().skip(1).collect::<Vec<_>>();
let arg = |name| args.windows(2).find(|args| args[0] == name).and_then(|args| args[1].to_str());

let stage = parse_rustc_stage();
let verbose = parse_rustc_verbose();

// Detect whether or not we're a build script depending on whether --target
Expand Down Expand Up @@ -108,27 +107,13 @@ fn main() {
cmd.arg("-Ztls-model=initial-exec");
}
} else {
// FIXME(rust-lang/cargo#5754) we shouldn't be using special env vars
// here, but rather Cargo should know what flags to pass rustc itself.

// Find any host flags that were passed by bootstrap.
// The flags are stored in a RUSTC_HOST_FLAGS variable, separated by spaces.
if let Ok(flags) = std::env::var("RUSTC_HOST_FLAGS") {
for flag in flags.split(' ') {
cmd.arg(flag);
}
}

// Cargo doesn't pass RUSTFLAGS to proc_macros:
// https://github.com/rust-lang/cargo/issues/4423
// Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.
// We also declare that the flag is expected, which we need to do to not
// get warnings about it being unexpected.
if stage == "0" {
cmd.arg("--cfg=bootstrap");
}
cmd.arg("-Zunstable-options");
cmd.arg("--check-cfg=values(bootstrap)");
}

if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {
Expand Down
14 changes: 14 additions & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,20 @@ impl<'a> Builder<'a> {
}
}

// FIXME(rust-lang/cargo#5754) we shouldn't be using special command arguments
// to the host invocation here, but rather Cargo should know what flags to pass rustc
// itself.
if stage == 0 {
hostflags.arg("--cfg=bootstrap");
}
// Cargo doesn't pass RUSTFLAGS to proc_macros:
// https://github.com/rust-lang/cargo/issues/4423
// Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.
// We also declare that the flag is expected, which we need to do to not
// get warnings about it being unexpected.
hostflags.arg("-Zunstable-options");
hostflags.arg("--check-cfg=values(bootstrap)");

// FIXME: It might be better to use the same value for both `RUSTFLAGS` and `RUSTDOCFLAGS`,
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
// #71458.
Expand Down

0 comments on commit 3f9ab7a

Please sign in to comment.