Skip to content

Commit

Permalink
Move targets, hosts, and build triple into Build.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Jun 27, 2017
1 parent 5cfe2a8 commit ff796e7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 27 deletions.
38 changes: 37 additions & 1 deletion src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ pub struct Build {
fail_fast: bool,
verbosity: usize,

// Targets for which to build.
build: String,
hosts: Vec<String>,
targets: Vec<String>,

// Stage 0 (downloaded) compiler and cargo or their local rust equivalents.
initial_rustc: PathBuf,
initial_cargo: PathBuf,
Expand Down Expand Up @@ -243,13 +248,38 @@ impl Build {
let cargo_info = channel::GitInfo::new(&src.join("src/tools/cargo"));
let rls_info = channel::GitInfo::new(&src.join("src/tools/rls"));

let hosts = if !flags.host.is_empty() {
for host in flags.host.iter() {
if !config.host.contains(host) {
panic!("specified host `{}` is not in configuration", host);
}
}
flags.host.clone()
} else {
config.host.clone()
};
let targets = if !flags.target.is_empty() {
for target in flags.target.iter() {
if !config.target.contains(target) {
panic!("specified target `{}` is not in configuration", target);
}
}
flags.target.clone()
} else {
config.target.clone()
};

Build {
initial_rustc: config.initial_rustc.clone(),
initial_cargo: config.initial_cargo.clone(),
local_rebuild: config.local_rebuild,
fail_fast: flags.cmd.fail_fast(),
verbosity: cmp::max(flags.verbose, config.verbose),

build: config.host[0].clone(),
hosts: hosts,
targets: targets,

flags: flags,
config: config,
src: src,
Expand All @@ -269,6 +299,12 @@ impl Build {
}
}

fn build_slice(&self) -> &[String] {
unsafe {
std::slice::from_raw_parts(&self.build, 1)
}
}

/// Executes the entire build, as configured by the flags and configuration.
pub fn build(&mut self) {
unsafe {
Expand Down Expand Up @@ -798,7 +834,7 @@ impl Build {
/// Returns the number of parallel jobs that have been configured for this
/// build.
fn jobs(&self) -> u32 {
self.flags.jobs.unwrap_or(num_cpus::get() as u32)
self.flags.jobs.unwrap_or_else(|| num_cpus::get() as u32)
}

/// Returns the path to the C compiler for the target specified.
Expand Down
11 changes: 0 additions & 11 deletions src/bootstrap/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,6 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
}
}

for host in build.flags.host.iter() {
if !build.config.host.contains(host) {
panic!("specified host `{}` is not in configuration", host);
}
}
for target in build.flags.target.iter() {
if !build.config.target.contains(target) {
panic!("specified target `{}` is not in configuration", target);
}
}

let run = |cmd: &mut Command| {
cmd.output().map(|output| {
String::from_utf8_lossy(&output.stdout)
Expand Down
22 changes: 7 additions & 15 deletions src/bootstrap/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,16 +1218,9 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?

rules.into_iter().flat_map(|(rule, _)| {
let hosts = if rule.only_host_build || rule.only_build {
&self.build.config.host[..1]
} else if self.build.flags.host.len() > 0 {
&self.build.flags.host
self.build.build_slice()
} else {
&self.build.config.host
};
let targets = if self.build.flags.target.len() > 0 {
&self.build.flags.target
} else {
&self.build.config.target
&self.build.hosts
};
// Determine the actual targets participating in this rule.
// NOTE: We should keep the full projection from build triple to
Expand All @@ -1236,19 +1229,18 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
// the original non-shadowed hosts array is used below.
let arr = if rule.host {
// 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`.
// don't run any host-only tests.
if self.build.flags.host.len() > 0 {
&self.build.flags.host[..]
&self.build.hosts
} else if self.build.flags.target.len() > 0 {
&[]
} else if rule.only_build {
&self.build.config.host[..1]
self.build.build_slice()
} else {
&self.build.config.host[..]
&self.build.hosts
}
} else {
targets
&self.build.targets
};

hosts.iter().flat_map(move |host| {
Expand Down

0 comments on commit ff796e7

Please sign in to comment.