Skip to content

Commit 78125ec

Browse files
Stop implicitly appending triples to config.toml hosts and targets
Previously, the CLI --target/--host definitions and configured options differed in their effect: when setting these on the CLI, only the passed triples would be compiled for, while in config.toml we would also compile for the build triple and any host triples. This is needlessly confusing; users expect --target and --host to be identical to editing the configuration file. The new behavior is to respect --host and --target when passed as the *only* configured triples (no triples are implicitly added). The default for --host is the build triple, and the default for --target is the host triple(s), either configured or the default build triple.
1 parent b4eb099 commit 78125ec

File tree

3 files changed

+53
-46
lines changed

3 files changed

+53
-46
lines changed

config.toml.example

+7-8
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,18 @@
120120
# Defaults to host platform
121121
#build = "x86_64-unknown-linux-gnu"
122122

123-
# In addition to the build triple, other triples to produce full compiler
124-
# toolchains for. Each of these triples will be bootstrapped from the build
125-
# triple and then will continue to bootstrap themselves. This platform must
126-
# currently be able to run all of the triples provided here.
123+
# Which triples to produce a compiler toolchain for. Each of these triples will
124+
# be bootstrapped from the build triple themselves.
127125
#
128126
# Defaults to just the build triple
129127
#host = ["x86_64-unknown-linux-gnu"]
130128

131-
# In addition to all host triples, other triples to produce the standard library
132-
# for. Each host triple will be used to produce a copy of the standard library
133-
# for each target triple.
129+
# Which triples to build libraries (core/alloc/std/test/proc_macro) for. Each of
130+
# these triples will be bootstrapped from the build triple themselves.
134131
#
135-
# Defaults to just the build triple
132+
# Defaults to `host`. If you set this explicitly, you likely want to add all
133+
# host triples to this list as well in order for those host toolchains to be
134+
# able to compile programs for their native target.
136135
#target = ["x86_64-unknown-linux-gnu"]
137136

138137
# Use this directory to store build artifacts.

src/bootstrap/config.rs

+24-28
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,8 @@ struct TomlConfig {
273273
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
274274
struct Build {
275275
build: Option<String>,
276-
#[serde(default)]
277-
host: Vec<String>,
278-
#[serde(default)]
279-
target: Vec<String>,
276+
host: Option<Vec<String>>,
277+
target: Option<Vec<String>>,
280278
// This is ignored, the rust code always gets the build directory from the `BUILD_DIR` env variable
281279
build_dir: Option<String>,
282280
cargo: Option<String>,
@@ -505,11 +503,6 @@ impl Config {
505503
config.out = dir;
506504
}
507505

508-
// If --target was specified but --host wasn't specified, don't run any host-only tests.
509-
let has_hosts = !flags.host.is_empty();
510-
let has_targets = !flags.target.is_empty();
511-
config.skip_only_host_steps = !has_hosts && has_targets;
512-
513506
let toml = file
514507
.map(|file| {
515508
let contents = t!(fs::read_to_string(&file));
@@ -528,25 +521,28 @@ impl Config {
528521
.unwrap_or_else(TomlConfig::default);
529522

530523
let build = toml.build.clone().unwrap_or_default();
531-
// set by bootstrap.py
532-
config.hosts.push(config.build);
533-
for host in build.host.iter().map(|h| TargetSelection::from_user(h)) {
534-
if !config.hosts.contains(&host) {
535-
config.hosts.push(host);
536-
}
537-
}
538-
for target in config
539-
.hosts
540-
.iter()
541-
.copied()
542-
.chain(build.target.iter().map(|h| TargetSelection::from_user(h)))
543-
{
544-
if !config.targets.contains(&target) {
545-
config.targets.push(target);
546-
}
547-
}
548-
config.hosts = if !flags.host.is_empty() { flags.host } else { config.hosts };
549-
config.targets = if !flags.target.is_empty() { flags.target } else { config.targets };
524+
525+
// If --target was specified but --host wasn't specified, don't run any host-only tests.
526+
let has_hosts = build.host.is_some() || flags.host.is_some();
527+
let has_targets = build.target.is_some() || flags.target.is_some();
528+
config.skip_only_host_steps = !has_hosts && has_targets;
529+
530+
config.hosts = if let Some(arg_host) = flags.host.clone() {
531+
arg_host
532+
} else if let Some(file_host) = build.host {
533+
file_host.iter().map(|h| TargetSelection::from_user(h)).collect()
534+
} else {
535+
vec![config.build]
536+
};
537+
config.targets = if let Some(arg_target) = flags.target.clone() {
538+
arg_target
539+
} else if let Some(file_target) = build.target {
540+
file_target.iter().map(|h| TargetSelection::from_user(h)).collect()
541+
} else {
542+
// If target is *not* configured, then default to the host
543+
// toolchains.
544+
config.hosts.clone()
545+
};
550546

551547
config.nodejs = build.nodejs.map(PathBuf::from);
552548
config.gdb = build.gdb.map(PathBuf::from);

src/bootstrap/flags.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub struct Flags {
2020
pub stage: Option<u32>,
2121
pub keep_stage: Vec<u32>,
2222

23-
pub host: Vec<TargetSelection>,
24-
pub target: Vec<TargetSelection>,
23+
pub host: Option<Vec<TargetSelection>>,
24+
pub target: Option<Vec<TargetSelection>>,
2525
pub config: Option<PathBuf>,
2626
pub jobs: Option<u32>,
2727
pub cmd: Subcommand,
@@ -526,14 +526,26 @@ Arguments:
526526
.into_iter()
527527
.map(|j| j.parse().expect("`keep-stage` should be a number"))
528528
.collect(),
529-
host: split(&matches.opt_strs("host"))
530-
.into_iter()
531-
.map(|x| TargetSelection::from_user(&x))
532-
.collect::<Vec<_>>(),
533-
target: split(&matches.opt_strs("target"))
534-
.into_iter()
535-
.map(|x| TargetSelection::from_user(&x))
536-
.collect::<Vec<_>>(),
529+
host: if matches.opt_present("host") {
530+
Some(
531+
split(&matches.opt_strs("host"))
532+
.into_iter()
533+
.map(|x| TargetSelection::from_user(&x))
534+
.collect::<Vec<_>>(),
535+
)
536+
} else {
537+
None
538+
},
539+
target: if matches.opt_present("target") {
540+
Some(
541+
split(&matches.opt_strs("target"))
542+
.into_iter()
543+
.map(|x| TargetSelection::from_user(&x))
544+
.collect::<Vec<_>>(),
545+
)
546+
} else {
547+
None
548+
},
537549
config: cfg_file,
538550
jobs: matches.opt_str("jobs").map(|j| j.parse().expect("`jobs` should be a number")),
539551
cmd,

0 commit comments

Comments
 (0)