Skip to content

Commit adbce60

Browse files
committed
Auto merge of #43630 - Mark-Simulacrum:rustbuild-cleanups, r=alexcrichton
Rustbuild cleanups/fixes and improvements Each commit is a standalone change, and can/should be reviewed separately. This adds two new functionalities: - `--target` and `--host` can be passed without changing config.toml, and we'll respect the users' wishes, instead of requiring that all possible targets are passed. - Note that this means that `./x.py clean` won't be quite as wide-spread as before, since it limits itself to the configured hosts, not all hosts. This could be considered a feature as well. - `ignore-git` field in `config.toml` which tells Rustbuild to not attempt to load git hashes from `.git`. This is a precursor to eventual further simplification of the configuration system, but I want to get this merged first so that later work can be made in individual PRs. r? @alexcrichton
2 parents 0ed03e5 + 01641c7 commit adbce60

17 files changed

+239
-189
lines changed

config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@
258258
# saying that the FileCheck executable is missing, you may want to disable this.
259259
#codegen-tests = true
260260

261+
# Flag indicating whether git info will be retrieved from .git automatically.
262+
#ignore-git = false
263+
261264
# =============================================================================
262265
# Options for specific targets
263266
#

src/bootstrap/bin/main.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ extern crate bootstrap;
2121

2222
use std::env;
2323

24-
use bootstrap::{Flags, Config, Build};
24+
use bootstrap::{Config, Build};
2525

2626
fn main() {
2727
let args = env::args().skip(1).collect::<Vec<_>>();
28-
let flags = Flags::parse(&args);
29-
let config = Config::parse(&flags.build, flags.config.clone());
30-
Build::new(flags, config).build();
28+
let config = Config::parse(&args);
29+
Build::new(config).build();
3130
}

src/bootstrap/builder.rs

+18-30
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,19 @@ impl StepDescription {
120120
fn maybe_run(&self, builder: &Builder, path: Option<&Path>) {
121121
let build = builder.build;
122122
let hosts = if self.only_build_targets || self.only_build {
123-
&build.config.host[..1]
123+
build.build_triple()
124124
} else {
125125
&build.hosts
126126
};
127127

128-
// Determine the actual targets participating in this rule.
129-
// NOTE: We should keep the full projection from build triple to
130-
// the hosts for the dist steps, now that the hosts array above is
131-
// truncated to avoid duplication of work in that case. Therefore
132-
// the original non-shadowed hosts array is used below.
128+
// Determine the targets participating in this rule.
133129
let targets = if self.only_hosts {
134-
// If --target was specified but --host wasn't specified,
135-
// don't run any host-only tests. Also, respect any `--host`
136-
// overrides as done for `hosts`.
137-
if build.flags.host.len() > 0 {
138-
&build.flags.host[..]
139-
} else if build.flags.target.len() > 0 {
130+
if build.config.run_host_only {
140131
&[]
141132
} else if self.only_build {
142-
&build.config.host[..1]
133+
build.build_triple()
143134
} else {
144-
&build.config.host[..]
135+
&build.hosts
145136
}
146137
} else {
147138
&build.targets
@@ -288,7 +279,7 @@ impl<'a> Builder<'a> {
288279

289280
let builder = Builder {
290281
build: build,
291-
top_stage: build.flags.stage.unwrap_or(2),
282+
top_stage: build.config.stage.unwrap_or(2),
292283
kind: kind,
293284
cache: Cache::new(),
294285
stack: RefCell::new(Vec::new()),
@@ -307,7 +298,7 @@ impl<'a> Builder<'a> {
307298
}
308299

309300
pub fn run(build: &Build) {
310-
let (kind, paths) = match build.flags.cmd {
301+
let (kind, paths) = match build.config.cmd {
311302
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
312303
Subcommand::Doc { ref paths } => (Kind::Doc, &paths[..]),
313304
Subcommand::Test { ref paths, .. } => (Kind::Test, &paths[..]),
@@ -319,7 +310,7 @@ impl<'a> Builder<'a> {
319310

320311
let builder = Builder {
321312
build: build,
322-
top_stage: build.flags.stage.unwrap_or(2),
313+
top_stage: build.config.stage.unwrap_or(2),
323314
kind: kind,
324315
cache: Cache::new(),
325316
stack: RefCell::new(Vec::new()),
@@ -414,22 +405,19 @@ impl<'a> Builder<'a> {
414405
}
415406
}
416407

417-
pub fn rustdoc(&self, compiler: Compiler) -> PathBuf {
418-
self.ensure(tool::Rustdoc { target_compiler: compiler })
408+
pub fn rustdoc(&self, host: Interned<String>) -> PathBuf {
409+
self.ensure(tool::Rustdoc { host })
419410
}
420411

421-
pub fn rustdoc_cmd(&self, compiler: Compiler) -> Command {
412+
pub fn rustdoc_cmd(&self, host: Interned<String>) -> Command {
422413
let mut cmd = Command::new(&self.out.join("bootstrap/debug/rustdoc"));
414+
let compiler = self.compiler(self.top_stage, host);
423415
cmd
424416
.env("RUSTC_STAGE", compiler.stage.to_string())
425-
.env("RUSTC_SYSROOT", if compiler.is_snapshot(&self.build) {
426-
INTERNER.intern_path(self.build.rustc_snapshot_libdir())
427-
} else {
428-
self.sysroot(compiler)
429-
})
430-
.env("RUSTC_LIBDIR", self.rustc_libdir(compiler))
417+
.env("RUSTC_SYSROOT", self.sysroot(compiler))
418+
.env("RUSTC_LIBDIR", self.sysroot_libdir(compiler, self.build.build))
431419
.env("CFG_RELEASE_CHANNEL", &self.build.config.channel)
432-
.env("RUSTDOC_REAL", self.rustdoc(compiler));
420+
.env("RUSTDOC_REAL", self.rustdoc(host));
433421
cmd
434422
}
435423

@@ -483,7 +471,7 @@ impl<'a> Builder<'a> {
483471
.env("RUSTC_RPATH", self.config.rust_rpath.to_string())
484472
.env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc"))
485473
.env("RUSTDOC_REAL", if cmd == "doc" || cmd == "test" {
486-
self.rustdoc(compiler)
474+
self.rustdoc(compiler.host)
487475
} else {
488476
PathBuf::from("/path/to/nowhere/rustdoc/not/required")
489477
})
@@ -543,12 +531,12 @@ impl<'a> Builder<'a> {
543531
// Ignore incremental modes except for stage0, since we're
544532
// not guaranteeing correctness across builds if the compiler
545533
// is changing under your feet.`
546-
if self.flags.incremental && compiler.stage == 0 {
534+
if self.config.incremental && compiler.stage == 0 {
547535
let incr_dir = self.incremental_dir(compiler);
548536
cargo.env("RUSTC_INCREMENTAL", incr_dir);
549537
}
550538

551-
if let Some(ref on_fail) = self.flags.on_fail {
539+
if let Some(ref on_fail) = self.config.on_fail {
552540
cargo.env("RUSTC_ON_FAIL", on_fail);
553541
}
554542

src/bootstrap/cc.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
//! everything.
3333
3434
use std::process::Command;
35+
use std::iter;
3536

3637
use build_helper::{cc2ar, output};
3738
use gcc;
@@ -43,47 +44,41 @@ use cache::Interned;
4344
pub fn find(build: &mut Build) {
4445
// For all targets we're going to need a C compiler for building some shims
4546
// and such as well as for being a linker for Rust code.
46-
//
47-
// This includes targets that aren't necessarily passed on the commandline
48-
// (FIXME: Perhaps it shouldn't?)
49-
for target in &build.config.target {
47+
for target in build.targets.iter().chain(&build.hosts).cloned().chain(iter::once(build.build)) {
5048
let mut cfg = gcc::Config::new();
5149
cfg.cargo_metadata(false).opt_level(0).debug(false)
52-
.target(target).host(&build.build);
50+
.target(&target).host(&build.build);
5351

5452
let config = build.config.target_config.get(&target);
5553
if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {
5654
cfg.compiler(cc);
5755
} else {
58-
set_compiler(&mut cfg, "gcc", *target, config, build);
56+
set_compiler(&mut cfg, "gcc", target, config, build);
5957
}
6058

6159
let compiler = cfg.get_compiler();
62-
let ar = cc2ar(compiler.path(), target);
63-
build.verbose(&format!("CC_{} = {:?}", target, compiler.path()));
60+
let ar = cc2ar(compiler.path(), &target);
61+
build.verbose(&format!("CC_{} = {:?}", &target, compiler.path()));
6462
if let Some(ref ar) = ar {
65-
build.verbose(&format!("AR_{} = {:?}", target, ar));
63+
build.verbose(&format!("AR_{} = {:?}", &target, ar));
6664
}
67-
build.cc.insert(*target, (compiler, ar));
65+
build.cc.insert(target, (compiler, ar));
6866
}
6967

7068
// For all host triples we need to find a C++ compiler as well
71-
//
72-
// This includes hosts that aren't necessarily passed on the commandline
73-
// (FIXME: Perhaps it shouldn't?)
74-
for host in &build.config.host {
69+
for host in build.hosts.iter().cloned().chain(iter::once(build.build)) {
7570
let mut cfg = gcc::Config::new();
7671
cfg.cargo_metadata(false).opt_level(0).debug(false).cpp(true)
77-
.target(host).host(&build.build);
78-
let config = build.config.target_config.get(host);
72+
.target(&host).host(&build.build);
73+
let config = build.config.target_config.get(&host);
7974
if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
8075
cfg.compiler(cxx);
8176
} else {
82-
set_compiler(&mut cfg, "g++", *host, config, build);
77+
set_compiler(&mut cfg, "g++", host, config, build);
8378
}
8479
let compiler = cfg.get_compiler();
8580
build.verbose(&format!("CXX_{} = {:?}", host, compiler.path()));
86-
build.cxx.insert(*host, compiler);
81+
build.cxx.insert(host, compiler);
8782
}
8883
}
8984

src/bootstrap/channel.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::process::Command;
2121
use build_helper::output;
2222

2323
use Build;
24+
use config::Config;
2425

2526
// The version number
2627
pub const CFG_RELEASE_NUM: &str = "1.21.0";
@@ -41,9 +42,9 @@ struct Info {
4142
}
4243

4344
impl GitInfo {
44-
pub fn new(dir: &Path) -> GitInfo {
45+
pub fn new(config: &Config, dir: &Path) -> GitInfo {
4546
// See if this even begins to look like a git dir
46-
if !dir.join(".git").exists() {
47+
if config.ignore_git || !dir.join(".git").exists() {
4748
return GitInfo { inner: None }
4849
}
4950

src/bootstrap/check.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl Step for Cargotest {
164164
try_run(build, cmd.arg(&build.initial_cargo)
165165
.arg(&out_dir)
166166
.env("RUSTC", builder.rustc(compiler))
167-
.env("RUSTDOC", builder.rustdoc(compiler)));
167+
.env("RUSTDOC", builder.rustdoc(compiler.host)));
168168
}
169169
}
170170

@@ -565,7 +565,7 @@ impl Step for Compiletest {
565565

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

571571
cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
@@ -625,7 +625,7 @@ impl Step for Compiletest {
625625
cmd.arg("--system-llvm");
626626
}
627627

628-
cmd.args(&build.flags.cmd.test_args());
628+
cmd.args(&build.config.cmd.test_args());
629629

630630
if build.is_verbose() {
631631
cmd.arg("--verbose");
@@ -814,13 +814,13 @@ fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
814814
}
815815

816816
println!("doc tests for: {}", markdown.display());
817-
let mut cmd = builder.rustdoc_cmd(compiler);
817+
let mut cmd = builder.rustdoc_cmd(compiler.host);
818818
build.add_rust_test_threads(&mut cmd);
819819
cmd.arg("--test");
820820
cmd.arg(markdown);
821821
cmd.env("RUSTC_BOOTSTRAP", "1");
822822

823-
let test_args = build.flags.cmd.test_args().join(" ");
823+
let test_args = build.config.cmd.test_args().join(" ");
824824
cmd.arg("--test-args").arg(test_args);
825825

826826
if build.config.quiet_tests {
@@ -1051,7 +1051,7 @@ impl Step for Crate {
10511051
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
10521052

10531053
cargo.arg("--");
1054-
cargo.args(&build.flags.cmd.test_args());
1054+
cargo.args(&build.config.cmd.test_args());
10551055

10561056
if build.config.quiet_tests {
10571057
cargo.arg("--quiet");
@@ -1147,6 +1147,7 @@ pub struct Distcheck;
11471147

11481148
impl Step for Distcheck {
11491149
type Output = ();
1150+
const ONLY_BUILD: bool = true;
11501151

11511152
fn should_run(run: ShouldRun) -> ShouldRun {
11521153
run.path("distcheck")
@@ -1160,16 +1161,6 @@ impl Step for Distcheck {
11601161
fn run(self, builder: &Builder) {
11611162
let build = builder.build;
11621163

1163-
if *build.build != *"x86_64-unknown-linux-gnu" {
1164-
return
1165-
}
1166-
if !build.config.host.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
1167-
return
1168-
}
1169-
if !build.config.target.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
1170-
return
1171-
}
1172-
11731164
println!("Distcheck");
11741165
let dir = build.out.join("tmp").join("distcheck");
11751166
let _ = fs::remove_dir_all(&dir);
@@ -1236,7 +1227,7 @@ impl Step for Bootstrap {
12361227
if !build.fail_fast {
12371228
cmd.arg("--no-fail-fast");
12381229
}
1239-
cmd.arg("--").args(&build.flags.cmd.test_args());
1230+
cmd.arg("--").args(&build.config.cmd.test_args());
12401231
try_run(build, &mut cmd);
12411232
}
12421233

src/bootstrap/clean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn clean(build: &Build) {
2626
rm_rf(&build.out.join("tmp"));
2727
rm_rf(&build.out.join("dist"));
2828

29-
for host in build.config.host.iter() {
29+
for host in &build.hosts {
3030
let entries = match build.out.join(host).read_dir() {
3131
Ok(iter) => iter,
3232
Err(_) => continue,

src/bootstrap/compile.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use serde_json;
3232
use util::{exe, libdir, is_dylib, copy};
3333
use {Build, Compiler, Mode};
3434
use native;
35+
use tool;
3536

3637
use cache::{INTERNER, Interned};
3738
use builder::{Step, RunConfig, ShouldRun, Builder};
@@ -198,6 +199,12 @@ impl Step for StdLink {
198199
// for reason why the sanitizers are not built in stage0.
199200
copy_apple_sanitizer_dylibs(&build.native_dir(target), "osx", &libdir);
200201
}
202+
203+
builder.ensure(tool::CleanTools {
204+
compiler: target_compiler,
205+
target: target,
206+
mode: Mode::Libstd,
207+
});
201208
}
202209
}
203210

@@ -389,6 +396,11 @@ impl Step for TestLink {
389396
target);
390397
add_to_sysroot(&builder.sysroot_libdir(target_compiler, target),
391398
&libtest_stamp(build, compiler, target));
399+
builder.ensure(tool::CleanTools {
400+
compiler: target_compiler,
401+
target: target,
402+
mode: Mode::Libtest,
403+
});
392404
}
393405
}
394406

@@ -567,6 +579,11 @@ impl Step for RustcLink {
567579
target);
568580
add_to_sysroot(&builder.sysroot_libdir(target_compiler, target),
569581
&librustc_stamp(build, compiler, target));
582+
builder.ensure(tool::CleanTools {
583+
compiler: target_compiler,
584+
target: target,
585+
mode: Mode::Librustc,
586+
});
570587
}
571588
}
572589

@@ -679,10 +696,10 @@ impl Step for Assemble {
679696
// link to these. (FIXME: Is that correct? It seems to be correct most
680697
// of the time but I think we do link to these for stage2/bin compilers
681698
// when not performing a full bootstrap).
682-
if builder.build.flags.keep_stage.map_or(false, |s| target_compiler.stage <= s) {
699+
if builder.build.config.keep_stage.map_or(false, |s| target_compiler.stage <= s) {
683700
builder.verbose("skipping compilation of compiler due to --keep-stage");
684701
let compiler = build_compiler;
685-
for stage in 0..min(target_compiler.stage, builder.flags.keep_stage.unwrap()) {
702+
for stage in 0..min(target_compiler.stage, builder.config.keep_stage.unwrap()) {
686703
let target_compiler = builder.compiler(stage, target_compiler.host);
687704
let target = target_compiler.host;
688705
builder.ensure(StdLink { compiler, target_compiler, target });

0 commit comments

Comments
 (0)