Skip to content

Commit 60e10e6

Browse files
authored
Rollup merge of #127322 - onur-ozkan:ci-rustc-incompatible-options, r=Mark-Simulacrum
handle ci-rustc incompatible options during config parse This PR ensures that `config.toml` does not use CI rustc incompatible options when CI rustc is enabled (just like [ci-llvm checks](https://github.com/rust-lang/rust/blob/e2cf31a6148725bde4ea48acf1e4fe72675257a2/src/bootstrap/src/core/config/config.rs#L1809-L1836)). Some options can change compiler's behavior in certain scenarios. If we don't check these incompatible options, CI runners using CI rustc might ignore options we have explicitly set. This could be dangerous as we might think a rustc test passed with option T but in fact it wasn't tested with option T. Later in #122709, I will disable CI rustc if any of those options were used (similar to [this approach](https://github.com/rust-lang/rust/blob/dd2c24aafddbd9cc170f32f5b447c7d3005c7412/src/ci/run.sh#L165-L169)). If CI runners fail because of these checks, it means the logic in run.sh isn't covering the incompatible options correctly (since any incompatible option should turn off CI rustc). The list may not be complete, but should be a good first step as it's better than nothing! Blocker for #122709
2 parents 459120d + 335bdd4 commit 60e10e6

File tree

2 files changed

+119
-8
lines changed

2 files changed

+119
-8
lines changed

config.example.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@
609609

610610
# Forces frame pointers to be used with `-Cforce-frame-pointers`.
611611
# This can be helpful for profiling at a small performance cost.
612-
# frame-pointers = false
612+
#frame-pointers = false
613613

614614
# Indicates whether stack protectors should be used
615615
# via the unstable option `-Zstack-protector`.

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

+118-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ macro_rules! check_ci_llvm {
3333
assert!(
3434
$name.is_none(),
3535
"setting {} is incompatible with download-ci-llvm.",
36-
stringify!($name)
36+
stringify!($name).replace("_", "-")
3737
);
3838
};
3939
}
@@ -1568,7 +1568,15 @@ impl Config {
15681568
let mut lld_enabled = None;
15691569

15701570
let mut is_user_configured_rust_channel = false;
1571+
15711572
if let Some(rust) = toml.rust {
1573+
config.download_rustc_commit =
1574+
config.download_ci_rustc_commit(rust.download_rustc.clone());
1575+
1576+
if config.download_rustc_commit.is_some() {
1577+
check_incompatible_options_for_ci_rustc(&rust);
1578+
}
1579+
15721580
let Rust {
15731581
optimize: optimize_toml,
15741582
debug: debug_toml,
@@ -1616,7 +1624,7 @@ impl Config {
16161624
new_symbol_mangling,
16171625
profile_generate,
16181626
profile_use,
1619-
download_rustc,
1627+
download_rustc: _,
16201628
lto,
16211629
validate_mir_opts,
16221630
frame_pointers,
@@ -1626,11 +1634,7 @@ impl Config {
16261634
} = rust;
16271635

16281636
is_user_configured_rust_channel = channel.is_some();
1629-
set(&mut config.channel, channel);
1630-
1631-
config.download_rustc_commit = config.download_ci_rustc_commit(download_rustc);
1632-
1633-
// FIXME: handle download-rustc incompatible options.
1637+
set(&mut config.channel, channel.clone());
16341638

16351639
debug = debug_toml;
16361640
debug_assertions = debug_assertions_toml;
@@ -2608,6 +2612,113 @@ impl Config {
26082612
}
26092613
}
26102614

2615+
/// Checks the CI rustc incompatible options by destructuring the `Rust` instance
2616+
/// and makes sure that no rust options from config.toml are missed.
2617+
fn check_incompatible_options_for_ci_rustc(rust: &Rust) {
2618+
macro_rules! err {
2619+
($name:expr) => {
2620+
assert!(
2621+
$name.is_none(),
2622+
"ERROR: Setting `rust.{}` is incompatible with `rust.download-rustc`.",
2623+
stringify!($name).replace("_", "-")
2624+
);
2625+
};
2626+
}
2627+
2628+
macro_rules! warn {
2629+
($name:expr) => {
2630+
if $name.is_some() {
2631+
println!(
2632+
"WARNING: `rust.{}` has no effect with `rust.download-rustc`.",
2633+
stringify!($name).replace("_", "-")
2634+
);
2635+
}
2636+
};
2637+
}
2638+
2639+
let Rust {
2640+
// Following options are the CI rustc incompatible ones.
2641+
optimize,
2642+
debug_logging,
2643+
debuginfo_level_rustc,
2644+
llvm_tools,
2645+
llvm_bitcode_linker,
2646+
lto,
2647+
stack_protector,
2648+
strip,
2649+
lld_mode,
2650+
jemalloc,
2651+
rpath,
2652+
channel,
2653+
description,
2654+
incremental,
2655+
default_linker,
2656+
2657+
// Rest of the options can simply be ignored.
2658+
debug: _,
2659+
codegen_units: _,
2660+
codegen_units_std: _,
2661+
debug_assertions: _,
2662+
debug_assertions_std: _,
2663+
overflow_checks: _,
2664+
overflow_checks_std: _,
2665+
debuginfo_level: _,
2666+
debuginfo_level_std: _,
2667+
debuginfo_level_tools: _,
2668+
debuginfo_level_tests: _,
2669+
split_debuginfo: _,
2670+
backtrace: _,
2671+
parallel_compiler: _,
2672+
musl_root: _,
2673+
verbose_tests: _,
2674+
optimize_tests: _,
2675+
codegen_tests: _,
2676+
omit_git_hash: _,
2677+
dist_src: _,
2678+
save_toolstates: _,
2679+
codegen_backends: _,
2680+
lld: _,
2681+
deny_warnings: _,
2682+
backtrace_on_ice: _,
2683+
verify_llvm_ir: _,
2684+
thin_lto_import_instr_limit: _,
2685+
remap_debuginfo: _,
2686+
test_compare_mode: _,
2687+
llvm_libunwind: _,
2688+
control_flow_guard: _,
2689+
ehcont_guard: _,
2690+
new_symbol_mangling: _,
2691+
profile_generate: _,
2692+
profile_use: _,
2693+
download_rustc: _,
2694+
validate_mir_opts: _,
2695+
frame_pointers: _,
2696+
} = rust;
2697+
2698+
// There are two kinds of checks for CI rustc incompatible options:
2699+
// 1. Checking an option that may change the compiler behaviour/output.
2700+
// 2. Checking an option that have no effect on the compiler behaviour/output.
2701+
//
2702+
// If the option belongs to the first category, we call `err` macro for a hard error;
2703+
// otherwise, we just print a warning with `warn` macro.
2704+
err!(optimize);
2705+
err!(debug_logging);
2706+
err!(debuginfo_level_rustc);
2707+
err!(default_linker);
2708+
err!(rpath);
2709+
err!(strip);
2710+
err!(stack_protector);
2711+
err!(lld_mode);
2712+
err!(llvm_tools);
2713+
err!(llvm_bitcode_linker);
2714+
err!(jemalloc);
2715+
err!(lto);
2716+
2717+
warn!(channel);
2718+
warn!(description);
2719+
warn!(incremental);
2720+
}
2721+
26112722
fn set<T>(field: &mut T, val: Option<T>) {
26122723
if let Some(v) = val {
26132724
*field = v;

0 commit comments

Comments
 (0)