Skip to content

Commit 2075597

Browse files
committed
Auto merge of #44675 - alexcrichton:many-cgu, r=aidanhs
ci: Use multiple codegen units on non-dist bots This commit is yet another attempt to bring down our cycle times by parallelizing some of the long-and-serial parts of the build, for example optimizing the libsyntax, librustc, and librustc_driver crate. The hope is that any perf loss from codegen units is more than made up for with the perf gain from using multiple codegen units. The value of 16 codegen units here is pretty arbitrary, it's basically just a number which hopefully means that the cores are always nice and warm.
2 parents ee409a4 + 27c26da commit 2075597

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

config.toml.example

+3-1
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,10 @@
223223

224224
# Number of codegen units to use for each compiler invocation. A value of 0
225225
# means "the number of cores on this machine", and 1+ is passed through to the
226-
# compiler.
226+
# compiler. The `codegen-units` setting applies to std/rustc/tools whereas
227+
# `rustc-codegen-units` does not apply to std
227228
#codegen-units = 1
229+
#rustc-codegen-units = 1
228230

229231
# Whether or not debug assertions are enabled for the compiler and standard
230232
# library. Also enables compilation of debug! and trace! logging macros.

src/bootstrap/builder.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,12 @@ impl<'a> Builder<'a> {
458458
stage = compiler.stage;
459459
}
460460

461+
let cgus = if mode == Mode::Libstd {
462+
self.config.rust_codegen_units
463+
} else {
464+
self.config.rustc_codegen_units.unwrap_or(self.config.rust_codegen_units)
465+
};
466+
461467
// Customize the compiler we're running. Specify the compiler to cargo
462468
// as our shim and then pass it some various options used to configure
463469
// how the actual compiler itself is called.
@@ -468,8 +474,7 @@ impl<'a> Builder<'a> {
468474
.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
469475
.env("RUSTC_REAL", self.rustc(compiler))
470476
.env("RUSTC_STAGE", stage.to_string())
471-
.env("RUSTC_CODEGEN_UNITS",
472-
self.config.rust_codegen_units.to_string())
477+
.env("RUSTC_CODEGEN_UNITS", cgus.to_string())
473478
.env("RUSTC_DEBUG_ASSERTIONS",
474479
self.config.rust_debug_assertions.to_string())
475480
.env("RUSTC_SYSROOT", self.sysroot(compiler))

src/bootstrap/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub struct Config {
8282
// rust codegen options
8383
pub rust_optimize: bool,
8484
pub rust_codegen_units: u32,
85+
pub rustc_codegen_units: Option<u32>,
8586
pub rust_debug_assertions: bool,
8687
pub rust_debuginfo: bool,
8788
pub rust_debuginfo_lines: bool,
@@ -254,6 +255,7 @@ impl Default for StringOrBool {
254255
struct Rust {
255256
optimize: Option<bool>,
256257
codegen_units: Option<u32>,
258+
rustc_codegen_units: Option<u32>,
257259
debug_assertions: Option<bool>,
258260
debuginfo: Option<bool>,
259261
debuginfo_lines: Option<bool>,
@@ -472,6 +474,10 @@ impl Config {
472474
Some(n) => config.rust_codegen_units = n,
473475
None => {}
474476
}
477+
match rust.rustc_codegen_units {
478+
Some(0) => config.rustc_codegen_units = Some(num_cpus::get() as u32),
479+
other => config.rustc_codegen_units = other,
480+
}
475481
}
476482

477483
if let Some(ref t) = toml.target {

src/bootstrap/configure.py

+4
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ def set(key, value):
256256
value = True
257257
elif keyval[1] == "false":
258258
value = False
259+
elif keyval[1].isdigit():
260+
value = int(keyval[1])
259261
else:
260262
value = keyval[1]
261263
set(keyval[0], value)
@@ -357,6 +359,8 @@ def to_toml(value):
357359
return '[' + ', '.join(map(to_toml, value)) + ']'
358360
elif isinstance(value, str):
359361
return "'" + value + "'"
362+
elif isinstance(value, int):
363+
return str(value)
360364
else:
361365
raise 'no toml'
362366

src/ci/run.sh

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then
5252
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"
5353
fi
5454
else
55+
# Let's try to take advantage of some of those sweet sweet parallelism wins by
56+
# using multiple codegen units during the bootstrap
57+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.rustc-codegen-units=8"
58+
5559
# We almost always want debug assertions enabled, but sometimes this takes too
5660
# long for too little benefit, so we just turn them off.
5761
if [ "$NO_DEBUG_ASSERTIONS" = "" ]; then

0 commit comments

Comments
 (0)