Skip to content

Commit

Permalink
Unify flags into config.
Browse files Browse the repository at this point in the history
This introduces a slight change in behavior, where we unilaterally
respect the --host and --target parameters passed for all sanity
checking and runtime configuration.
  • Loading branch information
Mark-Simulacrum committed Aug 13, 2017
1 parent f774bce commit 44ffb61
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 117 deletions.
7 changes: 3 additions & 4 deletions src/bootstrap/bin/main.rs
Expand Up @@ -21,11 +21,10 @@ extern crate bootstrap;

use std::env;

use bootstrap::{Flags, Config, Build};
use bootstrap::{Config, Build};

fn main() {
let args = env::args().skip(1).collect::<Vec<_>>();
let flags = Flags::parse(&args);
let config = Config::parse(&flags.build, flags.config.clone());
Build::new(flags, config).build();
let config = Config::parse(&args);
Build::new(config).build();
}
31 changes: 12 additions & 19 deletions src/bootstrap/builder.rs
Expand Up @@ -120,28 +120,21 @@ impl StepDescription {
fn maybe_run(&self, builder: &Builder, path: Option<&Path>) {
let build = builder.build;
let hosts = if self.only_build_targets || self.only_build {
&build.config.host[..1]
build.build_triple()
} else {
&build.hosts
};

// Determine the actual targets participating in this rule.
// NOTE: We should keep the full projection from build triple to
// the hosts for the dist steps, now that the hosts array above is
// truncated to avoid duplication of work in that case. Therefore
// the original non-shadowed hosts array is used below.
// Determine the targets participating in this rule.
let targets = if self.only_hosts {
// If --target was specified but --host wasn't specified,
// don't run any host-only tests. Also, respect any `--host`
// overrides as done for `hosts`.
if build.flags.host.len() > 0 {
&build.flags.host[..]
} else if build.flags.target.len() > 0 {
// If --target was specified but --host wasn't specified, don't run
// any host-only tests.
if build.config.hosts.is_empty() && !build.config.targets.is_empty() {
&[]
} else if self.only_build {
&build.config.host[..1]
build.build_triple()
} else {
&build.config.host[..]
&build.hosts
}
} else {
&build.targets
Expand Down Expand Up @@ -288,7 +281,7 @@ impl<'a> Builder<'a> {

let builder = Builder {
build: build,
top_stage: build.flags.stage.unwrap_or(2),
top_stage: build.config.stage.unwrap_or(2),
kind: kind,
cache: Cache::new(),
stack: RefCell::new(Vec::new()),
Expand All @@ -307,7 +300,7 @@ impl<'a> Builder<'a> {
}

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

let builder = Builder {
build: build,
top_stage: build.flags.stage.unwrap_or(2),
top_stage: build.config.stage.unwrap_or(2),
kind: kind,
cache: Cache::new(),
stack: RefCell::new(Vec::new()),
Expand Down Expand Up @@ -543,12 +536,12 @@ impl<'a> Builder<'a> {
// Ignore incremental modes except for stage0, since we're
// not guaranteeing correctness across builds if the compiler
// is changing under your feet.`
if self.flags.incremental && compiler.stage == 0 {
if self.config.incremental && compiler.stage == 0 {
let incr_dir = self.incremental_dir(compiler);
cargo.env("RUSTC_INCREMENTAL", incr_dir);
}

if let Some(ref on_fail) = self.flags.on_fail {
if let Some(ref on_fail) = self.config.on_fail {
cargo.env("RUSTC_ON_FAIL", on_fail);
}

Expand Down
31 changes: 13 additions & 18 deletions src/bootstrap/cc.rs
Expand Up @@ -32,6 +32,7 @@
//! everything.

use std::process::Command;
use std::iter;

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

let config = build.config.target_config.get(&target);
if let Some(cc) = config.and_then(|c| c.cc.as_ref()) {
cfg.compiler(cc);
} else {
set_compiler(&mut cfg, "gcc", *target, config, build);
set_compiler(&mut cfg, "gcc", target, config, build);
}

let compiler = cfg.get_compiler();
let ar = cc2ar(compiler.path(), target);
build.verbose(&format!("CC_{} = {:?}", target, compiler.path()));
let ar = cc2ar(compiler.path(), &target);
build.verbose(&format!("CC_{} = {:?}", &target, compiler.path()));
if let Some(ref ar) = ar {
build.verbose(&format!("AR_{} = {:?}", target, ar));
build.verbose(&format!("AR_{} = {:?}", &target, ar));
}
build.cc.insert(*target, (compiler, ar));
build.cc.insert(target, (compiler, ar));
}

// For all host triples we need to find a C++ compiler as well
//
// This includes hosts that aren't necessarily passed on the commandline
// (FIXME: Perhaps it shouldn't?)
for host in &build.config.host {
for host in build.hosts.iter().cloned().chain(iter::once(build.build)) {
let mut cfg = gcc::Config::new();
cfg.cargo_metadata(false).opt_level(0).debug(false).cpp(true)
.target(host).host(&build.build);
let config = build.config.target_config.get(host);
.target(&host).host(&build.build);
let config = build.config.target_config.get(&host);
if let Some(cxx) = config.and_then(|c| c.cxx.as_ref()) {
cfg.compiler(cxx);
} else {
set_compiler(&mut cfg, "g++", *host, config, build);
set_compiler(&mut cfg, "g++", host, config, build);
}
let compiler = cfg.get_compiler();
build.verbose(&format!("CXX_{} = {:?}", host, compiler.path()));
build.cxx.insert(*host, compiler);
build.cxx.insert(host, compiler);
}
}

Expand Down
19 changes: 5 additions & 14 deletions src/bootstrap/check.rs
Expand Up @@ -625,7 +625,7 @@ impl Step for Compiletest {
cmd.arg("--system-llvm");
}

cmd.args(&build.flags.cmd.test_args());
cmd.args(&build.config.cmd.test_args());

if build.is_verbose() {
cmd.arg("--verbose");
Expand Down Expand Up @@ -820,7 +820,7 @@ fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
cmd.arg(markdown);
cmd.env("RUSTC_BOOTSTRAP", "1");

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

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

cargo.arg("--");
cargo.args(&build.flags.cmd.test_args());
cargo.args(&build.config.cmd.test_args());

if build.config.quiet_tests {
cargo.arg("--quiet");
Expand Down Expand Up @@ -1147,6 +1147,7 @@ pub struct Distcheck;

impl Step for Distcheck {
type Output = ();
const ONLY_BUILD: bool = true;

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

if *build.build != *"x86_64-unknown-linux-gnu" {
return
}
if !build.config.host.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
return
}
if !build.config.target.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
return
}

println!("Distcheck");
let dir = build.out.join("tmp").join("distcheck");
let _ = fs::remove_dir_all(&dir);
Expand Down Expand Up @@ -1236,7 +1227,7 @@ impl Step for Bootstrap {
if !build.fail_fast {
cmd.arg("--no-fail-fast");
}
cmd.arg("--").args(&build.flags.cmd.test_args());
cmd.arg("--").args(&build.config.cmd.test_args());
try_run(build, &mut cmd);
}

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/clean.rs
Expand Up @@ -26,7 +26,7 @@ pub fn clean(build: &Build) {
rm_rf(&build.out.join("tmp"));
rm_rf(&build.out.join("dist"));

for host in build.config.host.iter() {
for host in &build.hosts {
let entries = match build.out.join(host).read_dir() {
Ok(iter) => iter,
Err(_) => continue,
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/compile.rs
Expand Up @@ -679,10 +679,10 @@ impl Step for Assemble {
// link to these. (FIXME: Is that correct? It seems to be correct most
// of the time but I think we do link to these for stage2/bin compilers
// when not performing a full bootstrap).
if builder.build.flags.keep_stage.map_or(false, |s| target_compiler.stage <= s) {
if builder.build.config.keep_stage.map_or(false, |s| target_compiler.stage <= s) {
builder.verbose("skipping compilation of compiler due to --keep-stage");
let compiler = build_compiler;
for stage in 0..min(target_compiler.stage, builder.flags.keep_stage.unwrap()) {
for stage in 0..min(target_compiler.stage, builder.config.keep_stage.unwrap()) {
let target_compiler = builder.compiler(stage, target_compiler.host);
let target = target_compiler.host;
builder.ensure(StdLink { compiler, target_compiler, target });
Expand Down
67 changes: 55 additions & 12 deletions src/bootstrap/config.rs
Expand Up @@ -19,11 +19,14 @@ use std::fs::{self, File};
use std::io::prelude::*;
use std::path::PathBuf;
use std::process;
use std::cmp;

use num_cpus;
use toml;
use util::{exe, push_exe_path};
use cache::{INTERNER, Interned};
use flags::Flags;
pub use flags::Subcommand;

/// Global configuration for the entire build and/or bootstrap.
///
Expand Down Expand Up @@ -52,6 +55,14 @@ pub struct Config {
pub sanitizers: bool,
pub profiler: bool,

pub on_fail: Option<String>,
pub stage: Option<u32>,
pub keep_stage: Option<u32>,
pub src: PathBuf,
pub jobs: Option<u32>,
pub cmd: Subcommand,
pub incremental: bool,

// llvm codegen options
pub llvm_enabled: bool,
pub llvm_assertions: bool,
Expand Down Expand Up @@ -79,8 +90,8 @@ pub struct Config {
pub rust_dist_src: bool,

pub build: Interned<String>,
pub host: Vec<Interned<String>>,
pub target: Vec<Interned<String>>,
pub hosts: Vec<Interned<String>>,
pub targets: Vec<Interned<String>>,
pub local_rebuild: bool,

// dist misc
Expand Down Expand Up @@ -265,7 +276,9 @@ struct TomlTarget {
}

impl Config {
pub fn parse(build: &str, file: Option<PathBuf>) -> Config {
pub fn parse(args: &[String]) -> Config {
let flags = Flags::parse(&args);
let file = flags.config.clone();
let mut config = Config::default();
config.llvm_enabled = true;
config.llvm_optimize = true;
Expand All @@ -277,11 +290,19 @@ impl Config {
config.docs = true;
config.rust_rpath = true;
config.rust_codegen_units = 1;
config.build = INTERNER.intern_str(build);
config.build = flags.build;
config.channel = "dev".to_string();
config.codegen_tests = true;
config.rust_dist_src = true;

config.on_fail = flags.on_fail;
config.stage = flags.stage;
config.src = flags.src;
config.jobs = flags.jobs;
config.cmd = flags.cmd;
config.incremental = flags.incremental;
config.keep_stage = flags.keep_stage;

let toml = file.map(|file| {
let mut f = t!(File::open(&file));
let mut contents = String::new();
Expand All @@ -298,20 +319,41 @@ impl Config {

let build = toml.build.clone().unwrap_or(Build::default());
set(&mut config.build, build.build.clone().map(|x| INTERNER.intern_string(x)));
config.host.push(config.build.clone());
config.hosts.push(config.build.clone());
for host in build.host.iter() {
let host = INTERNER.intern_str(host);
if !config.host.contains(&host) {
config.host.push(host);
if !config.hosts.contains(&host) {
config.hosts.push(host);
}
}
for target in config.host.iter().cloned()
for target in config.hosts.iter().cloned()
.chain(build.target.iter().map(|s| INTERNER.intern_str(s)))
{
if !config.target.contains(&target) {
config.target.push(target);
if !config.targets.contains(&target) {
config.targets.push(target);
}
}
config.hosts = if !flags.host.is_empty() {
for host in flags.host.iter() {
if !config.hosts.contains(host) {
panic!("specified host `{}` is not in configuration", host);
}
}
flags.host
} else {
config.hosts
};
config.targets = if !flags.target.is_empty() {
for target in flags.target.iter() {
if !config.targets.contains(target) {
panic!("specified target `{}` is not in configuration", target);
}
}
flags.target
} else {
config.targets
};

config.nodejs = build.nodejs.map(PathBuf::from);
config.gdb = build.gdb.map(PathBuf::from);
config.python = build.python.map(PathBuf::from);
Expand All @@ -327,6 +369,7 @@ impl Config {
set(&mut config.sanitizers, build.sanitizers);
set(&mut config.profiler, build.profiler);
set(&mut config.openssl_static, build.openssl_static);
config.verbose = cmp::max(config.verbose, flags.verbose);

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

}
"CFG_TARGET" if value.len() > 0 => {
self.target.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
self.targets.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
}
"CFG_EXPERIMENTAL_TARGETS" if value.len() > 0 => {
self.llvm_experimental_targets = Some(value.to_string());
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/dist.rs
Expand Up @@ -546,7 +546,7 @@ impl Step for Std {
// We want to package up as many target libraries as possible
// for the `rust-std` package, so if this is a host target we
// depend on librustc and otherwise we just depend on libtest.
if build.config.host.iter().any(|t| t == target) {
if build.hosts.iter().any(|t| t == target) {
builder.ensure(compile::Rustc { compiler, target });
} else {
builder.ensure(compile::Test { compiler, target });
Expand Down

0 comments on commit 44ffb61

Please sign in to comment.