Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8cd8d31

Browse files
committedDec 9, 2023
Auto merge of rust-lang#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

File tree

7 files changed

+128
-68
lines changed

7 files changed

+128
-68
lines changed
 

‎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
let mut 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-
let mut 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+
let mut 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
pub struct Config {
118118
pub changelog_seen: Option<usize>, // FIXME: Deprecated field. Remove it at 2024.
119119
pub change_id: Option<usize>,
120+
pub bypass_bootstrap_lock: bool,
120121
pub ccache: Option<String>,
121122
/// Call Build::ninja() instead of this.
122123
pub ninja_in_file: bool,
@@ -1059,6 +1060,7 @@ define_config! {
10591060
impl Config {
10601061
pub fn default_opts() -> Config {
10611062
let mut 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
pub color: 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+
pub bypass_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
pub llvm_skip_rebuild: Option<bool>,

‎src/etc/completions/x.py.fish

Lines changed: 20 additions & 5 deletions
Large diffs are not rendered by default.

‎src/etc/completions/x.py.ps1

Lines changed: 25 additions & 10 deletions
Large diffs are not rendered by default.

‎src/etc/completions/x.py.sh

Lines changed: 15 additions & 15 deletions
Large diffs are not rendered by default.

‎src/etc/completions/x.py.zsh

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ _x.py() {
4646
'--include-default-paths[include default paths in addition to the provided ones]' \
4747
'--dry-run[dry run; don'\''t build anything]' \
4848
'--json-output[use message-format=json]' \
49+
'--bypass-bootstrap-lock[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)]' \
4950
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
5051
'--enable-bolt-settings[Enable BOLT link flags]' \
5152
'--skip-stage0-validation[Skip stage0 compiler validation]' \
52-
'-h[Print help]' \
53-
'--help[Print help]' \
53+
'-h[Print help (see more with '\''--help'\'')]' \
54+
'--help[Print help (see more with '\''--help'\'')]' \
5455
'::paths -- paths for the subcommand:_files' \
5556
'::free_args -- arguments passed to subcommands:' \
5657
":: :_x.py_commands" \
@@ -95,6 +96,7 @@ _arguments "${_arguments_options[@]}" \
9596
'--include-default-paths[include default paths in addition to the provided ones]' \
9697
'--dry-run[dry run; don'\''t build anything]' \
9798
'--json-output[use message-format=json]' \
99+
'--bypass-bootstrap-lock[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)]' \
98100
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
99101
'--enable-bolt-settings[Enable BOLT link flags]' \
100102
'--skip-stage0-validation[Skip stage0 compiler validation]' \
@@ -137,6 +139,7 @@ _arguments "${_arguments_options[@]}" \
137139
'--include-default-paths[include default paths in addition to the provided ones]' \
138140
'--dry-run[dry run; don'\''t build anything]' \
139141
'--json-output[use message-format=json]' \
142+
'--bypass-bootstrap-lock[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)]' \
140143
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
141144
'--enable-bolt-settings[Enable BOLT link flags]' \
142145
'--skip-stage0-validation[Skip stage0 compiler validation]' \
@@ -183,6 +186,7 @@ _arguments "${_arguments_options[@]}" \
183186
'--include-default-paths[include default paths in addition to the provided ones]' \
184187
'--dry-run[dry run; don'\''t build anything]' \
185188
'--json-output[use message-format=json]' \
189+
'--bypass-bootstrap-lock[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)]' \
186190
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
187191
'--enable-bolt-settings[Enable BOLT link flags]' \
188192
'--skip-stage0-validation[Skip stage0 compiler validation]' \
@@ -224,6 +228,7 @@ _arguments "${_arguments_options[@]}" \
224228
'--include-default-paths[include default paths in addition to the provided ones]' \
225229
'--dry-run[dry run; don'\''t build anything]' \
226230
'--json-output[use message-format=json]' \
231+
'--bypass-bootstrap-lock[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)]' \
227232
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
228233
'--enable-bolt-settings[Enable BOLT link flags]' \
229234
'--skip-stage0-validation[Skip stage0 compiler validation]' \
@@ -266,6 +271,7 @@ _arguments "${_arguments_options[@]}" \
266271
'--include-default-paths[include default paths in addition to the provided ones]' \
267272
'--dry-run[dry run; don'\''t build anything]' \
268273
'--json-output[use message-format=json]' \
274+
'--bypass-bootstrap-lock[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)]' \
269275
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
270276
'--enable-bolt-settings[Enable BOLT link flags]' \
271277
'--skip-stage0-validation[Skip stage0 compiler validation]' \
@@ -309,6 +315,7 @@ _arguments "${_arguments_options[@]}" \
309315
'--include-default-paths[include default paths in addition to the provided ones]' \
310316
'--dry-run[dry run; don'\''t build anything]' \
311317
'--json-output[use message-format=json]' \
318+
'--bypass-bootstrap-lock[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)]' \
312319
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
313320
'--enable-bolt-settings[Enable BOLT link flags]' \
314321
'--skip-stage0-validation[Skip stage0 compiler validation]' \
@@ -363,6 +370,7 @@ _arguments "${_arguments_options[@]}" \
363370
'--include-default-paths[include default paths in addition to the provided ones]' \
364371
'--dry-run[dry run; don'\''t build anything]' \
365372
'--json-output[use message-format=json]' \
373+
'--bypass-bootstrap-lock[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)]' \
366374
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
367375
'--enable-bolt-settings[Enable BOLT link flags]' \
368376
'--skip-stage0-validation[Skip stage0 compiler validation]' \
@@ -405,11 +413,12 @@ _arguments "${_arguments_options[@]}" \
405413
'--include-default-paths[include default paths in addition to the provided ones]' \
406414
'--dry-run[dry run; don'\''t build anything]' \
407415
'--json-output[use message-format=json]' \
416+
'--bypass-bootstrap-lock[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)]' \
408417
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
409418
'--enable-bolt-settings[Enable BOLT link flags]' \
410419
'--skip-stage0-validation[Skip stage0 compiler validation]' \
411-
'-h[Print help]' \
412-
'--help[Print help]' \
420+
'-h[Print help (see more with '\''--help'\'')]' \
421+
'--help[Print help (see more with '\''--help'\'')]' \
413422
'*::paths -- paths for the subcommand:_files' \
414423
&& ret=0
415424
;;
@@ -447,11 +456,12 @@ _arguments "${_arguments_options[@]}" \
447456
'--include-default-paths[include default paths in addition to the provided ones]' \
448457
'--dry-run[dry run; don'\''t build anything]' \
449458
'--json-output[use message-format=json]' \
459+
'--bypass-bootstrap-lock[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)]' \
450460
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
451461
'--enable-bolt-settings[Enable BOLT link flags]' \
452462
'--skip-stage0-validation[Skip stage0 compiler validation]' \
453-
'-h[Print help]' \
454-
'--help[Print help]' \
463+
'-h[Print help (see more with '\''--help'\'')]' \
464+
'--help[Print help (see more with '\''--help'\'')]' \
455465
'*::paths -- paths for the subcommand:_files' \
456466
&& ret=0
457467
;;
@@ -488,11 +498,12 @@ _arguments "${_arguments_options[@]}" \
488498
'--include-default-paths[include default paths in addition to the provided ones]' \
489499
'--dry-run[dry run; don'\''t build anything]' \
490500
'--json-output[use message-format=json]' \
501+
'--bypass-bootstrap-lock[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)]' \
491502
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
492503
'--enable-bolt-settings[Enable BOLT link flags]' \
493504
'--skip-stage0-validation[Skip stage0 compiler validation]' \
494-
'-h[Print help]' \
495-
'--help[Print help]' \
505+
'-h[Print help (see more with '\''--help'\'')]' \
506+
'--help[Print help (see more with '\''--help'\'')]' \
496507
'*::paths -- paths for the subcommand:_files' \
497508
&& ret=0
498509
;;
@@ -529,11 +540,12 @@ _arguments "${_arguments_options[@]}" \
529540
'--include-default-paths[include default paths in addition to the provided ones]' \
530541
'--dry-run[dry run; don'\''t build anything]' \
531542
'--json-output[use message-format=json]' \
543+
'--bypass-bootstrap-lock[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)]' \
532544
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
533545
'--enable-bolt-settings[Enable BOLT link flags]' \
534546
'--skip-stage0-validation[Skip stage0 compiler validation]' \
535-
'-h[Print help]' \
536-
'--help[Print help]' \
547+
'-h[Print help (see more with '\''--help'\'')]' \
548+
'--help[Print help (see more with '\''--help'\'')]' \
537549
'*::paths -- paths for the subcommand:_files' \
538550
&& ret=0
539551
;;
@@ -571,6 +583,7 @@ _arguments "${_arguments_options[@]}" \
571583
'--include-default-paths[include default paths in addition to the provided ones]' \
572584
'--dry-run[dry run; don'\''t build anything]' \
573585
'--json-output[use message-format=json]' \
586+
'--bypass-bootstrap-lock[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)]' \
574587
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
575588
'--enable-bolt-settings[Enable BOLT link flags]' \
576589
'--skip-stage0-validation[Skip stage0 compiler validation]' \
@@ -612,6 +625,7 @@ _arguments "${_arguments_options[@]}" \
612625
'--include-default-paths[include default paths in addition to the provided ones]' \
613626
'--dry-run[dry run; don'\''t build anything]' \
614627
'--json-output[use message-format=json]' \
628+
'--bypass-bootstrap-lock[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)]' \
615629
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
616630
'--enable-bolt-settings[Enable BOLT link flags]' \
617631
'--skip-stage0-validation[Skip stage0 compiler validation]' \
@@ -655,6 +669,7 @@ _arguments "${_arguments_options[@]}" \
655669
'--include-default-paths[include default paths in addition to the provided ones]' \
656670
'--dry-run[dry run; don'\''t build anything]' \
657671
'--json-output[use message-format=json]' \
672+
'--bypass-bootstrap-lock[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)]' \
658673
'--llvm-profile-generate[generate PGO profile with llvm built for rustc]' \
659674
'--enable-bolt-settings[Enable BOLT link flags]' \
660675
'--skip-stage0-validation[Skip stage0 compiler validation]' \

0 commit comments

Comments
 (0)
This repository has been archived.