Skip to content

Commit 217238f

Browse files
committed
refactor(config): Move TOML compatibility checks to respective modules
Moves `check_incompatible_options_for_ci_llvm` to `src/bootstrap/config/toml/llvm.rs` and `check_incompatible_options_for_ci_rustc` to `src/bootstrap/config/toml/rust.rs`. The generic `set` and threads_from_config helper function is moved to `common.rs`.
1 parent 06ef7b7 commit 217238f

File tree

6 files changed

+290
-289
lines changed

6 files changed

+290
-289
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ use crate::core::build_steps::llvm;
2424
use crate::core::build_steps::llvm::LLVM_INVALIDATION_PATHS;
2525
use crate::core::config::flags::Color;
2626
pub use crate::core::config::flags::Subcommand;
27-
use crate::core::config::parsing::check_incompatible_options_for_ci_rustc;
2827
use crate::core::config::toml::change_id::ChangeId;
2928
use crate::core::config::toml::common::{
3029
DebuginfoLevel, LlvmLibunwind, SplitDebuginfo, StringOrBool,
3130
};
32-
use crate::core::config::toml::rust::{LldMode, RustOptimize};
31+
use crate::core::config::toml::rust::{
32+
LldMode, RustOptimize, check_incompatible_options_for_ci_rustc,
33+
};
3334
use crate::core::config::toml::target::Target;
3435
use crate::core::config::types::{DryRun, GccCiMode, RustcLto};
3536
use crate::core::download::is_download_ci_available;

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

Lines changed: 1 addition & 283 deletions
Original file line numberDiff line numberDiff line change
@@ -30,293 +30,11 @@ use crate::core::config::toml::llvm::Llvm;
3030
use crate::core::config::toml::merge::Merge;
3131
use crate::core::config::toml::rust::{LldMode, Rust, RustOptimize};
3232
use crate::core::config::toml::target::Target;
33-
use crate::core::config::{GccCiMode, RustcLto};
33+
use crate::core::config::{GccCiMode, RustcLto, set, threads_from_config};
3434
use crate::utils::channel::GitInfo;
3535
use crate::utils::helpers::{self, exe, t};
3636
use crate::{Config, DryRun, TargetSelection, check_ci_llvm};
3737

38-
/// Compares the current `Llvm` options against those in the CI LLVM builder and detects any incompatible options.
39-
/// It does this by destructuring the `Llvm` instance to make sure every `Llvm` field is covered and not missing.
40-
#[cfg(not(test))]
41-
pub fn check_incompatible_options_for_ci_llvm(
42-
current_config_toml: TomlConfig,
43-
ci_config_toml: TomlConfig,
44-
) -> Result<(), String> {
45-
macro_rules! err {
46-
($current:expr, $expected:expr) => {
47-
if let Some(current) = &$current {
48-
if Some(current) != $expected.as_ref() {
49-
return Err(format!(
50-
"ERROR: Setting `llvm.{}` is incompatible with `llvm.download-ci-llvm`. \
51-
Current value: {:?}, Expected value(s): {}{:?}",
52-
stringify!($expected).replace("_", "-"),
53-
$current,
54-
if $expected.is_some() { "None/" } else { "" },
55-
$expected,
56-
));
57-
};
58-
};
59-
};
60-
}
61-
62-
macro_rules! warn {
63-
($current:expr, $expected:expr) => {
64-
if let Some(current) = &$current {
65-
if Some(current) != $expected.as_ref() {
66-
println!(
67-
"WARNING: `llvm.{}` has no effect with `llvm.download-ci-llvm`. \
68-
Current value: {:?}, Expected value(s): {}{:?}",
69-
stringify!($expected).replace("_", "-"),
70-
$current,
71-
if $expected.is_some() { "None/" } else { "" },
72-
$expected,
73-
);
74-
};
75-
};
76-
};
77-
}
78-
79-
let (Some(current_llvm_config), Some(ci_llvm_config)) =
80-
(current_config_toml.llvm, ci_config_toml.llvm)
81-
else {
82-
return Ok(());
83-
};
84-
85-
let Llvm {
86-
optimize,
87-
thin_lto,
88-
release_debuginfo,
89-
assertions: _,
90-
tests: _,
91-
plugins,
92-
ccache: _,
93-
static_libstdcpp: _,
94-
libzstd,
95-
ninja: _,
96-
targets,
97-
experimental_targets,
98-
link_jobs: _,
99-
link_shared: _,
100-
version_suffix,
101-
clang_cl,
102-
cflags,
103-
cxxflags,
104-
ldflags,
105-
use_libcxx,
106-
use_linker,
107-
allow_old_toolchain,
108-
offload,
109-
polly,
110-
clang,
111-
enable_warnings,
112-
download_ci_llvm: _,
113-
build_config,
114-
enzyme,
115-
} = ci_llvm_config;
116-
117-
err!(current_llvm_config.optimize, optimize);
118-
err!(current_llvm_config.thin_lto, thin_lto);
119-
err!(current_llvm_config.release_debuginfo, release_debuginfo);
120-
err!(current_llvm_config.libzstd, libzstd);
121-
err!(current_llvm_config.targets, targets);
122-
err!(current_llvm_config.experimental_targets, experimental_targets);
123-
err!(current_llvm_config.clang_cl, clang_cl);
124-
err!(current_llvm_config.version_suffix, version_suffix);
125-
err!(current_llvm_config.cflags, cflags);
126-
err!(current_llvm_config.cxxflags, cxxflags);
127-
err!(current_llvm_config.ldflags, ldflags);
128-
err!(current_llvm_config.use_libcxx, use_libcxx);
129-
err!(current_llvm_config.use_linker, use_linker);
130-
err!(current_llvm_config.allow_old_toolchain, allow_old_toolchain);
131-
err!(current_llvm_config.offload, offload);
132-
err!(current_llvm_config.polly, polly);
133-
err!(current_llvm_config.clang, clang);
134-
err!(current_llvm_config.build_config, build_config);
135-
err!(current_llvm_config.plugins, plugins);
136-
err!(current_llvm_config.enzyme, enzyme);
137-
138-
warn!(current_llvm_config.enable_warnings, enable_warnings);
139-
140-
Ok(())
141-
}
142-
143-
/// Compares the current Rust options against those in the CI rustc builder and detects any incompatible options.
144-
/// It does this by destructuring the `Rust` instance to make sure every `Rust` field is covered and not missing.
145-
pub fn check_incompatible_options_for_ci_rustc(
146-
host: TargetSelection,
147-
current_config_toml: TomlConfig,
148-
ci_config_toml: TomlConfig,
149-
) -> Result<(), String> {
150-
macro_rules! err {
151-
($current:expr, $expected:expr, $config_section:expr) => {
152-
if let Some(current) = &$current {
153-
if Some(current) != $expected.as_ref() {
154-
return Err(format!(
155-
"ERROR: Setting `{}` is incompatible with `rust.download-rustc`. \
156-
Current value: {:?}, Expected value(s): {}{:?}",
157-
format!("{}.{}", $config_section, stringify!($expected).replace("_", "-")),
158-
$current,
159-
if $expected.is_some() { "None/" } else { "" },
160-
$expected,
161-
));
162-
};
163-
};
164-
};
165-
}
166-
167-
macro_rules! warn {
168-
($current:expr, $expected:expr, $config_section:expr) => {
169-
if let Some(current) = &$current {
170-
if Some(current) != $expected.as_ref() {
171-
println!(
172-
"WARNING: `{}` has no effect with `rust.download-rustc`. \
173-
Current value: {:?}, Expected value(s): {}{:?}",
174-
format!("{}.{}", $config_section, stringify!($expected).replace("_", "-")),
175-
$current,
176-
if $expected.is_some() { "None/" } else { "" },
177-
$expected,
178-
);
179-
};
180-
};
181-
};
182-
}
183-
184-
let current_profiler = current_config_toml.build.as_ref().and_then(|b| b.profiler);
185-
let profiler = ci_config_toml.build.as_ref().and_then(|b| b.profiler);
186-
err!(current_profiler, profiler, "build");
187-
188-
let current_optimized_compiler_builtins =
189-
current_config_toml.build.as_ref().and_then(|b| b.optimized_compiler_builtins);
190-
let optimized_compiler_builtins =
191-
ci_config_toml.build.as_ref().and_then(|b| b.optimized_compiler_builtins);
192-
err!(current_optimized_compiler_builtins, optimized_compiler_builtins, "build");
193-
194-
// We always build the in-tree compiler on cross targets, so we only care
195-
// about the host target here.
196-
let host_str = host.to_string();
197-
if let Some(current_cfg) = current_config_toml.target.as_ref().and_then(|c| c.get(&host_str)) {
198-
if current_cfg.profiler.is_some() {
199-
let ci_target_toml = ci_config_toml.target.as_ref().and_then(|c| c.get(&host_str));
200-
let ci_cfg = ci_target_toml.ok_or(format!(
201-
"Target specific config for '{host_str}' is not present for CI-rustc"
202-
))?;
203-
204-
let profiler = &ci_cfg.profiler;
205-
err!(current_cfg.profiler, profiler, "build");
206-
207-
let optimized_compiler_builtins = &ci_cfg.optimized_compiler_builtins;
208-
err!(current_cfg.optimized_compiler_builtins, optimized_compiler_builtins, "build");
209-
}
210-
}
211-
212-
let (Some(current_rust_config), Some(ci_rust_config)) =
213-
(current_config_toml.rust, ci_config_toml.rust)
214-
else {
215-
return Ok(());
216-
};
217-
218-
let Rust {
219-
// Following options are the CI rustc incompatible ones.
220-
optimize,
221-
randomize_layout,
222-
debug_logging,
223-
debuginfo_level_rustc,
224-
llvm_tools,
225-
llvm_bitcode_linker,
226-
lto,
227-
stack_protector,
228-
strip,
229-
lld_mode,
230-
jemalloc,
231-
rpath,
232-
channel,
233-
description,
234-
incremental,
235-
default_linker,
236-
std_features,
237-
238-
// Rest of the options can simply be ignored.
239-
debug: _,
240-
codegen_units: _,
241-
codegen_units_std: _,
242-
rustc_debug_assertions: _,
243-
std_debug_assertions: _,
244-
tools_debug_assertions: _,
245-
overflow_checks: _,
246-
overflow_checks_std: _,
247-
debuginfo_level: _,
248-
debuginfo_level_std: _,
249-
debuginfo_level_tools: _,
250-
debuginfo_level_tests: _,
251-
backtrace: _,
252-
musl_root: _,
253-
verbose_tests: _,
254-
optimize_tests: _,
255-
codegen_tests: _,
256-
omit_git_hash: _,
257-
dist_src: _,
258-
save_toolstates: _,
259-
codegen_backends: _,
260-
lld: _,
261-
deny_warnings: _,
262-
backtrace_on_ice: _,
263-
verify_llvm_ir: _,
264-
thin_lto_import_instr_limit: _,
265-
remap_debuginfo: _,
266-
test_compare_mode: _,
267-
llvm_libunwind: _,
268-
control_flow_guard: _,
269-
ehcont_guard: _,
270-
new_symbol_mangling: _,
271-
profile_generate: _,
272-
profile_use: _,
273-
download_rustc: _,
274-
validate_mir_opts: _,
275-
frame_pointers: _,
276-
} = ci_rust_config;
277-
278-
// There are two kinds of checks for CI rustc incompatible options:
279-
// 1. Checking an option that may change the compiler behaviour/output.
280-
// 2. Checking an option that have no effect on the compiler behaviour/output.
281-
//
282-
// If the option belongs to the first category, we call `err` macro for a hard error;
283-
// otherwise, we just print a warning with `warn` macro.
284-
285-
err!(current_rust_config.optimize, optimize, "rust");
286-
err!(current_rust_config.randomize_layout, randomize_layout, "rust");
287-
err!(current_rust_config.debug_logging, debug_logging, "rust");
288-
err!(current_rust_config.debuginfo_level_rustc, debuginfo_level_rustc, "rust");
289-
err!(current_rust_config.rpath, rpath, "rust");
290-
err!(current_rust_config.strip, strip, "rust");
291-
err!(current_rust_config.lld_mode, lld_mode, "rust");
292-
err!(current_rust_config.llvm_tools, llvm_tools, "rust");
293-
err!(current_rust_config.llvm_bitcode_linker, llvm_bitcode_linker, "rust");
294-
err!(current_rust_config.jemalloc, jemalloc, "rust");
295-
err!(current_rust_config.default_linker, default_linker, "rust");
296-
err!(current_rust_config.stack_protector, stack_protector, "rust");
297-
err!(current_rust_config.lto, lto, "rust");
298-
err!(current_rust_config.std_features, std_features, "rust");
299-
300-
warn!(current_rust_config.channel, channel, "rust");
301-
warn!(current_rust_config.description, description, "rust");
302-
warn!(current_rust_config.incremental, incremental, "rust");
303-
304-
Ok(())
305-
}
306-
307-
pub fn set<T>(field: &mut T, val: Option<T>) {
308-
if let Some(v) = val {
309-
*field = v;
310-
}
311-
}
312-
313-
pub fn threads_from_config(v: u32) -> u32 {
314-
match v {
315-
0 => std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32,
316-
n => n,
317-
}
318-
}
319-
32038
impl Config {
32139
#[cfg_attr(
32240
feature = "tracing",

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,16 @@ pub enum ReplaceOpt {
142142
/// Exit with an error on duplicate values
143143
ErrorOnDuplicate,
144144
}
145+
146+
pub fn set<T>(field: &mut T, val: Option<T>) {
147+
if let Some(v) = val {
148+
*field = v;
149+
}
150+
}
151+
152+
pub fn threads_from_config(v: u32) -> u32 {
153+
match v {
154+
0 => std::thread::available_parallelism().map_or(1, std::num::NonZeroUsize::get) as u32,
155+
n => n,
156+
}
157+
}

0 commit comments

Comments
 (0)