From 03ca0e270613592f35ce654e2ef1e68cdfb154e3 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 22 Feb 2020 14:38:38 -0500 Subject: [PATCH 1/2] Allow getting `no_std` from the config file Currently, it is only set correctly in the sanity checking implicit default fallback code. Having a config file at all will for force `no_std = false`. --- src/bootstrap/config.rs | 3 +++ src/bootstrap/sanity.rs | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 214d572329e..b474d896bd2 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -353,6 +353,7 @@ struct TomlTarget { musl_root: Option, wasi_root: Option, qemu_rootfs: Option, + no_std: Option, } impl Config { @@ -615,6 +616,8 @@ pub fn parse(args: &[String]) -> Config { target.musl_root = cfg.musl_root.clone().map(PathBuf::from); target.wasi_root = cfg.wasi_root.clone().map(PathBuf::from); target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from); + target.no_std = + cfg.no_std.unwrap_or(triple.contains("-none-") || triple.contains("nvptx")); config.target_config.insert(INTERNER.intern_string(triple.clone()), target); } diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index 8ff7056e628..76e721ed8e3 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -194,9 +194,7 @@ pub fn check(build: &mut Build) { if target.contains("-none-") || target.contains("nvptx") { if build.no_std(*target).is_none() { - let target = build.config.target_config.entry(target.clone()).or_default(); - - target.no_std = true; + build.config.target_config.entry(target.clone()).or_default(); } if build.no_std(*target) == Some(false) { From 4f15867faf2797257cbeb9e4a38ae8dc87dcf2e9 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 24 Feb 2020 21:59:36 -0500 Subject: [PATCH 2/2] 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. --- src/bootstrap/config.rs | 16 +++++++++++++--- src/bootstrap/sanity.rs | 7 +++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index b474d896bd2..746cddbabd6 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -177,6 +177,15 @@ pub struct Target { pub no_std: bool, } +impl Target { + pub fn from_triple(triple: &str) -> Self { + let mut target: Self = Default::default(); + if triple.contains("-none-") || triple.contains("nvptx") { + target.no_std = true; + } + target + } +} /// Structure of the `config.toml` file that configuration is read from. /// /// This structure uses `Decodable` to automatically decode a TOML configuration @@ -596,7 +605,7 @@ pub fn parse(args: &[String]) -> Config { if let Some(ref t) = toml.target { for (triple, cfg) in t { - let mut target = Target::default(); + let mut target = Target::from_triple(triple); if let Some(ref s) = cfg.llvm_config { target.llvm_config = Some(config.src.join(s)); @@ -607,6 +616,9 @@ pub fn parse(args: &[String]) -> Config { if let Some(ref s) = cfg.android_ndk { target.ndk = Some(config.src.join(s)); } + if let Some(s) = cfg.no_std { + target.no_std = s; + } target.cc = cfg.cc.clone().map(PathBuf::from); target.cxx = cfg.cxx.clone().map(PathBuf::from); target.ar = cfg.ar.clone().map(PathBuf::from); @@ -616,8 +628,6 @@ pub fn parse(args: &[String]) -> Config { target.musl_root = cfg.musl_root.clone().map(PathBuf::from); target.wasi_root = cfg.wasi_root.clone().map(PathBuf::from); target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from); - target.no_std = - cfg.no_std.unwrap_or(triple.contains("-none-") || triple.contains("nvptx")); config.target_config.insert(INTERNER.intern_string(triple.clone()), target); } diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index 76e721ed8e3..530e74da8ca 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -17,6 +17,7 @@ use build_helper::{output, t}; +use crate::config::Target; use crate::Build; struct Finder { @@ -192,11 +193,9 @@ pub fn check(build: &mut Build) { panic!("the iOS target is only supported on macOS"); } - if target.contains("-none-") || target.contains("nvptx") { - if build.no_std(*target).is_none() { - build.config.target_config.entry(target.clone()).or_default(); - } + build.config.target_config.entry(target.clone()).or_insert(Target::from_triple(target)); + if target.contains("-none-") || target.contains("nvptx") { if build.no_std(*target) == Some(false) { panic!("All the *-none-* and nvptx* targets are no-std targets") }