Skip to content

Commit f29a9a2

Browse files
committed
Auto merge of #38667 - alexcrichton:stage0-tools, r=brson
rustbuild: Compile all support tools in stage0 This commit changes all tools and such to get compiled in stage0, not in later stages. The purpose of this commit is to cut down dependencies on later stages for future modifications to the build system. Notably we're going to be adding builders that produce a full suite of cross-compiled artifacts for a particular host, and that shouldn't compile the `x86_64-unknown-linux-gnu` compiler more than once. Currently dependencies on, for example, the error index end up compiling the `x86_64-unknown-linux-gnu` compiler more than necessary. As a result here we move many dependencies on these tools to being produced by a stage0 compiler, not a stage1+ compiler. None of these tools actually need to be staged at all, so they'll exhibit consistent behavior across the stages.
2 parents 8c547a0 + 254876e commit f29a9a2

File tree

10 files changed

+63
-40
lines changed

10 files changed

+63
-40
lines changed

src/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/bin/rustc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ fn main() {
8989
// When we build Rust dylibs they're all intended for intermediate
9090
// usage, so make sure we pass the -Cprefer-dynamic flag instead of
9191
// linking all deps statically into the dylib.
92-
cmd.arg("-Cprefer-dynamic");
92+
if env::var_os("RUSTC_NO_PREFER_DYNAMIC").is_none() {
93+
cmd.arg("-Cprefer-dynamic");
94+
}
9395

9496
// Help the libc crate compile by assisting it in finding the MUSL
9597
// native libraries.

src/bootstrap/check.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ impl fmt::Display for TestKind {
6262
///
6363
/// This tool in `src/tools` will verify the validity of all our links in the
6464
/// documentation to ensure we don't have a bunch of dead ones.
65-
pub fn linkcheck(build: &Build, stage: u32, host: &str) {
66-
println!("Linkcheck stage{} ({})", stage, host);
67-
let compiler = Compiler::new(stage, host);
65+
pub fn linkcheck(build: &Build, host: &str) {
66+
println!("Linkcheck ({})", host);
67+
let compiler = Compiler::new(0, host);
6868

6969
let _time = util::timeit();
7070
build.run(build.tool_cmd(&compiler, "linkchecker")
@@ -93,20 +93,21 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) {
9393
t!(fs::create_dir_all(&out_dir));
9494

9595
let _time = util::timeit();
96-
build.run(build.tool_cmd(compiler, "cargotest")
97-
.env("PATH", newpath)
98-
.arg(&build.cargo)
99-
.arg(&out_dir));
96+
let mut cmd = Command::new(build.tool(&Compiler::new(0, host), "cargotest"));
97+
build.prepare_tool_cmd(compiler, &mut cmd);
98+
build.run(cmd.env("PATH", newpath)
99+
.arg(&build.cargo)
100+
.arg(&out_dir));
100101
}
101102

102103
/// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
103104
///
104105
/// This tool in `src/tools` checks up on various bits and pieces of style and
105106
/// otherwise just implements a few lint-like checks that are specific to the
106107
/// compiler itself.
107-
pub fn tidy(build: &Build, stage: u32, host: &str) {
108-
println!("tidy check stage{} ({})", stage, host);
109-
let compiler = Compiler::new(stage, host);
108+
pub fn tidy(build: &Build, host: &str) {
109+
println!("tidy check ({})", host);
110+
let compiler = Compiler::new(0, host);
110111
build.run(build.tool_cmd(&compiler, "tidy")
111112
.arg(build.src.join("src")));
112113
}
@@ -127,7 +128,9 @@ pub fn compiletest(build: &Build,
127128
suite: &str) {
128129
println!("Check compiletest suite={} mode={} ({} -> {})",
129130
suite, mode, compiler.host, target);
130-
let mut cmd = build.tool_cmd(compiler, "compiletest");
131+
let mut cmd = Command::new(build.tool(&Compiler::new(0, compiler.host),
132+
"compiletest"));
133+
build.prepare_tool_cmd(compiler, &mut cmd);
131134

132135
// compiletest currently has... a lot of arguments, so let's just pass all
133136
// of them!
@@ -287,7 +290,8 @@ pub fn error_index(build: &Build, compiler: &Compiler) {
287290
let output = dir.join("error-index.md");
288291

289292
let _time = util::timeit();
290-
build.run(build.tool_cmd(compiler, "error_index_generator")
293+
build.run(build.tool_cmd(&Compiler::new(0, compiler.host),
294+
"error_index_generator")
291295
.arg("markdown")
292296
.arg(&output)
293297
.env("CFG_BUILD", &build.config.build));

src/bootstrap/compile.rs

+5
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ pub fn tool(build: &Build, stage: u32, host: &str, tool: &str) {
379379
let mut cargo = build.cargo(&compiler, Mode::Tool, host, "build");
380380
cargo.arg("--manifest-path")
381381
.arg(build.src.join(format!("src/tools/{}/Cargo.toml", tool)));
382+
383+
// We don't want to build tools dynamically as they'll be running across
384+
// stages and such and it's just easier if they're not dynamically linked.
385+
cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
386+
382387
build.run(&mut cargo);
383388
}
384389

src/bootstrap/doc.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ use util::{up_to_date, cp_r};
2929
///
3030
/// This will not actually generate any documentation if the documentation has
3131
/// already been generated.
32-
pub fn rustbook(build: &Build, stage: u32, target: &str, name: &str) {
32+
pub fn rustbook(build: &Build, target: &str, name: &str) {
3333
let out = build.doc_out(target);
3434
t!(fs::create_dir_all(&out));
3535

3636
let out = out.join(name);
37-
let compiler = Compiler::new(stage, &build.config.build);
37+
let compiler = Compiler::new(0, &build.config.build);
3838
let src = build.src.join("src/doc").join(name);
3939
let index = out.join("index.html");
4040
let rustbook = build.tool(&compiler, "rustbook");
4141
if up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
4242
return
4343
}
44-
println!("Rustbook stage{} ({}) - {}", stage, target, name);
44+
println!("Rustbook ({}) - {}", target, name);
4545
let _ = fs::remove_dir_all(&out);
4646
build.run(build.tool_cmd(&compiler, "rustbook")
4747
.arg("build")
@@ -214,11 +214,11 @@ pub fn rustc(build: &Build, stage: u32, target: &str) {
214214

215215
/// Generates the HTML rendered error-index by running the
216216
/// `error_index_generator` tool.
217-
pub fn error_index(build: &Build, stage: u32, target: &str) {
218-
println!("Documenting stage{} error index ({})", stage, target);
217+
pub fn error_index(build: &Build, target: &str) {
218+
println!("Documenting error index ({})", target);
219219
let out = build.doc_out(target);
220220
t!(fs::create_dir_all(&out));
221-
let compiler = Compiler::new(stage, &build.config.build);
221+
let compiler = Compiler::new(0, &build.config.build);
222222
let mut index = build.tool_cmd(&compiler, "error_index_generator");
223223
index.arg("html");
224224
index.arg(out.join("error-index.html"));

src/bootstrap/lib.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,15 @@ impl Build {
570570
/// `host`.
571571
fn tool_cmd(&self, compiler: &Compiler, tool: &str) -> Command {
572572
let mut cmd = Command::new(self.tool(&compiler, tool));
573+
self.prepare_tool_cmd(compiler, &mut cmd);
574+
return cmd
575+
}
576+
577+
/// Prepares the `cmd` provided to be able to run the `compiler` provided.
578+
///
579+
/// Notably this munges the dynamic library lookup path to point to the
580+
/// right location to run `compiler`.
581+
fn prepare_tool_cmd(&self, compiler: &Compiler, cmd: &mut Command) {
573582
let host = compiler.host;
574583
let mut paths = vec![
575584
self.sysroot_libdir(compiler, compiler.host),
@@ -593,8 +602,7 @@ impl Build {
593602
}
594603
}
595604
}
596-
add_lib_path(paths, &mut cmd);
597-
return cmd
605+
add_lib_path(paths, cmd);
598606
}
599607

600608
/// Get the space-separated set of activated features for the standard

src/bootstrap/mk/Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ distcheck:
6969
install:
7070
$(Q)$(BOOTSTRAP) dist --install $(BOOTSTRAP_ARGS)
7171
tidy:
72-
$(Q)$(BOOTSTRAP) test src/tools/tidy $(BOOTSTRAP_ARGS) --stage 0
72+
$(Q)$(BOOTSTRAP) test src/tools/tidy $(BOOTSTRAP_ARGS)
7373

7474
check-stage2-T-arm-linux-androideabi-H-x86_64-unknown-linux-gnu:
7575
$(Q)$(BOOTSTRAP) test --target arm-linux-androideabi

src/bootstrap/step.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
293293
let mut suite = |name, path, mode, dir| {
294294
rules.test(name, path)
295295
.dep(|s| s.name("libtest"))
296-
.dep(|s| s.name("tool-compiletest").target(s.host))
296+
.dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
297297
.dep(|s| s.name("test-helpers"))
298298
.dep(|s| s.name("android-copy-libs"))
299299
.default(mode != "pretty") // pretty tests don't run everywhere
@@ -325,7 +325,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
325325
rules.test("check-debuginfo", "src/test/debuginfo")
326326
.default(true)
327327
.dep(|s| s.name("libtest"))
328-
.dep(|s| s.name("tool-compiletest").target(s.host))
328+
.dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
329329
.dep(|s| s.name("test-helpers"))
330330
.dep(|s| s.name("debugger-scripts"))
331331
.run(move |s| check::compiletest(build, &s.compiler(), s.target,
@@ -334,7 +334,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
334334
rules.test("check-debuginfo", "src/test/debuginfo")
335335
.default(true)
336336
.dep(|s| s.name("libtest"))
337-
.dep(|s| s.name("tool-compiletest").target(s.host))
337+
.dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
338338
.dep(|s| s.name("test-helpers"))
339339
.dep(|s| s.name("debugger-scripts"))
340340
.dep(|s| s.name("android-copy-libs"))
@@ -351,7 +351,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
351351
rules.test(name, path)
352352
.dep(|s| s.name("librustc"))
353353
.dep(|s| s.name("test-helpers"))
354-
.dep(|s| s.name("tool-compiletest").target(s.host))
354+
.dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
355355
.default(mode != "pretty")
356356
.host(true)
357357
.run(move |s| {
@@ -441,24 +441,24 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
441441
Mode::Librustc, TestKind::Test, None));
442442

443443
rules.test("check-linkchecker", "src/tools/linkchecker")
444-
.dep(|s| s.name("tool-linkchecker"))
444+
.dep(|s| s.name("tool-linkchecker").stage(0))
445445
.dep(|s| s.name("default:doc"))
446446
.default(true)
447447
.host(true)
448-
.run(move |s| check::linkcheck(build, s.stage, s.target));
448+
.run(move |s| check::linkcheck(build, s.target));
449449
rules.test("check-cargotest", "src/tools/cargotest")
450-
.dep(|s| s.name("tool-cargotest"))
450+
.dep(|s| s.name("tool-cargotest").stage(0))
451451
.dep(|s| s.name("librustc"))
452452
.host(true)
453453
.run(move |s| check::cargotest(build, s.stage, s.target));
454454
rules.test("check-tidy", "src/tools/tidy")
455455
.dep(|s| s.name("tool-tidy").stage(0))
456456
.default(true)
457457
.host(true)
458-
.run(move |s| check::tidy(build, 0, s.target));
458+
.run(move |s| check::tidy(build, s.target));
459459
rules.test("check-error-index", "src/tools/error_index_generator")
460460
.dep(|s| s.name("libstd"))
461-
.dep(|s| s.name("tool-error-index").host(s.host))
461+
.dep(|s| s.name("tool-error-index").host(s.host).stage(0))
462462
.default(true)
463463
.host(true)
464464
.run(move |s| check::error_index(build, &s.compiler()));
@@ -504,23 +504,23 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
504504
// ========================================================================
505505
// Documentation targets
506506
rules.doc("doc-book", "src/doc/book")
507-
.dep(move |s| s.name("tool-rustbook").target(&build.config.build))
507+
.dep(move |s| s.name("tool-rustbook").target(&build.config.build).stage(0))
508508
.default(build.config.docs)
509-
.run(move |s| doc::rustbook(build, s.stage, s.target, "book"));
509+
.run(move |s| doc::rustbook(build, s.target, "book"));
510510
rules.doc("doc-nomicon", "src/doc/nomicon")
511-
.dep(move |s| s.name("tool-rustbook").target(&build.config.build))
511+
.dep(move |s| s.name("tool-rustbook").target(&build.config.build).stage(0))
512512
.default(build.config.docs)
513-
.run(move |s| doc::rustbook(build, s.stage, s.target, "nomicon"));
513+
.run(move |s| doc::rustbook(build, s.target, "nomicon"));
514514
rules.doc("doc-standalone", "src/doc")
515515
.dep(move |s| s.name("rustc").host(&build.config.build).target(&build.config.build))
516516
.default(build.config.docs)
517517
.run(move |s| doc::standalone(build, s.stage, s.target));
518518
rules.doc("doc-error-index", "src/tools/error_index_generator")
519-
.dep(move |s| s.name("tool-error-index").target(&build.config.build))
520-
.dep(move |s| s.name("librustc-link"))
519+
.dep(move |s| s.name("tool-error-index").target(&build.config.build).stage(0))
520+
.dep(move |s| s.name("librustc-link").stage(0))
521521
.default(build.config.docs)
522522
.host(true)
523-
.run(move |s| doc::error_index(build, s.stage, s.target));
523+
.run(move |s| doc::error_index(build, s.target));
524524
for (krate, path, default) in krates("std_shim") {
525525
rules.doc(&krate.doc_step, path)
526526
.dep(|s| s.name("libstd-link"))

src/tools/compiletest/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ build = "build.rs"
77
[dependencies]
88
log = "0.3"
99
env_logger = { version = "0.3.5", default-features = false }
10-
serialize = { path = "../../libserialize" }
10+
rustc-serialize = "0.3"

src/tools/compiletest/src/main.rs

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
extern crate libc;
2222
extern crate test;
2323
extern crate getopts;
24+
25+
#[cfg(cargobuild)]
26+
extern crate rustc_serialize;
27+
#[cfg(not(cargobuild))]
2428
extern crate serialize as rustc_serialize;
2529

2630
#[macro_use]

0 commit comments

Comments
 (0)