Skip to content

Commit e2e9b40

Browse files
Build rustdoc on-demand.
Rustdoc is no longer compiled in every stage, alongside rustc, instead it is only compiled when requested, and generally only for the last stage.
1 parent fe0eca0 commit e2e9b40

File tree

14 files changed

+106
-67
lines changed

14 files changed

+106
-67
lines changed

src/Cargo.lock

Lines changed: 10 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ members = [
1616
"tools/remote-test-server",
1717
"tools/rust-installer",
1818
"tools/cargo",
19+
"tools/rustdoc",
1920
"tools/rls",
2021
# FIXME(https://github.com/rust-lang/cargo/issues/4089): move these to exclude
2122
"tools/rls/test_data/borrow_error",

src/bootstrap/builder.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl<'a> Builder<'a> {
256256
compile::StartupObjects, tool::BuildManifest, tool::Rustbook, tool::ErrorIndex,
257257
tool::UnstableBookGen, tool::Tidy, tool::Linkchecker, tool::CargoTest,
258258
tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
259-
tool::RustInstaller, tool::Cargo, tool::Rls),
259+
tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc),
260260
Kind::Test => describe!(check::Tidy, check::Bootstrap, check::DefaultCompiletest,
261261
check::HostCompiletest, check::Crate, check::CrateLibrustc, check::Linkcheck,
262262
check::Cargotest, check::Cargo, check::Rls, check::Docs, check::ErrorIndex,
@@ -412,12 +412,22 @@ impl<'a> Builder<'a> {
412412
}
413413
}
414414

415-
/// Get the `rustdoc` executable next to the specified compiler
416415
pub fn rustdoc(&self, compiler: Compiler) -> PathBuf {
417-
let mut rustdoc = self.rustc(compiler);
418-
rustdoc.pop();
419-
rustdoc.push(exe("rustdoc", &compiler.host));
420-
rustdoc
416+
self.ensure(tool::Rustdoc { target_compiler: compiler })
417+
}
418+
419+
pub fn rustdoc_cmd(&self, compiler: Compiler) -> Command {
420+
let mut cmd = Command::new(&self.out.join("bootstrap/debug/rustdoc"));
421+
cmd
422+
.env("RUSTC_STAGE", compiler.stage.to_string())
423+
.env("RUSTC_SYSROOT", if compiler.is_snapshot(&self.build) {
424+
INTERNER.intern_path(self.build.rustc_snapshot_libdir())
425+
} else {
426+
self.sysroot(compiler)
427+
})
428+
.env("RUSTC_LIBDIR", self.sysroot_libdir(compiler, self.build.build))
429+
.env("RUSTDOC_REAL", self.rustdoc(compiler));
430+
cmd
421431
}
422432

423433
/// Prepares an invocation of `cargo` to be run.
@@ -469,7 +479,11 @@ impl<'a> Builder<'a> {
469479
.env("RUSTC_LIBDIR", self.rustc_libdir(compiler))
470480
.env("RUSTC_RPATH", self.config.rust_rpath.to_string())
471481
.env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc"))
472-
.env("RUSTDOC_REAL", self.rustdoc(compiler))
482+
.env("RUSTDOC_REAL", if cmd == "doc" || cmd == "test" {
483+
self.rustdoc(compiler)
484+
} else {
485+
PathBuf::from("/path/to/nowhere/rustdoc/not/required")
486+
})
473487
.env("RUSTC_FLAGS", self.rustc_flags(target).join(" "));
474488

475489
if mode != Mode::Tool {

src/bootstrap/check.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,7 @@ fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
809809
}
810810

811811
println!("doc tests for: {}", markdown.display());
812-
let mut cmd = Command::new(builder.rustdoc(compiler));
813-
builder.add_rustc_lib_path(compiler, &mut cmd);
812+
let mut cmd = builder.rustdoc_cmd(compiler);
814813
build.add_rust_test_threads(&mut cmd);
815814
cmd.arg("--test");
816815
cmd.arg(markdown);

src/bootstrap/compile.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -719,15 +719,6 @@ impl Step for Assemble {
719719
let _ = fs::remove_file(&compiler);
720720
copy(&rustc, &compiler);
721721

722-
// See if rustdoc exists to link it into place
723-
let rustdoc = exe("rustdoc", &*host);
724-
let rustdoc_src = out_dir.join(&rustdoc);
725-
let rustdoc_dst = bindir.join(&rustdoc);
726-
if fs::metadata(&rustdoc_src).is_ok() {
727-
let _ = fs::remove_file(&rustdoc_dst);
728-
copy(&rustdoc_src, &rustdoc_dst);
729-
}
730-
731722
target_compiler
732723
}
733724
}

src/bootstrap/dist.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ impl Step for Rustc {
413413
t!(fs::create_dir_all(image.join("bin")));
414414
cp_r(&src.join("bin"), &image.join("bin"));
415415

416+
install(&builder.ensure(tool::Rustdoc { target_compiler: compiler }),
417+
&image.join("bin"), 0o755);
418+
416419
// Copy runtime DLLs needed by the compiler
417420
if libdir != "bin" {
418421
for entry in t!(src.join(libdir).read_dir()).map(|e| t!(e)) {

src/bootstrap/doc.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use std::fs::{self, File};
2121
use std::io::prelude::*;
2222
use std::io;
2323
use std::path::{PathBuf, Path};
24-
use std::process::Command;
2524

2625
use Mode;
2726
use build_helper::up_to_date;
@@ -242,12 +241,8 @@ fn invoke_rustdoc(builder: &Builder, target: Interned<String>, markdown: &str) {
242241
let build = builder.build;
243242
let out = build.doc_out(target);
244243

245-
let compiler = builder.compiler(0, build.build);
246-
247244
let path = build.src.join("src/doc").join(markdown);
248245

249-
let rustdoc = builder.rustdoc(compiler);
250-
251246
let favicon = build.src.join("src/doc/favicon.inc");
252247
let footer = build.src.join("src/doc/footer.inc");
253248

@@ -263,9 +258,7 @@ fn invoke_rustdoc(builder: &Builder, target: Interned<String>, markdown: &str) {
263258
t!(t!(File::create(&version_info)).write_all(info.as_bytes()));
264259
}
265260

266-
let mut cmd = Command::new(&rustdoc);
267-
268-
builder.add_rustc_lib_path(compiler, &mut cmd);
261+
let mut cmd = builder.rustdoc_cmd(builder.compiler(0, build.build));
269262

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

@@ -357,8 +350,7 @@ impl Step for Standalone {
357350
continue
358351
}
359352

360-
let mut cmd = Command::new(&rustdoc);
361-
builder.add_rustc_lib_path(compiler, &mut cmd);
353+
let mut cmd = builder.rustdoc_cmd(compiler);
362354
cmd.arg("--html-after-content").arg(&footer)
363355
.arg("--html-before-content").arg(&version_info)
364356
.arg("--html-in-header").arg(&favicon)

src/bootstrap/tool.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::fs;
1112
use std::env;
1213
use std::path::PathBuf;
1314
use std::process::Command;
1415

1516
use Mode;
1617
use Compiler;
1718
use builder::{Step, RunConfig, ShouldRun, Builder};
18-
use util::{exe, add_lib_path};
19+
use util::{copy, exe, add_lib_path};
1920
use compile::{self, libtest_stamp, libstd_stamp, librustc_stamp};
2021
use native;
2122
use channel::GitInfo;
@@ -223,6 +224,56 @@ impl Step for RemoteTestServer {
223224
}
224225
}
225226

227+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
228+
pub struct Rustdoc {
229+
pub target_compiler: Compiler,
230+
}
231+
232+
impl Step for Rustdoc {
233+
type Output = PathBuf;
234+
const DEFAULT: bool = true;
235+
const ONLY_HOSTS: bool = true;
236+
237+
fn should_run(run: ShouldRun) -> ShouldRun {
238+
run.path("src/tools/rustdoc")
239+
}
240+
241+
fn make_run(run: RunConfig) {
242+
run.builder.ensure(Rustdoc {
243+
target_compiler: run.builder.compiler(run.builder.top_stage, run.host),
244+
});
245+
}
246+
247+
fn run(self, builder: &Builder) -> PathBuf {
248+
let target_compiler = self.target_compiler;
249+
let build_compiler = if target_compiler.stage == 0 {
250+
target_compiler
251+
} else {
252+
builder.compiler(target_compiler.stage - 1, target_compiler.host)
253+
};
254+
255+
let tool_rustdoc = builder.ensure(ToolBuild {
256+
compiler: build_compiler,
257+
target: build_compiler.host,
258+
tool: "rustdoc",
259+
mode: Mode::Librustc,
260+
});
261+
262+
// don't create a stage0-sysroot/bin directory.
263+
if target_compiler.stage > 0 {
264+
let sysroot = builder.sysroot(target_compiler);
265+
let bindir = sysroot.join("bin");
266+
t!(fs::create_dir_all(&bindir));
267+
let bin_rustdoc = bindir.join(exe("rustdoc", &*target_compiler.host));
268+
let _ = fs::remove_file(&bin_rustdoc);
269+
copy(&tool_rustdoc, &bin_rustdoc);
270+
bin_rustdoc
271+
} else {
272+
tool_rustdoc
273+
}
274+
}
275+
}
276+
226277
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
227278
pub struct Cargo {
228279
pub compiler: Compiler,

src/librustdoc/Cargo.toml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,10 @@ build = "build.rs"
77
[lib]
88
name = "rustdoc"
99
path = "lib.rs"
10-
crate-type = ["dylib"]
1110

1211
[dependencies]
13-
arena = { path = "../libarena" }
1412
env_logger = { version = "0.4", default-features = false }
1513
log = "0.3"
16-
rustc = { path = "../librustc" }
17-
rustc_back = { path = "../librustc_back" }
18-
rustc_data_structures = { path = "../librustc_data_structures" }
19-
rustc_driver = { path = "../librustc_driver" }
20-
rustc_errors = { path = "../librustc_errors" }
21-
rustc_lint = { path = "../librustc_lint" }
22-
rustc_metadata = { path = "../librustc_metadata" }
23-
rustc_resolve = { path = "../librustc_resolve" }
24-
rustc_typeck = { path = "../librustc_typeck" }
25-
rustc_trans = { path = "../librustc_trans" }
26-
serialize = { path = "../libserialize" }
27-
syntax = { path = "../libsyntax" }
28-
syntax_pos = { path = "../libsyntax_pos" }
2914
pulldown-cmark = { version = "0.0.14", default-features = false }
3015

3116
[build-dependencies]

src/librustdoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
html_playground_url = "https://play.rust-lang.org/")]
1818
#![deny(warnings)]
1919

20+
#![feature(rustc_private)]
2021
#![feature(box_patterns)]
2122
#![feature(box_syntax)]
2223
#![feature(libc)]

src/rustc/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@ version = "0.0.0"
77
name = "rustc"
88
path = "rustc.rs"
99

10-
[[bin]]
11-
name = "rustdoc"
12-
path = "rustdoc.rs"
13-
1410
# All optional dependencies so the features passed to this Cargo.toml select
1511
# what should actually be built.
1612
[dependencies]
1713
rustc_back = { path = "../librustc_back" }
1814
rustc_driver = { path = "../librustc_driver" }
19-
rustdoc = { path = "../librustdoc" }
2015

2116
[features]
2217
jemalloc = ["rustc_back/jemalloc"]

src/tools/error_index_generator/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ authors = ["The Rust Project Developers"]
33
name = "error_index_generator"
44
version = "0.0.0"
55

6+
[dependencies]
7+
rustdoc = { path = "../../librustdoc" }
8+
69
[[bin]]
710
name = "error_index_generator"
811
path = "main.rs"

src/tools/rustdoc/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "rustdoc-tool"
3+
version = "0.0.0"
4+
authors = ["The Rust Project Developers"]
5+
6+
[[bin]]
7+
name = "rustdoc"
8+
path = "main.rs"
9+
10+
[dependencies]
11+
rustdoc = { path = "../../librustdoc" }
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(rustc_private)]
12-
1311
extern crate rustdoc;
1412

1513
fn main() { rustdoc::main() }

0 commit comments

Comments
 (0)