Skip to content

Don't build rustdoc in more than one stage #59844

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
54 changes: 19 additions & 35 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ use crate::compile;
use crate::cache::{INTERNER, Interned};
use crate::config::Config;

fn doc_dir(
builder: &Builder<'_>,
compiler: Compiler,
target: Interned<String>,
mode: Mode,
) -> PathBuf {
let compiler = if builder.force_use_stage1(compiler, target) {
builder.compiler(1, compiler.host)
} else {
compiler
};
builder.stage_out(compiler, mode).join(target).join("doc")
}

macro_rules! book {
($($name:ident, $path:expr, $book_name:expr, $book_ver:expr;)+) => {
$(
Expand Down Expand Up @@ -476,15 +490,9 @@ impl Step for Std {
let out = builder.doc_out(target);
t!(fs::create_dir_all(&out));
let compiler = builder.compiler(stage, builder.config.build);
let compiler = if builder.force_use_stage1(compiler, target) {
builder.compiler(1, compiler.host)
} else {
compiler
};

builder.ensure(compile::Std { compiler, target });
let out_dir = builder.stage_out(compiler, Mode::Std)
.join(target).join("doc");
let out_dir = doc_dir(builder, compiler, target, Mode::Std);

// Here what we're doing is creating a *symlink* (directory junction on
// Windows) to the final output location. This is not done as an
Expand Down Expand Up @@ -564,18 +572,12 @@ impl Step for Test {
let out = builder.doc_out(target);
t!(fs::create_dir_all(&out));
let compiler = builder.compiler(stage, builder.config.build);
let compiler = if builder.force_use_stage1(compiler, target) {
builder.compiler(1, compiler.host)
} else {
compiler
};

// Build libstd docs so that we generate relative links
builder.ensure(Std { stage, target });

builder.ensure(compile::Test { compiler, target });
let out_dir = builder.stage_out(compiler, Mode::Test)
.join(target).join("doc");
let out_dir = doc_dir(builder, compiler, target, Mode::Test);

// See docs in std above for why we symlink
let my_out = builder.crate_doc_out(target);
Expand Down Expand Up @@ -633,18 +635,12 @@ impl Step for WhitelistedRustc {
let out = builder.doc_out(target);
t!(fs::create_dir_all(&out));
let compiler = builder.compiler(stage, builder.config.build);
let compiler = if builder.force_use_stage1(compiler, target) {
builder.compiler(1, compiler.host)
} else {
compiler
};

// Build libstd docs so that we generate relative links
builder.ensure(Std { stage, target });

builder.ensure(compile::Rustc { compiler, target });
let out_dir = builder.stage_out(compiler, Mode::Rustc)
.join(target).join("doc");
let out_dir = doc_dir(builder, compiler, target, Mode::Rustc);

// See docs in std above for why we symlink
let my_out = builder.crate_doc_out(target);
Expand Down Expand Up @@ -707,11 +703,6 @@ impl Step for Rustc {

// Get the correct compiler for this stage.
let compiler = builder.compiler(stage, builder.config.build);
let compiler = if builder.force_use_stage1(compiler, target) {
builder.compiler(1, compiler.host)
} else {
compiler
};

if !builder.config.compiler_docs {
builder.info("\tskipping - compiler/librustdoc docs disabled");
Expand All @@ -723,7 +714,7 @@ impl Step for Rustc {

// We do not symlink to the same shared folder that already contains std library
// documentation from previous steps as we do not want to include that.
let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target).join("doc");
let out_dir = doc_dir(builder, compiler, target, Mode::Rustc);
t!(symlink_dir_force(&builder.config, &out, &out_dir));

// Build cargo command.
Expand Down Expand Up @@ -808,11 +799,6 @@ impl Step for Rustdoc {

// Get the correct compiler for this stage.
let compiler = builder.compiler(stage, builder.config.build);
let compiler = if builder.force_use_stage1(compiler, target) {
builder.compiler(1, compiler.host)
} else {
compiler
};

if !builder.config.compiler_docs {
builder.info("\tskipping - compiler/librustdoc docs disabled");
Expand All @@ -826,9 +812,7 @@ impl Step for Rustdoc {
builder.ensure(tool::Rustdoc { compiler: compiler });

// Symlink compiler docs to the output directory of rustdoc documentation.
let out_dir = builder.stage_out(compiler, Mode::ToolRustc)
.join(target)
.join("doc");
let out_dir = doc_dir(builder, compiler, target, Mode::ToolRustc);
t!(fs::create_dir_all(&out_dir));
t!(symlink_dir_force(&builder.config, &out, &out_dir));

Expand Down
10 changes: 0 additions & 10 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1678,16 +1678,6 @@ impl Step for Crate {
builder.ensure(compile::Test { compiler, target });
builder.ensure(RemoteCopyLibs { compiler, target });

// If we're not doing a full bootstrap but we're testing a stage2 version of
// libstd, then what we're actually testing is the libstd produced in
// stage1. Reflect that here by updating the compiler that we're working
// with automatically.
let compiler = if builder.force_use_stage1(compiler, target) {
builder.compiler(1, compiler.host)
} else {
compiler.clone()
};

let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
match mode {
Mode::Std => {
Expand Down
17 changes: 17 additions & 0 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::env;
use std::path::PathBuf;
use std::process::{Command, exit};
use std::collections::HashSet;
use std::sync::Mutex;

use crate::Mode;
use crate::Compiler;
Expand Down Expand Up @@ -436,6 +437,7 @@ pub struct Rustdoc {
pub compiler: Compiler,
}


impl Step for Rustdoc {
type Output = PathBuf;
const DEFAULT: bool = true;
Expand All @@ -452,6 +454,21 @@ impl Step for Rustdoc {
}

fn run(self, builder: &Builder<'_>) -> PathBuf {
lazy_static! {
static ref BUILT_RUSTDOC_IN: Mutex<Vec<u32>> = Mutex::new(Vec::new());
}
{
let mut built = BUILT_RUSTDOC_IN.lock().unwrap();
if !built.contains(&self.compiler.stage) {
built.push(self.compiler.stage);
assert_eq!(
built.len(),
1,
"Only ever build one copy of rustdoc per run, currently built in stages {:?}",
built,
);
}
}
let target_compiler = self.compiler;
if target_compiler.stage == 0 {
if !target_compiler.is_snapshot(builder) {
Expand Down