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 5, 2024
1 parent 937b5c4 commit 99336cc
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 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,37 @@ 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_logging, "debug-logging");
err_incompatible_ci_rustc_option!(
debuginfo_level_rustc_toml,
"debuginfo-level-rustc"
);
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!(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!(lto, "lto");

warn_incompatible_ci_rustc_option!(channel, "channel");
warn_incompatible_ci_rustc_option!(description, "description");
warn_incompatible_ci_rustc_option!(incremental, "incremental");
}

debug = debug_toml;
debug_assertions = debug_assertions_toml;
Expand Down

0 comments on commit 99336cc

Please sign in to comment.