Skip to content

Commit 5809a7d

Browse files
Move targets, hosts, and build triple into Build.
1 parent 39cf1da commit 5809a7d

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

src/bootstrap/lib.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ pub struct Build {
170170
fail_fast: bool,
171171
verbosity: usize,
172172

173+
// Targets for which to build.
174+
build: String,
175+
hosts: Vec<String>,
176+
targets: Vec<String>,
177+
173178
// Stage 0 (downloaded) compiler and cargo or their local rust equivalents.
174179
initial_rustc: PathBuf,
175180
initial_cargo: PathBuf,
@@ -243,13 +248,38 @@ impl Build {
243248
let cargo_info = channel::GitInfo::new(&src.join("src/tools/cargo"));
244249
let rls_info = channel::GitInfo::new(&src.join("src/tools/rls"));
245250

251+
let hosts = if !flags.host.is_empty() {
252+
for host in flags.host.iter() {
253+
if !config.host.contains(host) {
254+
panic!("specified host `{}` is not in configuration", host);
255+
}
256+
}
257+
flags.host.clone()
258+
} else {
259+
config.host.clone()
260+
};
261+
let targets = if !flags.target.is_empty() {
262+
for target in flags.target.iter() {
263+
if !config.target.contains(target) {
264+
panic!("specified target `{}` is not in configuration", target);
265+
}
266+
}
267+
flags.target.clone()
268+
} else {
269+
config.target.clone()
270+
};
271+
246272
Build {
247273
initial_rustc: config.initial_rustc.clone(),
248274
initial_cargo: config.initial_cargo.clone(),
249275
local_rebuild: config.local_rebuild,
250276
fail_fast: flags.cmd.fail_fast(),
251277
verbosity: cmp::max(flags.verbose, config.verbose),
252278

279+
build: config.host[0].clone(),
280+
hosts: hosts,
281+
targets: targets,
282+
253283
flags: flags,
254284
config: config,
255285
src: src,
@@ -269,6 +299,12 @@ impl Build {
269299
}
270300
}
271301

302+
fn build_slice(&self) -> &[String] {
303+
unsafe {
304+
std::slice::from_raw_parts(&self.build, 1)
305+
}
306+
}
307+
272308
/// Executes the entire build, as configured by the flags and configuration.
273309
pub fn build(&mut self) {
274310
unsafe {
@@ -798,7 +834,7 @@ impl Build {
798834
/// Returns the number of parallel jobs that have been configured for this
799835
/// build.
800836
fn jobs(&self) -> u32 {
801-
self.flags.jobs.unwrap_or(num_cpus::get() as u32)
837+
self.flags.jobs.unwrap_or_else(|| num_cpus::get() as u32)
802838
}
803839

804840
/// Returns the path to the C compiler for the target specified.

src/bootstrap/sanity.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,6 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
194194
}
195195
}
196196

197-
for host in build.flags.host.iter() {
198-
if !build.config.host.contains(host) {
199-
panic!("specified host `{}` is not in configuration", host);
200-
}
201-
}
202-
for target in build.flags.target.iter() {
203-
if !build.config.target.contains(target) {
204-
panic!("specified target `{}` is not in configuration", target);
205-
}
206-
}
207-
208197
let run = |cmd: &mut Command| {
209198
cmd.output().map(|output| {
210199
String::from_utf8_lossy(&output.stdout)

src/bootstrap/step.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,16 +1218,9 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
12181218

12191219
rules.into_iter().flat_map(|(rule, _)| {
12201220
let hosts = if rule.only_host_build || rule.only_build {
1221-
&self.build.config.host[..1]
1222-
} else if self.build.flags.host.len() > 0 {
1223-
&self.build.flags.host
1221+
self.build.build_slice()
12241222
} else {
1225-
&self.build.config.host
1226-
};
1227-
let targets = if self.build.flags.target.len() > 0 {
1228-
&self.build.flags.target
1229-
} else {
1230-
&self.build.config.target
1223+
&self.build.hosts
12311224
};
12321225
// Determine the actual targets participating in this rule.
12331226
// NOTE: We should keep the full projection from build triple to
@@ -1236,19 +1229,18 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
12361229
// the original non-shadowed hosts array is used below.
12371230
let arr = if rule.host {
12381231
// If --target was specified but --host wasn't specified,
1239-
// don't run any host-only tests. Also, respect any `--host`
1240-
// overrides as done for `hosts`.
1232+
// don't run any host-only tests.
12411233
if self.build.flags.host.len() > 0 {
1242-
&self.build.flags.host[..]
1234+
&self.build.hosts
12431235
} else if self.build.flags.target.len() > 0 {
12441236
&[]
12451237
} else if rule.only_build {
1246-
&self.build.config.host[..1]
1238+
self.build.build_slice()
12471239
} else {
1248-
&self.build.config.host[..]
1240+
&self.build.hosts
12491241
}
12501242
} else {
1251-
targets
1243+
&self.build.targets
12521244
};
12531245

12541246
hosts.iter().flat_map(move |host| {

0 commit comments

Comments
 (0)