Skip to content

Commit 11739ba

Browse files
committed
moved target config parsing logic to toml/target.rs
1 parent 992b498 commit 11739ba

File tree

2 files changed

+84
-71
lines changed

2 files changed

+84
-71
lines changed

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

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -891,76 +891,7 @@ impl Config {
891891

892892
config.apply_gcc_config(toml.gcc);
893893

894-
if let Some(ref s) = cfg.llvm_config {
895-
if config.download_rustc_commit.is_some() && triple == *config.build.triple {
896-
panic!(
897-
"setting llvm_config for the host is incompatible with download-rustc"
898-
);
899-
}
900-
target.llvm_config = Some(config.src.join(s));
901-
}
902-
if let Some(patches) = cfg.llvm_has_rust_patches {
903-
assert!(
904-
config.submodules == Some(false) || cfg.llvm_config.is_some(),
905-
"use of `llvm-has-rust-patches` is restricted to cases where either submodules are disabled or llvm-config been provided"
906-
);
907-
target.llvm_has_rust_patches = Some(patches);
908-
}
909-
if let Some(ref s) = cfg.llvm_filecheck {
910-
target.llvm_filecheck = Some(config.src.join(s));
911-
}
912-
target.llvm_libunwind = cfg.llvm_libunwind.as_ref().map(|v| {
913-
v.parse().unwrap_or_else(|_| {
914-
panic!("failed to parse target.{triple}.llvm-libunwind")
915-
})
916-
});
917-
if let Some(s) = cfg.no_std {
918-
target.no_std = s;
919-
}
920-
target.cc = cfg.cc.map(PathBuf::from);
921-
target.cxx = cfg.cxx.map(PathBuf::from);
922-
target.ar = cfg.ar.map(PathBuf::from);
923-
target.ranlib = cfg.ranlib.map(PathBuf::from);
924-
target.linker = cfg.linker.map(PathBuf::from);
925-
target.crt_static = cfg.crt_static;
926-
target.musl_root = cfg.musl_root.map(PathBuf::from);
927-
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
928-
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
929-
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
930-
target.runner = cfg.runner;
931-
target.sanitizers = cfg.sanitizers;
932-
target.profiler = cfg.profiler;
933-
target.rpath = cfg.rpath;
934-
target.optimized_compiler_builtins = cfg.optimized_compiler_builtins;
935-
target.jemalloc = cfg.jemalloc;
936-
937-
if let Some(ref backends) = cfg.codegen_backends {
938-
let available_backends = ["llvm", "cranelift", "gcc"];
939-
940-
target.codegen_backends = Some(backends.iter().map(|s| {
941-
if let Some(backend) = s.strip_prefix(CODEGEN_BACKEND_PREFIX) {
942-
if available_backends.contains(&backend) {
943-
panic!("Invalid value '{s}' for 'target.{triple}.codegen-backends'. Instead, please use '{backend}'.");
944-
} else {
945-
println!("HELP: '{s}' for 'target.{triple}.codegen-backends' might fail. \
946-
Codegen backends are mostly defined without the '{CODEGEN_BACKEND_PREFIX}' prefix. \
947-
In this case, it would be referred to as '{backend}'.");
948-
}
949-
}
950-
951-
s.clone()
952-
}).collect());
953-
}
954-
955-
target.split_debuginfo = cfg.split_debuginfo.as_ref().map(|v| {
956-
v.parse().unwrap_or_else(|_| {
957-
panic!("invalid value for target.{triple}.split-debuginfo")
958-
})
959-
});
960-
961-
config.target_config.insert(TargetSelection::from_user(&triple), target);
962-
}
963-
}
894+
config.apply_target_config(toml.target);
964895

965896
match ccache {
966897
Some(StringOrBool::String(ref s)) => config.ccache = Some(s.to_string()),

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

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
use std::collections::HashMap;
2+
13
use serde::{Deserialize, Deserializer};
24

5+
use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
36
use crate::core::config::toml::common::{LlvmLibunwind, SplitDebuginfo, StringOrBool};
47
use crate::core::config::toml::{Merge, ReplaceOpt};
5-
use crate::{HashSet, PathBuf, define_config, exit};
8+
use crate::{Config, HashSet, PathBuf, TargetSelection, define_config, exit};
69

710
define_config! {
811
/// TOML representation of how each build target is configured.
@@ -77,3 +80,82 @@ impl Target {
7780
target
7881
}
7982
}
83+
84+
impl Config {
85+
pub fn apply_target_config(&mut self, toml_target: Option<HashMap<String, TomlTarget>>) {
86+
if let Some(t) = toml_target {
87+
for (triple, cfg) in t {
88+
let mut target = Target::from_triple(&triple);
89+
90+
if let Some(ref s) = cfg.llvm_config {
91+
if self.download_rustc_commit.is_some() && triple == *self.build.triple {
92+
panic!(
93+
"setting llvm_config for the host is incompatible with download-rustc"
94+
);
95+
}
96+
target.llvm_config = Some(self.src.join(s));
97+
}
98+
if let Some(patches) = cfg.llvm_has_rust_patches {
99+
assert!(
100+
self.submodules == Some(false) || cfg.llvm_config.is_some(),
101+
"use of `llvm-has-rust-patches` is restricted to cases where either submodules are disabled or llvm-config been provided"
102+
);
103+
target.llvm_has_rust_patches = Some(patches);
104+
}
105+
if let Some(ref s) = cfg.llvm_filecheck {
106+
target.llvm_filecheck = Some(self.src.join(s));
107+
}
108+
target.llvm_libunwind = cfg.llvm_libunwind.as_ref().map(|v| {
109+
v.parse().unwrap_or_else(|_| {
110+
panic!("failed to parse target.{triple}.llvm-libunwind")
111+
})
112+
});
113+
if let Some(s) = cfg.no_std {
114+
target.no_std = s;
115+
}
116+
target.cc = cfg.cc.map(PathBuf::from);
117+
target.cxx = cfg.cxx.map(PathBuf::from);
118+
target.ar = cfg.ar.map(PathBuf::from);
119+
target.ranlib = cfg.ranlib.map(PathBuf::from);
120+
target.linker = cfg.linker.map(PathBuf::from);
121+
target.crt_static = cfg.crt_static;
122+
target.musl_root = cfg.musl_root.map(PathBuf::from);
123+
target.musl_libdir = cfg.musl_libdir.map(PathBuf::from);
124+
target.wasi_root = cfg.wasi_root.map(PathBuf::from);
125+
target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from);
126+
target.runner = cfg.runner;
127+
target.sanitizers = cfg.sanitizers;
128+
target.profiler = cfg.profiler;
129+
target.rpath = cfg.rpath;
130+
target.optimized_compiler_builtins = cfg.optimized_compiler_builtins;
131+
target.jemalloc = cfg.jemalloc;
132+
133+
if let Some(ref backends) = cfg.codegen_backends {
134+
let available_backends = ["llvm", "cranelift", "gcc"];
135+
136+
target.codegen_backends = Some(backends.iter().map(|s| {
137+
if let Some(backend) = s.strip_prefix(CODEGEN_BACKEND_PREFIX) {
138+
if available_backends.contains(&backend) {
139+
panic!("Invalid value '{s}' for 'target.{triple}.codegen-backends'. Instead, please use '{backend}'.");
140+
} else {
141+
println!("HELP: '{s}' for 'target.{triple}.codegen-backends' might fail. \
142+
Codegen backends are mostly defined without the '{CODEGEN_BACKEND_PREFIX}' prefix. \
143+
In this case, it would be referred to as '{backend}'.");
144+
}
145+
}
146+
147+
s.clone()
148+
}).collect());
149+
}
150+
151+
target.split_debuginfo = cfg.split_debuginfo.as_ref().map(|v| {
152+
v.parse().unwrap_or_else(|_| {
153+
panic!("invalid value for target.{triple}.split-debuginfo")
154+
})
155+
});
156+
157+
self.target_config.insert(TargetSelection::from_user(&triple), target);
158+
}
159+
}
160+
}
161+
}

0 commit comments

Comments
 (0)