Skip to content

Commit 3de9b41

Browse files
authored
Rollup merge of #82309 - jyn514:rustdocflags, r=Mark-Simulacrum
Propagate RUSTDOCFLAGS in the environment when documenting Previously, RUSTDOCFLAGS would get overriden when bootstrap set `RUSTDOCFLAGS` itself. Propagate the flag manually, using the same logic as `RUSTFLAGS`. Fixes #75256.
2 parents 3b150b7 + 0238986 commit 3de9b41

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/bootstrap/builder.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,12 @@ impl<'a> Builder<'a> {
939939
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
940940
// #71458.
941941
let mut rustdocflags = rustflags.clone();
942+
rustdocflags.propagate_cargo_env("RUSTDOCFLAGS");
943+
if stage == 0 {
944+
rustdocflags.env("RUSTDOCFLAGS_BOOTSTRAP");
945+
} else {
946+
rustdocflags.env("RUSTDOCFLAGS_NOT_BOOTSTRAP");
947+
}
942948

943949
if let Ok(s) = env::var("CARGOFLAGS") {
944950
cargo.args(s.split_whitespace());
@@ -1544,21 +1550,27 @@ impl<'a> Builder<'a> {
15441550
mod tests;
15451551

15461552
#[derive(Debug, Clone)]
1547-
struct Rustflags(String);
1553+
struct Rustflags(String, TargetSelection);
15481554

15491555
impl Rustflags {
15501556
fn new(target: TargetSelection) -> Rustflags {
1551-
let mut ret = Rustflags(String::new());
1557+
let mut ret = Rustflags(String::new(), target);
1558+
ret.propagate_cargo_env("RUSTFLAGS");
1559+
ret
1560+
}
15521561

1562+
/// By default, cargo will pick up on various variables in the environment. However, bootstrap
1563+
/// reuses those variables to pass additional flags to rustdoc, so by default they get overriden.
1564+
/// Explicitly add back any previous value in the environment.
1565+
///
1566+
/// `prefix` is usually `RUSTFLAGS` or `RUSTDOCFLAGS`.
1567+
fn propagate_cargo_env(&mut self, prefix: &str) {
15531568
// Inherit `RUSTFLAGS` by default ...
1554-
ret.env("RUSTFLAGS");
1555-
1556-
// ... and also handle target-specific env RUSTFLAGS if they're
1557-
// configured.
1558-
let target_specific = format!("CARGO_TARGET_{}_RUSTFLAGS", crate::envify(&target.triple));
1559-
ret.env(&target_specific);
1569+
self.env(prefix);
15601570

1561-
ret
1571+
// ... and also handle target-specific env RUSTFLAGS if they're configured.
1572+
let target_specific = format!("CARGO_TARGET_{}_{}", crate::envify(&self.1.triple), prefix);
1573+
self.env(&target_specific);
15621574
}
15631575

15641576
fn env(&mut self, env: &str) {

0 commit comments

Comments
 (0)