Skip to content

Commit 254876e

Browse files
committed
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.
1 parent 7f2d2af commit 254876e

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")
@@ -213,11 +213,11 @@ pub fn rustc(build: &Build, stage: u32, target: &str) {
213213

214214
/// Generates the HTML rendered error-index by running the
215215
/// `error_index_generator` tool.
216-
pub fn error_index(build: &Build, stage: u32, target: &str) {
217-
println!("Documenting stage{} error index ({})", stage, target);
216+
pub fn error_index(build: &Build, target: &str) {
217+
println!("Documenting error index ({})", target);
218218
let out = build.doc_out(target);
219219
t!(fs::create_dir_all(&out));
220-
let compiler = Compiler::new(stage, &build.config.build);
220+
let compiler = Compiler::new(0, &build.config.build);
221221
let mut index = build.tool_cmd(&compiler, "error_index_generator");
222222
index.arg("html");
223223
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(move |s| {
299299
if s.target.contains("android") {
@@ -331,7 +331,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
331331
rules.test("check-debuginfo", "src/test/debuginfo")
332332
.default(true)
333333
.dep(|s| s.name("libtest"))
334-
.dep(|s| s.name("tool-compiletest").target(s.host))
334+
.dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
335335
.dep(|s| s.name("test-helpers"))
336336
.dep(|s| s.name("debugger-scripts"))
337337
.run(move |s| check::compiletest(build, &s.compiler(), s.target,
@@ -340,7 +340,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
340340
rules.test("check-debuginfo", "src/test/debuginfo")
341341
.default(true)
342342
.dep(|s| s.name("libtest"))
343-
.dep(|s| s.name("tool-compiletest").target(s.host))
343+
.dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
344344
.dep(|s| s.name("test-helpers"))
345345
.dep(|s| s.name("debugger-scripts"))
346346
.run(move |s| check::compiletest(build, &s.compiler(), s.target,
@@ -356,7 +356,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
356356
rules.test(name, path)
357357
.dep(|s| s.name("librustc"))
358358
.dep(|s| s.name("test-helpers"))
359-
.dep(|s| s.name("tool-compiletest").target(s.host))
359+
.dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
360360
.default(mode != "pretty")
361361
.host(true)
362362
.run(move |s| {
@@ -438,24 +438,24 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
438438
Mode::Librustc, TestKind::Test, None));
439439

440440
rules.test("check-linkchecker", "src/tools/linkchecker")
441-
.dep(|s| s.name("tool-linkchecker"))
441+
.dep(|s| s.name("tool-linkchecker").stage(0))
442442
.dep(|s| s.name("default:doc"))
443443
.default(true)
444444
.host(true)
445-
.run(move |s| check::linkcheck(build, s.stage, s.target));
445+
.run(move |s| check::linkcheck(build, s.target));
446446
rules.test("check-cargotest", "src/tools/cargotest")
447-
.dep(|s| s.name("tool-cargotest"))
447+
.dep(|s| s.name("tool-cargotest").stage(0))
448448
.dep(|s| s.name("librustc"))
449449
.host(true)
450450
.run(move |s| check::cargotest(build, s.stage, s.target));
451451
rules.test("check-tidy", "src/tools/tidy")
452452
.dep(|s| s.name("tool-tidy").stage(0))
453453
.default(true)
454454
.host(true)
455-
.run(move |s| check::tidy(build, 0, s.target));
455+
.run(move |s| check::tidy(build, s.target));
456456
rules.test("check-error-index", "src/tools/error_index_generator")
457457
.dep(|s| s.name("libstd"))
458-
.dep(|s| s.name("tool-error-index").host(s.host))
458+
.dep(|s| s.name("tool-error-index").host(s.host).stage(0))
459459
.default(true)
460460
.host(true)
461461
.run(move |s| check::error_index(build, &s.compiler()));
@@ -501,23 +501,23 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
501501
// ========================================================================
502502
// Documentation targets
503503
rules.doc("doc-book", "src/doc/book")
504-
.dep(move |s| s.name("tool-rustbook").target(&build.config.build))
504+
.dep(move |s| s.name("tool-rustbook").target(&build.config.build).stage(0))
505505
.default(build.config.docs)
506-
.run(move |s| doc::rustbook(build, s.stage, s.target, "book"));
506+
.run(move |s| doc::rustbook(build, s.target, "book"));
507507
rules.doc("doc-nomicon", "src/doc/nomicon")
508-
.dep(move |s| s.name("tool-rustbook").target(&build.config.build))
508+
.dep(move |s| s.name("tool-rustbook").target(&build.config.build).stage(0))
509509
.default(build.config.docs)
510-
.run(move |s| doc::rustbook(build, s.stage, s.target, "nomicon"));
510+
.run(move |s| doc::rustbook(build, s.target, "nomicon"));
511511
rules.doc("doc-standalone", "src/doc")
512512
.dep(move |s| s.name("rustc").host(&build.config.build).target(&build.config.build))
513513
.default(build.config.docs)
514514
.run(move |s| doc::standalone(build, s.stage, s.target));
515515
rules.doc("doc-error-index", "src/tools/error_index_generator")
516-
.dep(move |s| s.name("tool-error-index").target(&build.config.build))
517-
.dep(move |s| s.name("librustc-link"))
516+
.dep(move |s| s.name("tool-error-index").target(&build.config.build).stage(0))
517+
.dep(move |s| s.name("librustc-link").stage(0))
518518
.default(build.config.docs)
519519
.host(true)
520-
.run(move |s| doc::error_index(build, s.stage, s.target));
520+
.run(move |s| doc::error_index(build, s.target));
521521
for (krate, path, default) in krates("std_shim") {
522522
rules.doc(&krate.doc_step, path)
523523
.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)