Skip to content

Commit 8cd8d31

Browse files
committed
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`
2 parents 06e02d5 + 6860654 commit 8cd8d31

7 files changed

Lines changed: 128 additions & 68 deletions

File tree

‎src/bootstrap/src/bin/main.rs‎

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,40 @@ fn main() {
2626
letmut build_lock;
2727
#[cfg(all(any(unix, windows), not(target_os = "solaris")))]
2828
let _build_lock_guard;
29-
#[cfg(all(any(unix, windows), not(target_os = "solaris")))]
30-
// Display PID of process holding the lock
31-
// PID will be stored in a lock file
32-
{
33-
let path = config.out.join("lock");
34-
let pid = match fs::read_to_string(&path){
35-
Ok(contents) => contents,
36-
Err(_) => String::new(),
37-
};
38-
39-
build_lock =
40-
fd_lock::RwLock::new(t!(fs::OpenOptions::new().write(true).create(true).open(&path)));
41-
_build_lock_guard = match build_lock.try_write(){
42-
Ok(mut lock) => {
43-
t!(lock.write(&process::id().to_string().as_ref()));
44-
lock
45-
}
46-
err => {
47-
drop(err);
48-
println!("WARNING: build directory locked by process {pid}, waiting for lock");
49-
letmut lock = t!(build_lock.write());
50-
t!(lock.write(&process::id().to_string().as_ref()));
51-
lock
52-
}
53-
};
54-
}
5529

56-
#[cfg(any(not(any(unix, windows)), target_os = "solaris"))]
57-
println!("WARNING: file locking not supported for target, not locking build directory");
30+
if !config.bypass_bootstrap_lock{
31+
// Display PID of process holding the lock
32+
// PID will be stored in a lock file
33+
#[cfg(all(any(unix, windows), not(target_os = "solaris")))]
34+
{
35+
let path = config.out.join("lock");
36+
let pid = match fs::read_to_string(&path){
37+
Ok(contents) => contents,
38+
Err(_) => String::new(),
39+
};
40+
41+
build_lock = fd_lock::RwLock::new(t!(fs::OpenOptions::new()
42+
.write(true)
43+
.create(true)
44+
.open(&path)));
45+
_build_lock_guard = match build_lock.try_write(){
46+
Ok(mut lock) => {
47+
t!(lock.write(&process::id().to_string().as_ref()));
48+
lock
49+
}
50+
err => {
51+
drop(err);
52+
println!("WARNING: build directory locked by process {pid}, waiting for lock");
53+
letmut lock = t!(build_lock.write());
54+
t!(lock.write(&process::id().to_string().as_ref()));
55+
lock
56+
}
57+
};
58+
}
59+
60+
#[cfg(any(not(any(unix, windows)), target_os = "solaris"))]
61+
println!("WARNING: file locking not supported for target, not locking build directory");
62+
}
5863

5964
// check_version warnings are not printed during setup
6065
let changelog_suggestion =

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ impl Display for DebuginfoLevel {
117117
pubstructConfig{
118118
pubchangelog_seen:Option<usize>,// FIXME: Deprecated field. Remove it at 2024.
119119
pubchange_id:Option<usize>,
120+
pubbypass_bootstrap_lock:bool,
120121
pubccache:Option<String>,
121122
/// Call Build::ninja() instead of this.
122123
pubninja_in_file:bool,
@@ -1059,6 +1060,7 @@ define_config! {
10591060
implConfig{
10601061
pubfndefault_opts() -> Config{
10611062
letmut config = Config::default();
1063+
config.bypass_bootstrap_lock = false;
10621064
config.llvm_optimize = true;
10631065
config.ninja_in_file = true;
10641066
config.llvm_static_stdcpp = false;
@@ -1137,6 +1139,7 @@ impl Config {
11371139
config.llvm_profile_use = flags.llvm_profile_use;
11381140
config.llvm_profile_generate = flags.llvm_profile_generate;
11391141
config.enable_bolt_settings = flags.enable_bolt_settings;
1142+
config.bypass_bootstrap_lock = flags.bypass_bootstrap_lock;
11401143

11411144
// Infer the rest of the configuration.
11421145

‎src/bootstrap/src/core/config/flags.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ pub struct Flags {
133133
/// whether to use color in cargo and rustc output
134134
pubcolor:Color,
135135

136+
#[arg(global(true), long)]
137+
/// Bootstrap uses this value to decide whether it should bypass locking the build process.
138+
/// This is rarely needed (e.g., compiling the std library for different targets in parallel).
139+
///
140+
/// Unless you know exactly what you are doing, you probably don't need this.
141+
pubbypass_bootstrap_lock:bool,
142+
136143
/// whether rebuilding llvm should be skipped, overriding `skip-rebuld` in config.toml
137144
#[arg(global(true), long, value_name = "VALUE")]
138145
publlvm_skip_rebuild:Option<bool>,

0 commit comments

Comments
 (0)