Skip to content

Commit feed02f

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

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ 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-
343+
v("parallel-frontend-threads", "rust.parallel-frontend-threads", "number of parallel threads for rustc compilation")
344344

345345
def p(msg):
346346
print("configure: " + 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: 4 additions & 1 deletion
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,
@@ -1314,6 +1316,7 @@ impl Config {
13141316
rustc_default_linker: rust_default_linker,
13151317
rustc_error_format: flags_rustc_error_format,
13161318
rustfmt_info,
1319+
rust_parallel_frontend_threads: rust_parallel_frontend_threads.map(threads_from_config),
13171320
sanitizers: build_sanitizers.unwrap_or(false),
13181321
save_toolstates: rust_save_toolstates.map(PathBuf::from),
13191322
skip,

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)