Skip to content

Commit 0238986

Browse files
committed
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`. This also extracts the logic into a helper function to make sure it's the same.
1 parent 8599bff commit 0238986

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
@@ -938,6 +938,12 @@ impl<'a> Builder<'a> {
938938
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
939939
// #71458.
940940
let mut rustdocflags = rustflags.clone();
941+
rustdocflags.propagate_cargo_env("RUSTDOCFLAGS");
942+
if stage == 0 {
943+
rustdocflags.env("RUSTDOCFLAGS_BOOTSTRAP");
944+
} else {
945+
rustdocflags.env("RUSTDOCFLAGS_NOT_BOOTSTRAP");
946+
}
941947

942948
if let Ok(s) = env::var("CARGOFLAGS") {
943949
cargo.args(s.split_whitespace());
@@ -1551,21 +1557,27 @@ impl<'a> Builder<'a> {
15511557
mod tests;
15521558

15531559
#[derive(Debug, Clone)]
1554-
struct Rustflags(String);
1560+
struct Rustflags(String, TargetSelection);
15551561

15561562
impl Rustflags {
15571563
fn new(target: TargetSelection) -> Rustflags {
1558-
let mut ret = Rustflags(String::new());
1564+
let mut ret = Rustflags(String::new(), target);
1565+
ret.propagate_cargo_env("RUSTFLAGS");
1566+
ret
1567+
}
15591568

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

1568-
ret
1578+
// ... and also handle target-specific env RUSTFLAGS if they're configured.
1579+
let target_specific = format!("CARGO_TARGET_{}_{}", crate::envify(&self.1.triple), prefix);
1580+
self.env(&target_specific);
15691581
}
15701582

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

0 commit comments

Comments
 (0)