diff options
| author | bors <bors@rust-lang.org> | 2023-12-09 23:02:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-09 23:02:05 +0000 |
| commit | 8cd8d313690260e6cacc280b93710d62d4ffefb0 (patch) | |
| tree | f05f1c5255082abb1feac54e4c652aed45c9f066 /src/bootstrap | |
| parent | 06e02d5b259c1e88cbf0c74366d9e0a4c7cfd6d9 (diff) | |
| parent | 6860654d82963fa2f4d0f1ef6adaf7a1d82f80df (diff) | |
Auto merge of #118069 - onur-ozkan:bypass_bootstrap_lock, r=Mark-Simulacrum
allow bypassing the build directory lock As bootstrap locks its entire build directory, parallel bootstrapping for anything becomes impossible. This change enables developers to bypass the locking mechanism (with `--bypass-bootstrap-lock` flag) when it is unnecessary for their specific use case. more context: https://rust-lang.zulipchat.com/#narrow/stream/326414-t-infra.2Fbootstrap/topic/Build.20.28miri.3F.29.20sysroots.20in.20parallel cc `@saethlin`
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/src/bin/main.rs | 61 | ||||
| -rw-r--r-- | src/bootstrap/src/core/config/config.rs | 3 | ||||
| -rw-r--r-- | src/bootstrap/src/core/config/flags.rs | 7 |
3 files changed, 43 insertions, 28 deletions
diff --git a/src/bootstrap/src/bin/main.rs b/src/bootstrap/src/bin/main.rs index 952ef40ed42..b3c427721ea 100644 --- a/src/bootstrap/src/bin/main.rs +++ b/src/bootstrap/src/bin/main.rs @@ -26,35 +26,40 @@ fn main() { let mut build_lock; #[cfg(all(any(unix, windows), not(target_os = "solaris")))] let _build_lock_guard; - #[cfg(all(any(unix, windows), not(target_os = "solaris")))] - // Display PID of process holding the lock - // PID will be stored in a lock file - { - let path = config.out.join("lock"); - let pid = match fs::read_to_string(&path) { - Ok(contents) => contents, - Err(_) => String::new(), - }; - - build_lock = - fd_lock::RwLock::new(t!(fs::OpenOptions::new().write(true).create(true).open(&path))); - _build_lock_guard = match build_lock.try_write() { - Ok(mut lock) => { - t!(lock.write(&process::id().to_string().as_ref())); - lock - } - err => { - drop(err); - println!("WARNING: build directory locked by process {pid}, waiting for lock"); - let mut lock = t!(build_lock.write()); - t!(lock.write(&process::id().to_string().as_ref())); - lock - } - }; - } - #[cfg(any(not(any(unix, windows)), target_os = "solaris"))] - println!("WARNING: file locking not supported for target, not locking build directory"); + if !config.bypass_bootstrap_lock { + // Display PID of process holding the lock + // PID will be stored in a lock file + #[cfg(all(any(unix, windows), not(target_os = "solaris")))] + { + let path = config.out.join("lock"); + let pid = match fs::read_to_string(&path) { + Ok(contents) => contents, + Err(_) => String::new(), + }; + + build_lock = fd_lock::RwLock::new(t!(fs::OpenOptions::new() + .write(true) + .create(true) + .open(&path))); + _build_lock_guard = match build_lock.try_write() { + Ok(mut lock) => { + t!(lock.write(&process::id().to_string().as_ref())); + lock + } + err => { + drop(err); + println!("WARNING: build directory locked by process {pid}, waiting for lock"); + let mut lock = t!(build_lock.write()); + t!(lock.write(&process::id().to_string().as_ref())); + lock + } + }; + } + + #[cfg(any(not(any(unix, windows)), target_os = "solaris"))] + println!("WARNING: file locking not supported for target, not locking build directory"); + } // check_version warnings are not printed during setup let changelog_suggestion = diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 22e8ce8365b..3d4a248e21a 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -117,6 +117,7 @@ impl Display for DebuginfoLevel { pub struct Config { pub changelog_seen: Option<usize>, // FIXME: Deprecated field. Remove it at 2024. pub change_id: Option<usize>, + pub bypass_bootstrap_lock: bool, pub ccache: Option<String>, /// Call Build::ninja() instead of this. pub ninja_in_file: bool, @@ -1059,6 +1060,7 @@ define_config! { impl Config { pub fn default_opts() -> Config { let mut config = Config::default(); + config.bypass_bootstrap_lock = false; config.llvm_optimize = true; config.ninja_in_file = true; config.llvm_static_stdcpp = false; @@ -1137,6 +1139,7 @@ impl Config { config.llvm_profile_use = flags.llvm_profile_use; config.llvm_profile_generate = flags.llvm_profile_generate; config.enable_bolt_settings = flags.enable_bolt_settings; + config.bypass_bootstrap_lock = flags.bypass_bootstrap_lock; // Infer the rest of the configuration. diff --git a/src/bootstrap/src/core/config/flags.rs b/src/bootstrap/src/core/config/flags.rs index 2a301007ab4..27d0425df54 100644 --- a/src/bootstrap/src/core/config/flags.rs +++ b/src/bootstrap/src/core/config/flags.rs @@ -133,6 +133,13 @@ pub struct Flags { /// whether to use color in cargo and rustc output pub color: Color, + #[arg(global(true), long)] + /// Bootstrap uses this value to decide whether it should bypass locking the build process. + /// This is rarely needed (e.g., compiling the std library for different targets in parallel). + /// + /// Unless you know exactly what you are doing, you probably don't need this. + pub bypass_bootstrap_lock: bool, + /// whether rebuilding llvm should be skipped, overriding `skip-rebuld` in config.toml #[arg(global(true), long, value_name = "VALUE")] pub llvm_skip_rebuild: Option<bool>, |
