From: Eric Huss Date: Sun, 22 Apr 2018 20:57:38 +0000 (-0700) Subject: Avoid building libs and bins twice in `cargo build --all-targets --release`. X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~1^2~41^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=195520b853049d2b3f52ddcaf449d8c4aa092531;p=cargo.git Avoid building libs and bins twice in `cargo build --all-targets --release`. This changes it so that `Build` mode is not set in the Unit, since there is no difference between Bench and Test once the profile has been selected. --- diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index e0c4e0b1e..624659784 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -112,7 +112,10 @@ pub enum CompileMode { /// `test` is true, then it is also compiled with `--test` to check it like /// a test. Check { test: bool }, - /// A target being built for a benchmark. + /// Used to indicate benchmarks should be built. This is not used in + /// `Target` because it is essentially the same as `Test` (indicating + /// `--test` should be passed to rustc) and by using `Test` instead it + /// allows some de-duping of Units to occur. Bench, /// A target that will be documented with `rustdoc`. /// If `deps` is true, then it will also document all dependencies. @@ -629,6 +632,17 @@ fn generate_targets<'a>( target_mode, release, ); + // Once the profile has been selected for benchmarks, we don't need to + // distinguish between benches and tests. Switching the mode allows + // de-duplication of units that are essentially identical. For + // example, `cargo build --all-targets --release` creates the units + // (lib profile:bench, mode:test) and (lib profile:bench, mode:bench) + // and since these are the same, we want them to be de-duped in + // `unit_dependencies`. + let target_mode = match target_mode { + CompileMode::Bench => CompileMode::Test, + _ => target_mode, + }; Unit { pkg, target, diff --git a/tests/testsuite/profile_targets.rs b/tests/testsuite/profile_targets.rs index 91450742e..7a245fe8a 100644 --- a/tests/testsuite/profile_targets.rs +++ b/tests/testsuite/profile_targets.rs @@ -178,11 +178,11 @@ fn profile_selection_build_all_targets() { // lib dev+panic build (a normal lib target) // lib dev-panic build (used by tests/benches) // lib test test - // lib bench bench + // lib bench test(bench) // test test test - // bench bench bench + // bench bench test(bench) // bin test test - // bin bench bench + // bin bench test(bench) // bin dev build // example dev build assert_that(p.cargo("build --all-targets -vv"), @@ -253,12 +253,10 @@ fn profile_selection_build_all_targets_release() { // ------ ------- ---- // lib release+panic build (a normal lib target) // lib release-panic build (used by tests/benches) - // lib bench test - // lib bench bench + // lib bench test (bench/test de-duped) // test bench test - // bench bench bench - // bin bench test - // bin bench bench + // bench bench test + // bin bench test (bench/test de-duped) // bin release build // example release build assert_that(p.cargo("build --all-targets --release -vv"), @@ -275,8 +273,6 @@ foo custom build PROFILE=release DEBUG=false OPT_LEVEL=3 [RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C panic=abort -C codegen-units=2 [..]` [RUNNING] `rustc --crate-name foo src[/]lib.rs --emit=dep-info,link -C opt-level=3 -C codegen-units=4 --test [..]` [RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C codegen-units=2 [..]` -[RUNNING] `rustc --crate-name foo src[/]lib.rs --emit=dep-info,link -C opt-level=3 -C codegen-units=4 --test [..]` -[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link -C opt-level=3 -C codegen-units=4 --test [..]` [RUNNING] `rustc --crate-name test1 tests[/]test1.rs --emit=dep-info,link -C opt-level=3 -C codegen-units=4 --test [..]` [RUNNING] `rustc --crate-name bench1 benches[/]bench1.rs --emit=dep-info,link -C opt-level=3 -C codegen-units=4 --test [..]` [RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link -C opt-level=3 -C codegen-units=4 --test [..]` @@ -449,9 +445,9 @@ fn profile_selection_bench() { // Target Profile Mode // ------ ------- ---- // lib release-panic build - // lib bench bench - // bench bench bench - // bin bench bench + // lib bench test(bench) + // bench bench test(bench) + // bin bench test(bench) // bin release-panic build // assert_that(p.cargo("bench -vv"), execs().with_status(0).with_stderr_unordered("\