Skip to content

Commit f4a23e7

Browse files
authored
Auto merge of #2946 - alexcrichton:build-script-metadata, r=brson
Always pass `-C metadata` to the compiler If it's not otherwise available we just key it off the pkgid which should be unique enough across compilations. This should help incremental compilation efforts be "more incremental" across projects. Closes #2943
2 parents f09ef68 + 083ff01 commit f4a23e7

File tree

9 files changed

+35
-13
lines changed

9 files changed

+35
-13
lines changed

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::{Package, PackageId, PackageSet, Target, Resolve};
99
use core::{Profile, Profiles, Workspace};
1010
use core::shell::ColorConfig;
1111
use util::{self, CargoResult, human};
12-
use util::{Config, internal, ChainError, profile, join_paths};
12+
use util::{Config, internal, ChainError, profile, join_paths, short_hash};
1313

1414
use self::job::{Job, Work};
1515
use self::job_queue::JobQueue;
@@ -554,9 +554,14 @@ fn build_base_args(cx: &Context,
554554
}
555555
}
556556

557-
if let Some(m) = cx.target_metadata(unit) {
558-
cmd.arg("-C").arg(&format!("metadata={}", m.metadata));
559-
cmd.arg("-C").arg(&format!("extra-filename={}", m.extra_filename));
557+
match cx.target_metadata(unit) {
558+
Some(m) => {
559+
cmd.arg("-C").arg(&format!("metadata={}", m.metadata));
560+
cmd.arg("-C").arg(&format!("extra-filename={}", m.extra_filename));
561+
}
562+
None => {
563+
cmd.arg("-C").arg(&format!("metadata={}", short_hash(unit.pkg)));
564+
}
560565
}
561566

562567
if rpath {

tests/build-lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
1010
format!("\
1111
[COMPILING] {name} v{version} ({url})
1212
[RUNNING] `rustc src{sep}lib.rs --crate-name {name} --crate-type lib -g \
13+
-C metadata=[..] \
1314
--out-dir [..] \
1415
--emit=dep-info,link \
1516
-L dependency={dir}{sep}target{sep}debug{sep}deps`

tests/build-script.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,15 +766,17 @@ fn build_cmd_with_a_build_cmd() {
766766
[RUNNING] `rustc a[..]build.rs [..] --extern b=[..]`
767767
[RUNNING] `[..]a-[..]build-script-build[..]`
768768
[RUNNING] `rustc [..]lib.rs --crate-name a --crate-type lib -g \
769+
-C metadata=[..] \
769770
--out-dir [..]target[..]deps --emit=dep-info,link \
770771
-L [..]target[..]deps`
771772
[COMPILING] foo v0.5.0 (file://[..])
772773
[RUNNING] `rustc build.rs --crate-name build_script_build --crate-type bin \
773-
-g --out-dir [..] --emit=dep-info,link \
774+
-g -C metadata=[..] --out-dir [..] --emit=dep-info,link \
774775
-L [..]target[..]deps \
775776
--extern a=[..]liba[..].rlib`
776777
[RUNNING] `[..]foo-[..]build-script-build[..]`
777778
[RUNNING] `rustc [..]lib.rs --crate-name foo --crate-type lib -g \
779+
-C metadata=[..] \
778780
--out-dir [..] --emit=dep-info,link \
779781
-L [..]target[..]deps`
780782
[FINISHED] debug [unoptimized + debuginfo] target(s) in [..]

tests/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ fn lto_build() {
10241024
[RUNNING] `rustc src[..]main.rs --crate-name test --crate-type bin \
10251025
-C opt-level=3 \
10261026
-C lto \
1027+
-C metadata=[..] \
10271028
--out-dir {dir}[..]target[..]release \
10281029
--emit=dep-info,link \
10291030
-L dependency={dir}[..]target[..]release[..]deps`
@@ -1050,6 +1051,7 @@ fn verbose_build() {
10501051
execs().with_status(0).with_stderr(&format!("\
10511052
[COMPILING] test v0.0.0 ({url})
10521053
[RUNNING] `rustc src[..]lib.rs --crate-name test --crate-type lib -g \
1054+
-C metadata=[..] \
10531055
--out-dir [..] \
10541056
--emit=dep-info,link \
10551057
-L dependency={dir}[..]target[..]debug[..]deps`
@@ -1077,6 +1079,7 @@ fn verbose_release_build() {
10771079
[COMPILING] test v0.0.0 ({url})
10781080
[RUNNING] `rustc src[..]lib.rs --crate-name test --crate-type lib \
10791081
-C opt-level=3 \
1082+
-C metadata=[..] \
10801083
--out-dir [..] \
10811084
--emit=dep-info,link \
10821085
-L dependency={dir}[..]target[..]release[..]deps`
@@ -1120,12 +1123,14 @@ fn verbose_release_build_deps() {
11201123
[RUNNING] `rustc foo[..]src[..]lib.rs --crate-name foo \
11211124
--crate-type dylib --crate-type rlib -C prefer-dynamic \
11221125
-C opt-level=3 \
1126+
-C metadata=[..] \
11231127
--out-dir [..] \
11241128
--emit=dep-info,link \
11251129
-L dependency={dir}[..]target[..]release[..]deps`
11261130
[COMPILING] test v0.0.0 ({url})
11271131
[RUNNING] `rustc src[..]lib.rs --crate-name test --crate-type lib \
11281132
-C opt-level=3 \
1133+
-C metadata=[..] \
11291134
--out-dir [..] \
11301135
--emit=dep-info,link \
11311136
-L dependency={dir}[..]target[..]release[..]deps \

tests/cargo_alias_config.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ fn alias_config() {
5555
assert_that(p.cargo_process("b-cargo-test").arg("-v"),
5656
execs().with_status(0).
5757
with_stderr_contains("[COMPILING] foo v0.5.0 [..]
58-
[RUNNING] `rustc [..] --crate-name foo --crate-type \
59-
bin -g --out-dir [..] --emit=dep-info,link -L dependency=[..]"));
58+
[RUNNING] `rustc [..] --crate-name foo [..]"));
6059
}
6160

6261
#[test]
@@ -74,9 +73,7 @@ fn alias_list_test() {
7473
assert_that(p.cargo_process("b-cargo-test").arg("-v"),
7574
execs().with_status(0).
7675
with_stderr_contains("[COMPILING] foo v0.5.0 [..]").
77-
with_stderr_contains("[RUNNING] `rustc [..] --crate-name foo \
78-
--crate-type bin -C opt-level=3 --out-dir [..]\
79-
--emit=dep-info,link -L dependency=[..]")
76+
with_stderr_contains("[RUNNING] `rustc [..] --crate-name [..]")
8077
);
8178
}
8279

@@ -95,9 +92,7 @@ fn alias_with_flags_config() {
9592
assert_that(p.cargo_process("b-cargo-test").arg("-v"),
9693
execs().with_status(0).
9794
with_stderr_contains("[COMPILING] foo v0.5.0 [..]").
98-
with_stderr_contains("[RUNNING] `rustc [..] --crate-name foo \
99-
--crate-type bin -C opt-level=3 --out-dir [..]\
100-
--emit=dep-info,link -L dependency=[..]")
95+
with_stderr_contains("[RUNNING] `rustc [..] --crate-name foo [..]")
10196
);
10297
}
10398

tests/cross-compile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ fn linker_and_ar() {
358358
.with_stderr_contains(&format!("\
359359
[COMPILING] foo v0.5.0 ({url})
360360
[RUNNING] `rustc src[..]foo.rs --crate-name foo --crate-type bin -g \
361+
-C metadata=[..] \
361362
--out-dir {dir}[..]target[..]{target}[..]debug \
362363
--emit=dep-info,link \
363364
--target {target} \

tests/profiles.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn profile_overrides() {
3030
[RUNNING] `rustc src{sep}lib.rs --crate-name test --crate-type lib \
3131
-C opt-level=1 \
3232
-C debug-assertions=on \
33+
-C metadata=[..] \
3334
-C rpath \
3435
--out-dir [..] \
3536
--emit=dep-info,link \
@@ -83,13 +84,15 @@ fn top_level_overrides_deps() {
8384
--crate-type dylib --crate-type rlib -C prefer-dynamic \
8485
-C opt-level=1 \
8586
-g \
87+
-C metadata=[..] \
8688
--out-dir {dir}{sep}target{sep}release{sep}deps \
8789
--emit=dep-info,link \
8890
-L dependency={dir}{sep}target{sep}release{sep}deps`
8991
[COMPILING] test v0.0.0 ({url})
9092
[RUNNING] `rustc src{sep}lib.rs --crate-name test --crate-type lib \
9193
-C opt-level=1 \
9294
-g \
95+
-C metadata=[..] \
9396
--out-dir [..] \
9497
--emit=dep-info,link \
9598
-L dependency={dir}{sep}target{sep}release{sep}deps \

tests/run.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,14 @@ fn example_with_release_flag() {
411411
[COMPILING] bar v0.0.1 ({url}/bar)
412412
[RUNNING] `rustc bar{sep}src{sep}bar.rs --crate-name bar --crate-type lib \
413413
-C opt-level=3 \
414+
-C metadata=[..] \
414415
--out-dir {dir}{sep}target{sep}release{sep}deps \
415416
--emit=dep-info,link \
416417
-L dependency={dir}{sep}target{sep}release{sep}deps`
417418
[COMPILING] foo v0.0.1 ({url})
418419
[RUNNING] `rustc examples{sep}a.rs --crate-name a --crate-type bin \
419420
-C opt-level=3 \
421+
-C metadata=[..] \
420422
--out-dir {dir}{sep}target{sep}release{sep}examples \
421423
--emit=dep-info,link \
422424
-L dependency={dir}{sep}target{sep}release{sep}deps \
@@ -437,12 +439,14 @@ fast2"));
437439
[COMPILING] bar v0.0.1 ({url}/bar)
438440
[RUNNING] `rustc bar{sep}src{sep}bar.rs --crate-name bar --crate-type lib \
439441
-g \
442+
-C metadata=[..] \
440443
--out-dir {dir}{sep}target{sep}debug{sep}deps \
441444
--emit=dep-info,link \
442445
-L dependency={dir}{sep}target{sep}debug{sep}deps`
443446
[COMPILING] foo v0.0.1 ({url})
444447
[RUNNING] `rustc examples{sep}a.rs --crate-name a --crate-type bin \
445448
-g \
449+
-C metadata=[..] \
446450
--out-dir {dir}{sep}target{sep}debug{sep}examples \
447451
--emit=dep-info,link \
448452
-L dependency={dir}{sep}target{sep}debug{sep}deps \

tests/rustc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn build_lib_for_foo() {
3030
.with_stderr(format!("\
3131
[COMPILING] foo v0.0.1 ({url})
3232
[RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
33+
-C metadata=[..] \
3334
--out-dir [..] \
3435
--emit=dep-info,link \
3536
-L dependency={dir}{sep}target{sep}debug{sep}deps`
@@ -60,6 +61,7 @@ fn lib() {
6061
[COMPILING] foo v0.0.1 ({url})
6162
[RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
6263
-C debug-assertions=off \
64+
-C metadata=[..] \
6365
--out-dir [..] \
6466
--emit=dep-info,link \
6567
-L dependency={dir}{sep}target{sep}debug{sep}deps`
@@ -89,11 +91,13 @@ fn build_main_and_allow_unstable_options() {
8991
.with_stderr(&format!("\
9092
[COMPILING] {name} v{version} ({url})
9193
[RUNNING] `rustc src{sep}lib.rs --crate-name {name} --crate-type lib -g \
94+
-C metadata=[..] \
9295
--out-dir [..] \
9396
--emit=dep-info,link \
9497
-L dependency={dir}{sep}target{sep}debug{sep}deps`
9598
[RUNNING] `rustc src{sep}main.rs --crate-name {name} --crate-type bin -g \
9699
-C debug-assertions \
100+
-C metadata=[..] \
97101
--out-dir [..] \
98102
--emit=dep-info,link \
99103
-L dependency={dir}{sep}target{sep}debug{sep}deps \
@@ -152,6 +156,7 @@ fn build_with_args_to_one_of_multiple_binaries() {
152156
.with_stderr(format!("\
153157
[COMPILING] foo v0.0.1 ({url})
154158
[RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
159+
-C metadata=[..] \
155160
--out-dir [..]`
156161
[RUNNING] `rustc src{sep}bin{sep}bar.rs --crate-name bar --crate-type bin -g \
157162
-C debug-assertions [..]`
@@ -207,6 +212,7 @@ fn build_with_args_to_one_of_multiple_tests() {
207212
.with_stderr(format!("\
208213
[COMPILING] foo v0.0.1 ({url})
209214
[RUNNING] `rustc src{sep}lib.rs --crate-name foo --crate-type lib -g \
215+
-C metadata=[..] \
210216
--out-dir [..]`
211217
[RUNNING] `rustc tests{sep}bar.rs --crate-name bar -g \
212218
-C debug-assertions [..]--test[..]`

0 commit comments

Comments
 (0)