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.
This commit is contained in:
Mark Rousskov 2020-09-06 12:57:13 -04:00
parent b4eb099261
commit 78125ec6b3
3 changed files with 53 additions and 46 deletions

View File

@ -120,19 +120,18 @@
# Defaults to host platform # Defaults to host platform
#build = "x86_64-unknown-linux-gnu" #build = "x86_64-unknown-linux-gnu"
# In addition to the build triple, other triples to produce full compiler # Which triples to produce a compiler toolchain for. Each of these triples will
# toolchains for. Each of these triples will be bootstrapped from the build # be bootstrapped from the build triple themselves.
# triple and then will continue to bootstrap themselves. This platform must
# currently be able to run all of the triples provided here.
# #
# Defaults to just the build triple # Defaults to just the build triple
#host = ["x86_64-unknown-linux-gnu"] #host = ["x86_64-unknown-linux-gnu"]
# In addition to all host triples, other triples to produce the standard library # Which triples to build libraries (core/alloc/std/test/proc_macro) for. Each of
# for. Each host triple will be used to produce a copy of the standard library # these triples will be bootstrapped from the build triple themselves.
# for each target triple.
# #
# Defaults to just the build triple # Defaults to `host`. If you set this explicitly, you likely want to add all
# host triples to this list as well in order for those host toolchains to be
# able to compile programs for their native target.
#target = ["x86_64-unknown-linux-gnu"] #target = ["x86_64-unknown-linux-gnu"]
# Use this directory to store build artifacts. # Use this directory to store build artifacts.

View File

@ -273,10 +273,8 @@ struct TomlConfig {
#[serde(deny_unknown_fields, rename_all = "kebab-case")] #[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct Build { struct Build {
build: Option<String>, build: Option<String>,
#[serde(default)] host: Option<Vec<String>>,
host: Vec<String>, target: Option<Vec<String>>,
#[serde(default)]
target: Vec<String>,
// This is ignored, the rust code always gets the build directory from the `BUILD_DIR` env variable // This is ignored, the rust code always gets the build directory from the `BUILD_DIR` env variable
build_dir: Option<String>, build_dir: Option<String>,
cargo: Option<String>, cargo: Option<String>,
@ -505,11 +503,6 @@ impl Config {
config.out = dir; config.out = dir;
} }
// If --target was specified but --host wasn't specified, don't run any host-only tests.
let has_hosts = !flags.host.is_empty();
let has_targets = !flags.target.is_empty();
config.skip_only_host_steps = !has_hosts && has_targets;
let toml = file let toml = file
.map(|file| { .map(|file| {
let contents = t!(fs::read_to_string(&file)); let contents = t!(fs::read_to_string(&file));
@ -528,25 +521,28 @@ impl Config {
.unwrap_or_else(TomlConfig::default); .unwrap_or_else(TomlConfig::default);
let build = toml.build.clone().unwrap_or_default(); let build = toml.build.clone().unwrap_or_default();
// set by bootstrap.py
config.hosts.push(config.build); // If --target was specified but --host wasn't specified, don't run any host-only tests.
for host in build.host.iter().map(|h| TargetSelection::from_user(h)) { let has_hosts = build.host.is_some() || flags.host.is_some();
if !config.hosts.contains(&host) { let has_targets = build.target.is_some() || flags.target.is_some();
config.hosts.push(host); config.skip_only_host_steps = !has_hosts && has_targets;
}
} config.hosts = if let Some(arg_host) = flags.host.clone() {
for target in config arg_host
.hosts } else if let Some(file_host) = build.host {
.iter() file_host.iter().map(|h| TargetSelection::from_user(h)).collect()
.copied() } else {
.chain(build.target.iter().map(|h| TargetSelection::from_user(h))) vec![config.build]
{ };
if !config.targets.contains(&target) { config.targets = if let Some(arg_target) = flags.target.clone() {
config.targets.push(target); arg_target
} } else if let Some(file_target) = build.target {
} file_target.iter().map(|h| TargetSelection::from_user(h)).collect()
config.hosts = if !flags.host.is_empty() { flags.host } else { config.hosts }; } else {
config.targets = if !flags.target.is_empty() { flags.target } else { config.targets }; // If target is *not* configured, then default to the host
// toolchains.
config.hosts.clone()
};
config.nodejs = build.nodejs.map(PathBuf::from); config.nodejs = build.nodejs.map(PathBuf::from);
config.gdb = build.gdb.map(PathBuf::from); config.gdb = build.gdb.map(PathBuf::from);

View File

@ -20,8 +20,8 @@ pub struct Flags {
pub stage: Option<u32>, pub stage: Option<u32>,
pub keep_stage: Vec<u32>, pub keep_stage: Vec<u32>,
pub host: Vec<TargetSelection>, pub host: Option<Vec<TargetSelection>>,
pub target: Vec<TargetSelection>, pub target: Option<Vec<TargetSelection>>,
pub config: Option<PathBuf>, pub config: Option<PathBuf>,
pub jobs: Option<u32>, pub jobs: Option<u32>,
pub cmd: Subcommand, pub cmd: Subcommand,
@ -526,14 +526,26 @@ Arguments:
.into_iter() .into_iter()
.map(|j| j.parse().expect("`keep-stage` should be a number")) .map(|j| j.parse().expect("`keep-stage` should be a number"))
.collect(), .collect(),
host: split(&matches.opt_strs("host")) host: if matches.opt_present("host") {
.into_iter() Some(
.map(|x| TargetSelection::from_user(&x)) split(&matches.opt_strs("host"))
.collect::<Vec<_>>(), .into_iter()
target: split(&matches.opt_strs("target")) .map(|x| TargetSelection::from_user(&x))
.into_iter() .collect::<Vec<_>>(),
.map(|x| TargetSelection::from_user(&x)) )
.collect::<Vec<_>>(), } else {
None
},
target: if matches.opt_present("target") {
Some(
split(&matches.opt_strs("target"))
.into_iter()
.map(|x| TargetSelection::from_user(&x))
.collect::<Vec<_>>(),
)
} else {
None
},
config: cfg_file, config: cfg_file,
jobs: matches.opt_str("jobs").map(|j| j.parse().expect("`jobs` should be a number")), jobs: matches.opt_str("jobs").map(|j| j.parse().expect("`jobs` should be a number")),
cmd, cmd,