Skip to content

Commit

Permalink
handle ci-rustc incompatible options during config parse
Browse files Browse the repository at this point in the history
This change ensures that `config.toml` does not use CI rustc incompatible
options when CI rustc is enabled. This is necessary because some options
can change compiler's behavior in certain scenarios.

The list may not be complete, but should be a good first step as it's better than nothing!

Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Jul 4, 2024
1 parent 937b5c4 commit e8412f7
Showing 1 changed file with 65 additions and 2 deletions.
67 changes: 65 additions & 2 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ macro_rules! check_ci_llvm {
};
}

macro_rules! err_incompatible_ci_rustc_option {
($name:expr, $option_name:literal) => {
assert!(
$name.is_none(),
"ERROR: Setting `rust.{}` is incompatible with `rust.download-rustc`.",
$option_name
);
};
}

macro_rules! warn_incompatible_ci_rustc_option {
($name:expr, $option_name:literal) => {
if $name.is_some() {
println!("WARNING: `rust.{}` has no effect with `rust.download-rustc`.", $option_name);
}
};
}

#[derive(Clone, Default)]
pub enum DryRun {
/// This isn't a dry run.
Expand Down Expand Up @@ -1605,11 +1623,56 @@ impl Config {
} = rust;

is_user_configured_rust_channel = channel.is_some();
set(&mut config.channel, channel);
set(&mut config.channel, channel.clone());

config.download_rustc_commit = config.download_ci_rustc_commit(download_rustc);

// FIXME: handle download-rustc incompatible options.
// There are two kinds of checks for CI rustc incompatible options:
// 1. Checking an option that may change the compiler behaviour/output.
// 2. Checking an option that have no effect on the compiler behaviour/output.
//
// If the option belongs to the first category, we call `err_incompatible_ci_rustc_option` macro
// for a hard error; otherwise, we just print a warning with `warn_incompatible_ci_rustc_option` macro.
if config.download_rustc_commit.is_some() {
err_incompatible_ci_rustc_option!(optimize_toml, "optimize");
err_incompatible_ci_rustc_option!(debug_toml, "debug");
err_incompatible_ci_rustc_option!(codegen_units, "codegen-units");
err_incompatible_ci_rustc_option!(codegen_units_std, "codegen-units-std");
err_incompatible_ci_rustc_option!(debug_assertions_toml, "debug-assertions");
err_incompatible_ci_rustc_option!(
debug_assertions_std_toml,
"debug-assertions-std"
);
err_incompatible_ci_rustc_option!(debug_logging, "debug-logging");
err_incompatible_ci_rustc_option!(overflow_checks_toml, "overflow-checks");
err_incompatible_ci_rustc_option!(overflow_checks_std_toml, "overflow-checks-std");
err_incompatible_ci_rustc_option!(debuginfo_level_toml, "debuginfo-level");
err_incompatible_ci_rustc_option!(
debuginfo_level_rustc_toml,
"debuginfo-level-rustc"
);
err_incompatible_ci_rustc_option!(debuginfo_level_std_toml, "debuginfo-level-std");
err_incompatible_ci_rustc_option!(split_debuginfo, "split-debuginfo");
err_incompatible_ci_rustc_option!(backtrace, "backtrace");
err_incompatible_ci_rustc_option!(default_linker, "default-linker");
err_incompatible_ci_rustc_option!(rpath, "rpath");
err_incompatible_ci_rustc_option!(strip, "strip");
err_incompatible_ci_rustc_option!(frame_pointers, "frame-pointers");
err_incompatible_ci_rustc_option!(stack_protector, "stack-protector");
err_incompatible_ci_rustc_option!(lld_mode, "use-lld");
err_incompatible_ci_rustc_option!(llvm_tools, "llvm-tools");
err_incompatible_ci_rustc_option!(llvm_bitcode_linker, "llvm-bitcode-linker");
err_incompatible_ci_rustc_option!(jemalloc, "jemalloc");
err_incompatible_ci_rustc_option!(control_flow_guard, "control-flow-guard");
err_incompatible_ci_rustc_option!(ehcont_guard, "ehcont-guard");
err_incompatible_ci_rustc_option!(lto, "lto");
err_incompatible_ci_rustc_option!(validate_mir_opts, "validate-mir-opts");

warn_incompatible_ci_rustc_option!(channel, "channel");
warn_incompatible_ci_rustc_option!(description, "description");
warn_incompatible_ci_rustc_option!(incremental, "incremental");
warn_incompatible_ci_rustc_option!(parallel_compiler, "parallel-compiler");
}

debug = debug_toml;
debug_assertions = debug_assertions_toml;
Expand Down

0 comments on commit e8412f7

Please sign in to comment.