Skip to content

Commit 44ffb61

Browse files
Unify flags into config.
This introduces a slight change in behavior, where we unilaterally respect the --host and --target parameters passed for all sanity checking and runtime configuration.
1 parent f774bce commit 44ffb61

File tree

12 files changed

+126
-117
lines changed

12 files changed

+126
-117
lines changed

src/bootstrap/bin/main.rs

Lines changed: 3 additions & 4 deletions
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

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,21 @@ 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 --target was specified but --host wasn't specified, don't run
131+
// any host-only tests.
132+
if build.config.hosts.is_empty() && !build.config.targets.is_empty() {
140133
&[]
141134
} else if self.only_build {
142-
&build.config.host[..1]
135+
build.build_triple()
143136
} else {
144-
&build.config.host[..]
137+
&build.hosts
145138
}
146139
} else {
147140
&build.targets
@@ -288,7 +281,7 @@ impl<'a> Builder<'a> {
288281

289282
let builder = Builder {
290283
build: build,
291-
top_stage: build.flags.stage.unwrap_or(2),
284+
top_stage: build.config.stage.unwrap_or(2),
292285
kind: kind,
293286
cache: Cache::new(),
294287
stack: RefCell::new(Vec::new()),
@@ -307,7 +300,7 @@ impl<'a> Builder<'a> {
307300
}
308301

309302
pub fn run(build: &Build) {
310-
let (kind, paths) = match build.flags.cmd {
303+
let (kind, paths) = match build.config.cmd {
311304
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
312305
Subcommand::Doc { ref paths } => (Kind::Doc, &paths[..]),
313306
Subcommand::Test { ref paths, .. } => (Kind::Test, &paths[..]),
@@ -319,7 +312,7 @@ impl<'a> Builder<'a> {
319312

320313
let builder = Builder {
321314
build: build,
322-
top_stage: build.flags.stage.unwrap_or(2),
315+
top_stage: build.config.stage.unwrap_or(2),
323316
kind: kind,
324317
cache: Cache::new(),
325318
stack: RefCell::new(Vec::new()),
@@ -543,12 +536,12 @@ impl<'a> Builder<'a> {
543536
// Ignore incremental modes except for stage0, since we're
544537
// not guaranteeing correctness across builds if the compiler
545538
// is changing under your feet.`
546-
if self.flags.incremental && compiler.stage == 0 {
539+
if self.config.incremental && compiler.stage == 0 {
547540
let incr_dir = self.incremental_dir(compiler);
548541
cargo.env("RUSTC_INCREMENTAL", incr_dir);
549542
}
550543

551-
if let Some(ref on_fail) = self.flags.on_fail {
544+
if let Some(ref on_fail) = self.config.on_fail {
552545
cargo.env("RUSTC_ON_FAIL", on_fail);
553546
}
554547

src/bootstrap/cc.rs

Lines changed: 13 additions & 18 deletions
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/check.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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");
@@ -820,7 +820,7 @@ fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,10 +679,10 @@ impl Step for Assemble {
679679
// link to these. (FIXME: Is that correct? It seems to be correct most
680680
// of the time but I think we do link to these for stage2/bin compilers
681681
// when not performing a full bootstrap).
682-
if builder.build.flags.keep_stage.map_or(false, |s| target_compiler.stage <= s) {
682+
if builder.build.config.keep_stage.map_or(false, |s| target_compiler.stage <= s) {
683683
builder.verbose("skipping compilation of compiler due to --keep-stage");
684684
let compiler = build_compiler;
685-
for stage in 0..min(target_compiler.stage, builder.flags.keep_stage.unwrap()) {
685+
for stage in 0..min(target_compiler.stage, builder.config.keep_stage.unwrap()) {
686686
let target_compiler = builder.compiler(stage, target_compiler.host);
687687
let target = target_compiler.host;
688688
builder.ensure(StdLink { compiler, target_compiler, target });

src/bootstrap/config.rs

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ use std::fs::{self, File};
1919
use std::io::prelude::*;
2020
use std::path::PathBuf;
2121
use std::process;
22+
use std::cmp;
2223

2324
use num_cpus;
2425
use toml;
2526
use util::{exe, push_exe_path};
2627
use cache::{INTERNER, Interned};
28+
use flags::Flags;
29+
pub use flags::Subcommand;
2730

2831
/// Global configuration for the entire build and/or bootstrap.
2932
///
@@ -52,6 +55,14 @@ pub struct Config {
5255
pub sanitizers: bool,
5356
pub profiler: bool,
5457

58+
pub on_fail: Option<String>,
59+
pub stage: Option<u32>,
60+
pub keep_stage: Option<u32>,
61+
pub src: PathBuf,
62+
pub jobs: Option<u32>,
63+
pub cmd: Subcommand,
64+
pub incremental: bool,
65+
5566
// llvm codegen options
5667
pub llvm_enabled: bool,
5768
pub llvm_assertions: bool,
@@ -79,8 +90,8 @@ pub struct Config {
7990
pub rust_dist_src: bool,
8091

8192
pub build: Interned<String>,
82-
pub host: Vec<Interned<String>>,
83-
pub target: Vec<Interned<String>>,
93+
pub hosts: Vec<Interned<String>>,
94+
pub targets: Vec<Interned<String>>,
8495
pub local_rebuild: bool,
8596

8697
// dist misc
@@ -265,7 +276,9 @@ struct TomlTarget {
265276
}
266277

267278
impl Config {
268-
pub fn parse(build: &str, file: Option<PathBuf>) -> Config {
279+
pub fn parse(args: &[String]) -> Config {
280+
let flags = Flags::parse(&args);
281+
let file = flags.config.clone();
269282
let mut config = Config::default();
270283
config.llvm_enabled = true;
271284
config.llvm_optimize = true;
@@ -277,11 +290,19 @@ impl Config {
277290
config.docs = true;
278291
config.rust_rpath = true;
279292
config.rust_codegen_units = 1;
280-
config.build = INTERNER.intern_str(build);
293+
config.build = flags.build;
281294
config.channel = "dev".to_string();
282295
config.codegen_tests = true;
283296
config.rust_dist_src = true;
284297

298+
config.on_fail = flags.on_fail;
299+
config.stage = flags.stage;
300+
config.src = flags.src;
301+
config.jobs = flags.jobs;
302+
config.cmd = flags.cmd;
303+
config.incremental = flags.incremental;
304+
config.keep_stage = flags.keep_stage;
305+
285306
let toml = file.map(|file| {
286307
let mut f = t!(File::open(&file));
287308
let mut contents = String::new();
@@ -298,20 +319,41 @@ impl Config {
298319

299320
let build = toml.build.clone().unwrap_or(Build::default());
300321
set(&mut config.build, build.build.clone().map(|x| INTERNER.intern_string(x)));
301-
config.host.push(config.build.clone());
322+
config.hosts.push(config.build.clone());
302323
for host in build.host.iter() {
303324
let host = INTERNER.intern_str(host);
304-
if !config.host.contains(&host) {
305-
config.host.push(host);
325+
if !config.hosts.contains(&host) {
326+
config.hosts.push(host);
306327
}
307328
}
308-
for target in config.host.iter().cloned()
329+
for target in config.hosts.iter().cloned()
309330
.chain(build.target.iter().map(|s| INTERNER.intern_str(s)))
310331
{
311-
if !config.target.contains(&target) {
312-
config.target.push(target);
332+
if !config.targets.contains(&target) {
333+
config.targets.push(target);
313334
}
314335
}
336+
config.hosts = if !flags.host.is_empty() {
337+
for host in flags.host.iter() {
338+
if !config.hosts.contains(host) {
339+
panic!("specified host `{}` is not in configuration", host);
340+
}
341+
}
342+
flags.host
343+
} else {
344+
config.hosts
345+
};
346+
config.targets = if !flags.target.is_empty() {
347+
for target in flags.target.iter() {
348+
if !config.targets.contains(target) {
349+
panic!("specified target `{}` is not in configuration", target);
350+
}
351+
}
352+
flags.target
353+
} else {
354+
config.targets
355+
};
356+
315357
config.nodejs = build.nodejs.map(PathBuf::from);
316358
config.gdb = build.gdb.map(PathBuf::from);
317359
config.python = build.python.map(PathBuf::from);
@@ -327,6 +369,7 @@ impl Config {
327369
set(&mut config.sanitizers, build.sanitizers);
328370
set(&mut config.profiler, build.profiler);
329371
set(&mut config.openssl_static, build.openssl_static);
372+
config.verbose = cmp::max(config.verbose, flags.verbose);
330373

331374
if let Some(ref install) = toml.install {
332375
config.prefix = install.prefix.clone().map(PathBuf::from);
@@ -505,11 +548,11 @@ impl Config {
505548
match key {
506549
"CFG_BUILD" if value.len() > 0 => self.build = INTERNER.intern_str(value),
507550
"CFG_HOST" if value.len() > 0 => {
508-
self.host.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
551+
self.hosts.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
509552

510553
}
511554
"CFG_TARGET" if value.len() > 0 => {
512-
self.target.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
555+
self.targets.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
513556
}
514557
"CFG_EXPERIMENTAL_TARGETS" if value.len() > 0 => {
515558
self.llvm_experimental_targets = Some(value.to_string());

src/bootstrap/dist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl Step for Std {
546546
// We want to package up as many target libraries as possible
547547
// for the `rust-std` package, so if this is a host target we
548548
// depend on librustc and otherwise we just depend on libtest.
549-
if build.config.host.iter().any(|t| t == target) {
549+
if build.hosts.iter().any(|t| t == target) {
550550
builder.ensure(compile::Rustc { compiler, target });
551551
} else {
552552
builder.ensure(compile::Test { compiler, target });

0 commit comments

Comments
 (0)