Skip to content

Build rustdoc only at the topmost stage. #43528

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bootstrap/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {
let args = env::args_os().skip(1).collect::<Vec<_>>();
let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
let libdir = env::var_os("RUSTC_LIBDIR").expect("RUSTC_LIBDIR was not set");
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
let stage = env::var("RUSTDOC_STAGE").expect("RUSTDOC_STAGE was not set");
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");

let mut dylib_path = bootstrap::util::dylib_path();
Expand Down
21 changes: 10 additions & 11 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,22 +412,20 @@ impl<'a> Builder<'a> {
}
}

pub fn rustdoc(&self, compiler: Compiler) -> PathBuf {
self.ensure(tool::Rustdoc { target_compiler: compiler })
pub fn rustdoc(&self, host: Interned<String>) -> PathBuf {
self.ensure(tool::Rustdoc { host })
}

pub fn rustdoc_cmd(&self, compiler: Compiler) -> Command {
pub fn rustdoc_cmd(&self, host: Interned<String>) -> Command {
let mut cmd = Command::new(&self.out.join("bootstrap/debug/rustdoc"));
// See rational for top_stage in rustdoc
let compiler = self.compiler(self.top_stage, host);
cmd
.env("RUSTC_STAGE", compiler.stage.to_string())
.env("RUSTC_SYSROOT", if compiler.is_snapshot(&self.build) {
INTERNER.intern_path(self.build.rustc_snapshot_libdir())
} else {
self.sysroot(compiler)
})
.env("RUSTDOC_STAGE", compiler.stage.to_string())
.env("RUSTC_SYSROOT", self.sysroot(compiler))
.env("RUSTC_LIBDIR", self.sysroot_libdir(compiler, self.build.build))
.env("CFG_RELEASE_CHANNEL", &self.build.config.channel)
.env("RUSTDOC_REAL", self.rustdoc(compiler));
.env("RUSTDOC_REAL", self.rustdoc(compiler.host));
cmd
}

Expand Down Expand Up @@ -480,8 +478,9 @@ impl<'a> Builder<'a> {
.env("RUSTC_LIBDIR", self.rustc_libdir(compiler))
.env("RUSTC_RPATH", self.config.rust_rpath.to_string())
.env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc"))
.env("RUSTDOC_STAGE", self.top_stage.to_string())
.env("RUSTDOC_REAL", if cmd == "doc" || cmd == "test" {
self.rustdoc(compiler)
self.rustdoc(compiler.host)
} else {
PathBuf::from("/path/to/nowhere/rustdoc/not/required")
})
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Step for Cargotest {
try_run(build, cmd.arg(&build.initial_cargo)
.arg(&out_dir)
.env("RUSTC", builder.rustc(compiler))
.env("RUSTDOC", builder.rustdoc(compiler)));
.env("RUSTDOC", builder.rustdoc(compiler.host)));
}
}

Expand Down Expand Up @@ -565,7 +565,7 @@ impl Step for Compiletest {

// Avoid depending on rustdoc when we don't need it.
if mode == "rustdoc" || mode == "run-make" {
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
}

cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
Expand Down Expand Up @@ -814,7 +814,7 @@ fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
}

println!("doc tests for: {}", markdown.display());
let mut cmd = builder.rustdoc_cmd(compiler);
let mut cmd = builder.rustdoc_cmd(compiler.host);
build.add_rust_test_threads(&mut cmd);
cmd.arg("--test");
cmd.arg(markdown);
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ impl Step for Rustc {
t!(fs::create_dir_all(image.join("bin")));
cp_r(&src.join("bin"), &image.join("bin"));

install(&builder.ensure(tool::Rustdoc { target_compiler: compiler }),
&image.join("bin"), 0o755);
install(&builder.rustdoc(compiler.host), &image.join("bin"), 0o755);

// Copy runtime DLLs needed by the compiler
if libdir != "bin" {
Expand Down
12 changes: 6 additions & 6 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned<String
t!(t!(File::create(&version_info)).write_all(info.as_bytes()));
}

let mut cmd = builder.rustdoc_cmd(compiler);
let mut cmd = builder.rustdoc_cmd(compiler.host);

let out = out.join("book");

Expand Down Expand Up @@ -343,7 +343,7 @@ impl Step for Standalone {
}

let html = out.join(filename).with_extension("html");
let rustdoc = builder.rustdoc(compiler);
let rustdoc = builder.rustdoc(compiler.host);
if up_to_date(&path, &html) &&
up_to_date(&footer, &html) &&
up_to_date(&favicon, &html) &&
Expand All @@ -353,7 +353,7 @@ impl Step for Standalone {
continue
}

let mut cmd = builder.rustdoc_cmd(compiler);
let mut cmd = builder.rustdoc_cmd(compiler.host);
cmd.arg("--html-after-content").arg(&footer)
.arg("--html-before-content").arg(&version_info)
.arg("--html-in-header").arg(&favicon)
Expand Down Expand Up @@ -408,7 +408,7 @@ impl Step for Std {
let out = build.doc_out(target);
t!(fs::create_dir_all(&out));
let compiler = builder.compiler(stage, build.build);
let rustdoc = builder.rustdoc(compiler);
let rustdoc = builder.rustdoc(compiler.host);
let compiler = if build.force_use_stage1(compiler, target) {
builder.compiler(1, compiler.host)
} else {
Expand Down Expand Up @@ -493,7 +493,7 @@ impl Step for Test {
let out = build.doc_out(target);
t!(fs::create_dir_all(&out));
let compiler = builder.compiler(stage, build.build);
let rustdoc = builder.rustdoc(compiler);
let rustdoc = builder.rustdoc(compiler.host);
let compiler = if build.force_use_stage1(compiler, target) {
builder.compiler(1, compiler.host)
} else {
Expand Down Expand Up @@ -554,7 +554,7 @@ impl Step for Rustc {
let out = build.doc_out(target);
t!(fs::create_dir_all(&out));
let compiler = builder.compiler(stage, build.build);
let rustdoc = builder.rustdoc(compiler);
let rustdoc = builder.rustdoc(compiler.host);
let compiler = if build.force_use_stage1(compiler, target) {
builder.compiler(1, compiler.host)
} else {
Expand Down
16 changes: 9 additions & 7 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl Step for RemoteTestServer {

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Rustdoc {
pub target_compiler: Compiler,
pub host: Interned<String>,
}

impl Step for Rustdoc {
Expand All @@ -240,30 +240,32 @@ impl Step for Rustdoc {

fn make_run(run: RunConfig) {
run.builder.ensure(Rustdoc {
target_compiler: run.builder.compiler(run.builder.top_stage, run.host),
host: run.host,
});
}

fn run(self, builder: &Builder) -> PathBuf {
let target_compiler = self.target_compiler;
let build_compiler = if target_compiler.stage == 0 {
// Always build rustdoc at the top stage; otherwise we rebuild it twice (or more).
let stage = builder.top_stage;
let build_compiler = if stage == 0 {
builder.compiler(0, builder.build.build)
} else {
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
// we'd have stageN/bin/rustc and stageN/bin/rustdoc be effectively different stage
// compilers, which isn't what we want.
builder.compiler(target_compiler.stage - 1, builder.build.build)
builder.compiler(stage - 1, builder.build.build)
};

let tool_rustdoc = builder.ensure(ToolBuild {
compiler: build_compiler,
target: target_compiler.host,
target: self.host,
tool: "rustdoc",
mode: Mode::Librustc,
});

// don't create a stage0-sysroot/bin directory.
if target_compiler.stage > 0 {
if stage > 0 {
let target_compiler = builder.compiler(build_compiler.stage + 1, self.host);
let sysroot = builder.sysroot(target_compiler);
let bindir = sysroot.join("bin");
t!(fs::create_dir_all(&bindir));
Expand Down