From 335bdd4eec418f3572ef532e111979681e14602c Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Thu, 4 Jul 2024 17:04:16 +0300 Subject: handle ci-rustc incompatible options during config parse 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 --- src/bootstrap/src/core/config/config.rs | 125 ++++++++++++++++++++++++++++++-- 1 file changed, 118 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 948f97e746f..29bdb3be2ad 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -33,7 +33,7 @@ macro_rules! check_ci_llvm { assert!( $name.is_none(), "setting {} is incompatible with download-ci-llvm.", - stringify!($name) + stringify!($name).replace("_", "-") ); }; } @@ -1547,7 +1547,15 @@ impl Config { let mut lld_enabled = None; let mut is_user_configured_rust_channel = false; + if let Some(rust) = toml.rust { + config.download_rustc_commit = + config.download_ci_rustc_commit(rust.download_rustc.clone()); + + if config.download_rustc_commit.is_some() { + check_incompatible_options_for_ci_rustc(&rust); + } + let Rust { optimize: optimize_toml, debug: debug_toml, @@ -1595,7 +1603,7 @@ impl Config { new_symbol_mangling, profile_generate, profile_use, - download_rustc, + download_rustc: _, lto, validate_mir_opts, frame_pointers, @@ -1605,11 +1613,7 @@ impl Config { } = rust; is_user_configured_rust_channel = channel.is_some(); - set(&mut config.channel, channel); - - config.download_rustc_commit = config.download_ci_rustc_commit(download_rustc); - - // FIXME: handle download-rustc incompatible options. + set(&mut config.channel, channel.clone()); debug = debug_toml; debug_assertions = debug_assertions_toml; @@ -2591,6 +2595,113 @@ impl Config { } } +/// Checks the CI rustc incompatible options by destructuring the `Rust` instance +/// and makes sure that no rust options from config.toml are missed. +fn check_incompatible_options_for_ci_rustc(rust: &Rust) { + macro_rules! err { + ($name:expr) => { + assert!( + $name.is_none(), + "ERROR: Setting `rust.{}` is incompatible with `rust.download-rustc`.", + stringify!($name).replace("_", "-") + ); + }; + } + + macro_rules! warn { + ($name:expr) => { + if $name.is_some() { + println!( + "WARNING: `rust.{}` has no effect with `rust.download-rustc`.", + stringify!($name).replace("_", "-") + ); + } + }; + } + + let Rust { + // Following options are the CI rustc incompatible ones. + optimize, + debug_logging, + debuginfo_level_rustc, + llvm_tools, + llvm_bitcode_linker, + lto, + stack_protector, + strip, + lld_mode, + jemalloc, + rpath, + channel, + description, + incremental, + default_linker, + + // Rest of the options can simply be ignored. + debug: _, + codegen_units: _, + codegen_units_std: _, + debug_assertions: _, + debug_assertions_std: _, + overflow_checks: _, + overflow_checks_std: _, + debuginfo_level: _, + debuginfo_level_std: _, + debuginfo_level_tools: _, + debuginfo_level_tests: _, + split_debuginfo: _, + backtrace: _, + parallel_compiler: _, + musl_root: _, + verbose_tests: _, + optimize_tests: _, + codegen_tests: _, + omit_git_hash: _, + dist_src: _, + save_toolstates: _, + codegen_backends: _, + lld: _, + deny_warnings: _, + backtrace_on_ice: _, + verify_llvm_ir: _, + thin_lto_import_instr_limit: _, + remap_debuginfo: _, + test_compare_mode: _, + llvm_libunwind: _, + control_flow_guard: _, + ehcont_guard: _, + new_symbol_mangling: _, + profile_generate: _, + profile_use: _, + download_rustc: _, + validate_mir_opts: _, + frame_pointers: _, + } = rust; + + // 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` macro for a hard error; + // otherwise, we just print a warning with `warn` macro. + err!(optimize); + err!(debug_logging); + err!(debuginfo_level_rustc); + err!(default_linker); + err!(rpath); + err!(strip); + err!(stack_protector); + err!(lld_mode); + err!(llvm_tools); + err!(llvm_bitcode_linker); + err!(jemalloc); + err!(lto); + + warn!(channel); + warn!(description); + warn!(incremental); +} + fn set(field: &mut T, val: Option) { if let Some(v) = val { *field = v; -- cgit 1.4.1-3-g733a5 From e2c15fe03bcfec07233e8c61dfbb652602c07100 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sun, 14 Jul 2024 00:41:05 +0300 Subject: use std for file mtime and atime modifications Since 1.75 std provides an interface to set access and modified times on files. This change replaces the external dependency previously used for these operations with the corresponding std functions. Signed-off-by: onur-ozkan --- src/bootstrap/Cargo.lock | 1 - src/bootstrap/Cargo.toml | 1 - src/bootstrap/src/core/build_steps/compile.rs | 7 ++++--- src/bootstrap/src/core/download.rs | 8 ++++++-- src/bootstrap/src/lib.rs | 11 +++++++---- 5 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock index c095127da14..de0924c0f42 100644 --- a/src/bootstrap/Cargo.lock +++ b/src/bootstrap/Cargo.lock @@ -48,7 +48,6 @@ dependencies = [ "clap_complete", "cmake", "fd-lock", - "filetime", "home", "ignore", "junction", diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index df7b5b88193..f723407c3ce 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -44,7 +44,6 @@ build_helper = { path = "../tools/build_helper" } clap = { version = "4.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] } clap_complete = "4.4" fd-lock = "4.0" -filetime = "0.2" home = "0.5" ignore = "0.4" libc = "0.2" diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 11a7a404535..df463966d20 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -33,7 +33,6 @@ use crate::utils::helpers::{ }; use crate::LLVM_TOOLS; use crate::{CLang, Compiler, DependencyType, GitRepo, Mode}; -use filetime::FileTime; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Std { @@ -2160,9 +2159,11 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path) return; } - let previous_mtime = FileTime::from_last_modification_time(&path.metadata().unwrap()); + let previous_mtime = t!(t!(path.metadata()).modified()); command("strip").capture().arg("--strip-debug").arg(path).run(builder); + let file = t!(fs::File::open(path)); + // After running `strip`, we have to set the file modification time to what it was before, // otherwise we risk Cargo invalidating its fingerprint and rebuilding the world next time // bootstrap is invoked. @@ -2175,5 +2176,5 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path) // In the second invocation of bootstrap, Cargo will see that the mtime of librustc_driver.so // is greater than the mtime of rustc-main, and will rebuild rustc-main. That will then cause // everything else (standard library, future stages...) to be rebuilt. - t!(filetime::set_file_mtime(path, previous_mtime)); + t!(file.set_modified(previous_mtime)); } diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs index a7f4bb0cf14..d01a910e815 100644 --- a/src/bootstrap/src/core/download.rs +++ b/src/bootstrap/src/core/download.rs @@ -702,9 +702,13 @@ download-rustc = false // time `rustc_llvm` build script ran. However, the timestamps of the // files in the tarball are in the past, so it doesn't trigger a // rebuild. - let now = filetime::FileTime::from_system_time(std::time::SystemTime::now()); + let now = std::time::SystemTime::now(); + let file_times = fs::FileTimes::new().set_accessed(now).set_modified(now); + let llvm_config = llvm_root.join("bin").join(exe("llvm-config", self.build)); - t!(filetime::set_file_times(llvm_config, now, now)); + let llvm_config_file = t!(File::open(llvm_config)); + + t!(llvm_config_file.set_times(file_times)); if self.should_fix_bins_and_dylibs() { let llvm_lib = llvm_root.join("lib"); diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index f16afb29796..4b30b460f26 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -30,7 +30,6 @@ use std::time::SystemTime; use build_helper::ci::{gha, CiEnv}; use build_helper::exit; -use filetime::FileTime; use sha2::digest::Digest; use termcolor::{ColorChoice, StandardStream, WriteColor}; use utils::channel::GitInfo; @@ -1693,9 +1692,13 @@ impl Build { panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e) } t!(fs::set_permissions(dst, metadata.permissions())); - let atime = FileTime::from_last_access_time(&metadata); - let mtime = FileTime::from_last_modification_time(&metadata); - t!(filetime::set_file_times(dst, atime, mtime)); + + let file_times = fs::FileTimes::new() + .set_accessed(t!(metadata.accessed())) + .set_modified(t!(metadata.modified())); + + let dst_file = t!(fs::File::open(dst)); + t!(dst_file.set_times(file_times)); } } -- cgit 1.4.1-3-g733a5