Skip to content

Commit 4f15867

Browse files
committed
bootstrap: Further centralize target defaulting logic.
Background: targets can be specied with or without config files; unneccessarily differences in the logic between those cases has caused a) the bug I tried to fix in the previous commit, b) the bug I introduced in the previous commit. The solution is to make the code paths the same as much as possible. 1. Targets are now not created from the `default` method. (I would both remove the impl if this was a public library, but just wrap it for convience becaues it's not.) Instead, there is a `from_triple` method which does the defaulting. 2. Besides the sanity checking, use the new method in the code reading config files. Now `no_std` is overriden iff set explicitly just like the other fields which are optional in the TOML AST type. 3. In sanity checking, just populate the map for all targets no matter what. That way do don't duplicate logic trying to be clever and remember which targets have "non standard" overrides. Sanity checking is back to just sanity checking, and out of the game of trying to default too.
1 parent 03ca0e2 commit 4f15867

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/bootstrap/config.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ pub struct Target {
177177
pub no_std: bool,
178178
}
179179

180+
impl Target {
181+
pub fn from_triple(triple: &str) -> Self {
182+
let mut target: Self = Default::default();
183+
if triple.contains("-none-") || triple.contains("nvptx") {
184+
target.no_std = true;
185+
}
186+
target
187+
}
188+
}
180189
/// Structure of the `config.toml` file that configuration is read from.
181190
///
182191
/// This structure uses `Decodable` to automatically decode a TOML configuration
@@ -596,7 +605,7 @@ impl Config {
596605

597606
if let Some(ref t) = toml.target {
598607
for (triple, cfg) in t {
599-
let mut target = Target::default();
608+
let mut target = Target::from_triple(triple);
600609

601610
if let Some(ref s) = cfg.llvm_config {
602611
target.llvm_config = Some(config.src.join(s));
@@ -607,6 +616,9 @@ impl Config {
607616
if let Some(ref s) = cfg.android_ndk {
608617
target.ndk = Some(config.src.join(s));
609618
}
619+
if let Some(s) = cfg.no_std {
620+
target.no_std = s;
621+
}
610622
target.cc = cfg.cc.clone().map(PathBuf::from);
611623
target.cxx = cfg.cxx.clone().map(PathBuf::from);
612624
target.ar = cfg.ar.clone().map(PathBuf::from);
@@ -616,8 +628,6 @@ impl Config {
616628
target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
617629
target.wasi_root = cfg.wasi_root.clone().map(PathBuf::from);
618630
target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
619-
target.no_std =
620-
cfg.no_std.unwrap_or(triple.contains("-none-") || triple.contains("nvptx"));
621631

622632
config.target_config.insert(INTERNER.intern_string(triple.clone()), target);
623633
}

src/bootstrap/sanity.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::process::Command;
1717

1818
use build_helper::{output, t};
1919

20+
use crate::config::Target;
2021
use crate::Build;
2122

2223
struct Finder {
@@ -192,11 +193,9 @@ pub fn check(build: &mut Build) {
192193
panic!("the iOS target is only supported on macOS");
193194
}
194195

195-
if target.contains("-none-") || target.contains("nvptx") {
196-
if build.no_std(*target).is_none() {
197-
build.config.target_config.entry(target.clone()).or_default();
198-
}
196+
build.config.target_config.entry(target.clone()).or_insert(Target::from_triple(target));
199197

198+
if target.contains("-none-") || target.contains("nvptx") {
200199
if build.no_std(*target) == Some(false) {
201200
panic!("All the *-none-* and nvptx* targets are no-std targets")
202201
}

0 commit comments

Comments
 (0)