Skip to content

Commit ebc3e15

Browse files
committed
Add parallel-frontend-threads to bootstrap.toml and enable multi-threaded parallel compilation
1 parent 5eda692 commit ebc3e15

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

bootstrap.example.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,13 @@
859859
# Trigger a `DebugBreak` after an internal compiler error during bootstrap on Windows
860860
#rust.break-on-ice = true
861861

862+
# Set the number of threads used during rustc compilation
863+
# The valid options are:
864+
# 1 - Use non-parallel compilation
865+
# N - Number of threads used for rustc compilation
866+
#
867+
#rust.parallel-frontend-threads = 1
868+
862869
# =============================================================================
863870
# Distribution options
864871
#

src/bootstrap/configure.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ def v(*args):
340340
"don't truncate options when printing them in this configure script",
341341
)
342342
v("set", None, "set arbitrary key/value pairs in TOML configuration")
343+
v(
344+
"parallel-frontend-threads",
345+
"rust.parallel-frontend-threads",
346+
"number of parallel threads for rustc compilation",
347+
)
343348

344349

345350
def p(msg):

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,12 @@ impl Builder<'_> {
679679
// cargo would implicitly add it, it was discover that sometimes bootstrap only use
680680
// `rustflags` without `cargo` making it required.
681681
rustflags.arg("-Zunstable-options");
682+
683+
// Add parallel frontend threads configuration
684+
if let Some(threads) = self.config.rust_parallel_frontend_threads {
685+
rustflags.arg(&format!("-Zthreads={}", threads));
686+
}
687+
682688
for (restricted_mode, name, values) in EXTRA_CHECK_CFGS {
683689
if restricted_mode.is_none() || *restricted_mode == Some(mode) {
684690
rustflags.arg(&check_cfg_arg(name, *values));

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ pub struct Config {
191191
pub rust_optimize: RustOptimize,
192192
pub rust_codegen_units: Option<u32>,
193193
pub rust_codegen_units_std: Option<u32>,
194-
195194
pub rustc_debug_assertions: bool,
196195
pub std_debug_assertions: bool,
197196
pub tools_debug_assertions: bool,
@@ -222,6 +221,8 @@ pub struct Config {
222221
pub rust_validate_mir_opts: Option<u32>,
223222
pub rust_std_features: BTreeSet<String>,
224223
pub rust_break_on_ice: bool,
224+
pub rust_parallel_frontend_threads: Option<u32>,
225+
225226
pub llvm_profile_use: Option<String>,
226227
pub llvm_profile_generate: bool,
227228
pub llvm_libunwind_default: Option<LlvmLibunwind>,
@@ -534,6 +535,7 @@ impl Config {
534535
backtrace_on_ice: rust_backtrace_on_ice,
535536
verify_llvm_ir: rust_verify_llvm_ir,
536537
thin_lto_import_instr_limit: rust_thin_lto_import_instr_limit,
538+
parallel_frontend_threads: rust_parallel_frontend_threads,
537539
remap_debuginfo: rust_remap_debuginfo,
538540
jemalloc: rust_jemalloc,
539541
test_compare_mode: rust_test_compare_mode,
@@ -1298,8 +1300,9 @@ impl Config {
12981300
rust_overflow_checks_std: rust_overflow_checks_std
12991301
.or(rust_overflow_checks)
13001302
.unwrap_or(rust_debug == Some(true)),
1303+
rust_parallel_frontend_threads: rust_parallel_frontend_threads.map(threads_from_config),
13011304
rust_profile_generate: flags_rust_profile_generate.or(rust_profile_generate),
1302-
rust_profile_use: flags_rust_profile_use.or(rust_profile_use),
1305+
rust_profile_use: flags_rust_profile_use.or(rust_profile_use),
13031306
rust_randomize_layout: rust_randomize_layout.unwrap_or(false),
13041307
rust_remap_debuginfo: rust_remap_debuginfo.unwrap_or(false),
13051308
rust_rpath: rust_rpath.unwrap_or(true),

src/bootstrap/src/core/config/toml/rust.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ define_config! {
6666
validate_mir_opts: Option<u32> = "validate-mir-opts",
6767
std_features: Option<BTreeSet<String>> = "std-features",
6868
break_on_ice: Option<bool> = "break-on-ice",
69+
parallel_frontend_threads: Option<u32> = "parallel-frontend-threads",
6970
}
7071
}
7172

@@ -357,6 +358,7 @@ pub fn check_incompatible_options_for_ci_rustc(
357358
validate_mir_opts: _,
358359
frame_pointers: _,
359360
break_on_ice: _,
361+
parallel_frontend_threads: _,
360362
} = ci_rust_config;
361363

362364
// There are two kinds of checks for CI rustc incompatible options:

0 commit comments

Comments
 (0)