Skip to content

Commit

Permalink
Set -Ccodegen-units=N for non-path dependencies when CARGO_INCREMENTA…
Browse files Browse the repository at this point in the history
…L is set.
  • Loading branch information
michaelwoerister committed Jun 27, 2017
1 parent 854bc16 commit 3d19b89
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 3d19b89

Please sign in to comment.