Skip to content

Commit

Permalink
ci: Use multiple codegen units on non-dist bots
Browse files Browse the repository at this point in the history
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 8 codegen units here is pretty arbitrary, it's basically just a
number which hopefully means that the cores are always nice and warm. Also a
previous version of this commit bounced on Windows CI due to libstd being
compiled with multiple codegen units, so only the compiler is now compiled with
multiple codegen units.
  • Loading branch information
alexcrichton committed Sep 21, 2017
1 parent 1b55d19 commit 27c26da
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
4 changes: 3 additions & 1 deletion config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@

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

# Whether or not debug assertions are enabled for the compiler and standard
# library. Also enables compilation of debug! and trace! logging macros.
Expand Down
9 changes: 7 additions & 2 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,12 @@ impl<'a> Builder<'a> {
stage = compiler.stage;
}

let cgus = if mode == Mode::Libstd {
self.config.rust_codegen_units
} else {
self.config.rustc_codegen_units.unwrap_or(self.config.rust_codegen_units)
};

// Customize the compiler we're running. Specify the compiler to cargo
// as our shim and then pass it some various options used to configure
// how the actual compiler itself is called.
Expand All @@ -468,8 +474,7 @@ impl<'a> Builder<'a> {
.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
.env("RUSTC_REAL", self.rustc(compiler))
.env("RUSTC_STAGE", stage.to_string())
.env("RUSTC_CODEGEN_UNITS",
self.config.rust_codegen_units.to_string())
.env("RUSTC_CODEGEN_UNITS", cgus.to_string())
.env("RUSTC_DEBUG_ASSERTIONS",
self.config.rust_debug_assertions.to_string())
.env("RUSTC_SYSROOT", self.sysroot(compiler))
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub struct Config {
// rust codegen options
pub rust_optimize: bool,
pub rust_codegen_units: u32,
pub rustc_codegen_units: Option<u32>,
pub rust_debug_assertions: bool,
pub rust_debuginfo: bool,
pub rust_debuginfo_lines: bool,
Expand Down Expand Up @@ -254,6 +255,7 @@ impl Default for StringOrBool {
struct Rust {
optimize: Option<bool>,
codegen_units: Option<u32>,
rustc_codegen_units: Option<u32>,
debug_assertions: Option<bool>,
debuginfo: Option<bool>,
debuginfo_lines: Option<bool>,
Expand Down Expand Up @@ -472,6 +474,10 @@ impl Config {
Some(n) => config.rust_codegen_units = n,
None => {}
}
match rust.rustc_codegen_units {
Some(0) => config.rustc_codegen_units = Some(num_cpus::get() as u32),
other => config.rustc_codegen_units = other,
}
}

if let Some(ref t) = toml.target {
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def set(key, value):
value = True
elif keyval[1] == "false":
value = False
elif keyval[1].isdigit():
value = int(keyval[1])
else:
value = keyval[1]
set(keyval[0], value)
Expand Down Expand Up @@ -357,6 +359,8 @@ def to_toml(value):
return '[' + ', '.join(map(to_toml, value)) + ']'
elif isinstance(value, str):
return "'" + value + "'"
elif isinstance(value, int):
return str(value)
else:
raise 'no toml'

Expand Down
4 changes: 4 additions & 0 deletions src/ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"
fi
else
# Let's try to take advantage of some of those sweet sweet parallelism wins by
# using multiple codegen units during the bootstrap
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.rustc-codegen-units=8"

# We almost always want debug assertions enabled, but sometimes this takes too
# long for too little benefit, so we just turn them off.
if [ "$NO_DEBUG_ASSERTIONS" = "" ]; then
Expand Down

0 comments on commit 27c26da

Please sign in to comment.