Skip to content

Commit 924912c

Browse files
committed
move target parsing to parse_inner
1 parent 3f9bf57 commit 924912c

File tree

2 files changed

+64
-71
lines changed

2 files changed

+64
-71
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::core::config::toml::build::{Build, Tool};
3939
use crate::core::config::toml::change_id::ChangeId;
4040
use crate::core::config::toml::dist::Dist;
4141
use crate::core::config::toml::rust::{
42-
LldMode, RustOptimize, check_incompatible_options_for_ci_rustc,
42+
LldMode, RustOptimize, check_incompatible_options_for_ci_rustc, validate_codegen_backends,
4343
};
4444
use crate::core::config::toml::target::Target;
4545
use crate::core::config::{
@@ -956,7 +956,68 @@ impl Config {
956956
config.rust_profile_use = flags_rust_profile_use;
957957
config.rust_profile_generate = flags_rust_profile_generate;
958958

959-
config.apply_target_config(toml.target);
959+
if let Some(t) = toml.target {
960+
for (triple, cfg) in t {
961+
let mut target = Target::from_triple(&triple);
962+
963+
if let Some(ref s) = cfg.llvm_config {
964+
if config.download_rustc_commit.is_some()
965+
&& triple == *config.host_target.triple
966+
{
967+
panic!(
968+
"setting llvm_config for the host is incompatible with download-rustc"
969+
);
970+
}
971+
target.llvm_config = Some(config.src.join(s));
972+
}
973+
if let Some(patches) = cfg.llvm_has_rust_patches {
974+
assert!(
975+
config.submodules == Some(false) || cfg.llvm_config.is_some(),
976+
"use of `llvm-has-rust-patches` is restricted to cases where either submodules are disabled or llvm-config been provided"
977+
);
978+
target.llvm_has_rust_patches = Some(patches);
979+
}
980+
if let Some(ref s) = cfg.llvm_filecheck {
981+
target.llvm_filecheck = Some(config.src.join(s));
982+
}
983+
target.llvm_libunwind = cfg.llvm_libunwind.as_ref().map(|v| {
984+
v.parse().unwrap_or_else(|_| {
985+
panic!("failed to parse target.{triple}.llvm-libunwind")
986+
})
987+
});
988+
if let Some(s) = cfg.no_std {
989+
target.no_std = s;
990+
}
991+
target.cc = cfg.cc.map(PathBuf::from);
992+
target.cxx = cfg.cxx.map(PathBuf::from);
993+
target.ar = cfg.ar.map(PathBuf::from);
994+
target.ranlib = cfg.ranlib.map(PathBuf::from);
995+
target.linker = cfg.linker.map(PathBuf::from);
996+
target.crt_static = cfg.crt_static;
997+
target.musl_root = cfg.musl_root.map(PathBuf::from);
998+
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
999+
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
1000+
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
1001+
target.runner = cfg.runner;
1002+
target.sanitizers = cfg.sanitizers;
1003+
target.profiler = cfg.profiler;
1004+
target.rpath = cfg.rpath;
1005+
target.optimized_compiler_builtins = cfg.optimized_compiler_builtins;
1006+
target.jemalloc = cfg.jemalloc;
1007+
if let Some(backends) = cfg.codegen_backends {
1008+
target.codegen_backends =
1009+
Some(validate_codegen_backends(backends, &format!("target.{triple}")))
1010+
}
1011+
1012+
target.split_debuginfo = cfg.split_debuginfo.as_ref().map(|v| {
1013+
v.parse().unwrap_or_else(|_| {
1014+
panic!("invalid value for target.{triple}.split-debuginfo")
1015+
})
1016+
});
1017+
1018+
config.target_config.insert(TargetSelection::from_user(&triple), target);
1019+
}
1020+
}
9601021
config.apply_rust_config(toml.rust, flags_warnings);
9611022

9621023
config.reproducible_artifacts = flags_reproducible_artifact;

src/bootstrap/src/core/config/toml/target.rs

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@
1212
//! applies it to the global [`Config`], ensuring proper path resolution, validation,
1313
//! and integration with other build settings.
1414
15-
use std::collections::HashMap;
16-
1715
use serde::{Deserialize, Deserializer};
1816

19-
use crate::core::config::toml::rust::parse_codegen_backends;
2017
use crate::core::config::{LlvmLibunwind, Merge, ReplaceOpt, SplitDebuginfo, StringOrBool};
21-
use crate::{CodegenBackendKind, Config, HashSet, PathBuf, TargetSelection, define_config, exit};
18+
use crate::{HashSet, PathBuf, define_config, exit};
2219

2320
define_config! {
2421
/// TOML representation of how each build target is configured.
@@ -93,68 +90,3 @@ impl Target {
9390
target
9491
}
9592
}
96-
97-
impl Config {
98-
pub fn apply_target_config(&mut self, toml_target: Option<HashMap<String, TomlTarget>>) {
99-
if let Some(t) = toml_target {
100-
for (triple, cfg) in t {
101-
let mut target = Target::from_triple(&triple);
102-
103-
if let Some(ref s) = cfg.llvm_config {
104-
if self.download_rustc_commit.is_some() && triple == *self.host_target.triple {
105-
panic!(
106-
"setting llvm_config for the host is incompatible with download-rustc"
107-
);
108-
}
109-
target.llvm_config = Some(self.src.join(s));
110-
}
111-
if let Some(patches) = cfg.llvm_has_rust_patches {
112-
assert!(
113-
self.submodules == Some(false) || cfg.llvm_config.is_some(),
114-
"use of `llvm-has-rust-patches` is restricted to cases where either submodules are disabled or llvm-config been provided"
115-
);
116-
target.llvm_has_rust_patches = Some(patches);
117-
}
118-
if let Some(ref s) = cfg.llvm_filecheck {
119-
target.llvm_filecheck = Some(self.src.join(s));
120-
}
121-
target.llvm_libunwind = cfg.llvm_libunwind.as_ref().map(|v| {
122-
v.parse().unwrap_or_else(|_| {
123-
panic!("failed to parse target.{triple}.llvm-libunwind")
124-
})
125-
});
126-
if let Some(s) = cfg.no_std {
127-
target.no_std = s;
128-
}
129-
target.cc = cfg.cc.map(PathBuf::from);
130-
target.cxx = cfg.cxx.map(PathBuf::from);
131-
target.ar = cfg.ar.map(PathBuf::from);
132-
target.ranlib = cfg.ranlib.map(PathBuf::from);
133-
target.linker = cfg.linker.map(PathBuf::from);
134-
target.crt_static = cfg.crt_static;
135-
target.musl_root = cfg.musl_root.map(PathBuf::from);
136-
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
137-
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
138-
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
139-
target.runner = cfg.runner;
140-
target.sanitizers = cfg.sanitizers;
141-
target.profiler = cfg.profiler;
142-
target.rpath = cfg.rpath;
143-
target.optimized_compiler_builtins = cfg.optimized_compiler_builtins;
144-
target.jemalloc = cfg.jemalloc;
145-
if let Some(backends) = cfg.codegen_backends {
146-
target.codegen_backends =
147-
Some(parse_codegen_backends(backends, &format!("target.{triple}")))
148-
}
149-
150-
target.split_debuginfo = cfg.split_debuginfo.as_ref().map(|v| {
151-
v.parse().unwrap_or_else(|_| {
152-
panic!("invalid value for target.{triple}.split-debuginfo")
153-
})
154-
});
155-
156-
self.target_config.insert(TargetSelection::from_user(&triple), target);
157-
}
158-
}
159-
}
160-
}

0 commit comments

Comments
 (0)