Skip to content

Commit

Permalink
Auto merge of #4234 - michaelwoerister:smarter-cargo-incremental-2, r…
Browse files Browse the repository at this point in the history
…=alexcrichton

Set -Ccodegen-units=N for non-path dependencies when CARGO_INCREMENTAL is set.

This PR tweaks compilation for non-path dependencies when CARGO_INCREMENTAL is set. Before, `cargo` would compile such dependencies "just" non-incrementally while, with this PR, it will also set the number of CGUs to the number of CPU cores. Otherwise compiling those dependencies might take significantly longer (because of more expensive optimizations and less multi-threading) than compiling them incrementally -- which is what we wanted to avoid in the first place.
  • Loading branch information
bors committed Jun 29, 2017
2 parents 64c3217 + 3d19b89 commit 5e023a6
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/cargo/ops/cargo_rustc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,15 +942,26 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
}

pub fn incremental_args(&self, unit: &Unit) -> CargoResult<Vec<String>> {
// Only enable incremental compilation for sources the user can modify.
// For things that change infrequently, non-incremental builds yield
// better performance.
// (see also https://github.com/rust-lang/cargo/issues/3972)
if self.incremental_enabled && unit.pkg.package_id().source_id().is_path() {
Ok(vec![format!("-Zincremental={}", self.layout(unit.kind).incremental().display())])
} else {
Ok(vec![])
if self.incremental_enabled {
if unit.pkg.package_id().source_id().is_path() {
// Only enable incremental compilation for sources the user can modify.
// For things that change infrequently, non-incremental builds yield
// better performance.
// (see also https://github.com/rust-lang/cargo/issues/3972)
return Ok(vec![format!("-Zincremental={}",
self.layout(unit.kind).incremental().display())]);
} else {
if unit.profile.codegen_units.is_none() {
// For non-incremental builds we set a higher number of
// codegen units so we get faster compiles. It's OK to do
// so because the user has already opted into slower
// runtime code by setting CARGO_INCREMENTAL.
return Ok(vec![format!("-Ccodegen-units={}", ::num_cpus::get())]);
}
}
}

Ok(vec![])
}

pub fn rustflags_args(&self, unit: &Unit) -> CargoResult<Vec<String>> {
Expand Down

0 comments on commit 5e023a6

Please sign in to comment.