Skip to content

Commit c444126

Browse files
committed
Start using precise -L flags
Now that the compiler supports the notion for a "dependency lookup path" Cargo can specify this information to the compiler in order to prevent transitive dependencies from being imported. Closes #1037
1 parent ba28004 commit c444126

File tree

5 files changed

+72
-26
lines changed

5 files changed

+72
-26
lines changed

src/cargo/ops/cargo_rustc/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package
727727
cx: &Context,
728728
kind: Kind) -> CargoResult<CommandPrototype> {
729729
let layout = cx.layout(package, kind);
730-
cmd = cmd.arg("-L").arg(layout.root());
731-
cmd = cmd.arg("-L").arg(layout.deps());
730+
cmd = cmd.arg("-L").arg(format!("dependency={}", layout.root().display()));
731+
cmd = cmd.arg("-L").arg(format!("dependency={}", layout.deps().display()));
732732

733733
cmd = cmd.env("OUT_DIR", if package.has_custom_build() {
734734
Some(layout.build_out(package))
@@ -746,7 +746,7 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package
746746
}
747747
});
748748
for dir in dirs.into_iter() {
749-
cmd = cmd.arg("-L").arg(dir);
749+
cmd = cmd.arg("-L").arg(format!("native={}", dir.display()));
750750
}
751751

752752
for &(pkg, target) in cx.dep_targets(package, target).iter() {
@@ -757,8 +757,9 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package
757757
target.is_lib() && target.get_profile().is_compile()
758758
});
759759

760-
if target.is_bin() && !target.get_profile().is_custom_build() {
761-
for target in targets.filter(|f| !f.is_staticlib()) {
760+
if (target.is_bin() || target.is_example()) &&
761+
!target.get_profile().is_custom_build() {
762+
for target in targets.filter(|f| f.is_rlib() || f.is_dylib()) {
762763
cmd = try!(link_to(cmd, package, target, cx, kind));
763764
}
764765
}
@@ -777,6 +778,7 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package
777778
});
778779

779780
for filename in try!(cx.target_filenames(target)).iter() {
781+
if filename.as_bytes().ends_with(b".a") { continue }
780782
let mut v = Vec::new();
781783
v.push_all(target.get_name().as_bytes());
782784
v.push(b'=');

tests/test_cargo_build_lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
1414
-C extra-filename=-[..] \
1515
--out-dir {dir}{sep}target \
1616
--emit=dep-info,link \
17-
-L {dir}{sep}target \
18-
-L {dir}{sep}target{sep}deps`
17+
-L dependency={dir}{sep}target \
18+
-L dependency={dir}{sep}target{sep}deps`
1919
",
2020
running = RUNNING, compiling = COMPILING, sep = path::SEP,
2121
dir = p.root().display(), url = p.url(),

tests/test_cargo_compile.rs

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,8 @@ test!(lto_build {
757757
--cfg ndebug \
758758
--out-dir {dir}{sep}target{sep}release \
759759
--emit=dep-info,link \
760-
-L {dir}{sep}target{sep}release \
761-
-L {dir}{sep}target{sep}release{sep}deps`
760+
-L dependency={dir}{sep}target{sep}release \
761+
-L dependency={dir}{sep}target{sep}release{sep}deps`
762762
",
763763
running = RUNNING, compiling = COMPILING, sep = path::SEP,
764764
dir = p.root().display(),
@@ -785,8 +785,8 @@ test!(verbose_build {
785785
-C extra-filename=-[..] \
786786
--out-dir {dir}{sep}target \
787787
--emit=dep-info,link \
788-
-L {dir}{sep}target \
789-
-L {dir}{sep}target{sep}deps`
788+
-L dependency={dir}{sep}target \
789+
-L dependency={dir}{sep}target{sep}deps`
790790
",
791791
running = RUNNING, compiling = COMPILING, sep = path::SEP,
792792
dir = p.root().display(),
@@ -815,8 +815,8 @@ test!(verbose_release_build {
815815
-C extra-filename=-[..] \
816816
--out-dir {dir}{sep}target{sep}release \
817817
--emit=dep-info,link \
818-
-L {dir}{sep}target{sep}release \
819-
-L {dir}{sep}target{sep}release{sep}deps`
818+
-L dependency={dir}{sep}target{sep}release \
819+
-L dependency={dir}{sep}target{sep}release{sep}deps`
820820
",
821821
running = RUNNING, compiling = COMPILING, sep = path::SEP,
822822
dir = p.root().display(),
@@ -861,8 +861,8 @@ test!(verbose_release_build_deps {
861861
-C extra-filename=-[..] \
862862
--out-dir {dir}{sep}target{sep}release{sep}deps \
863863
--emit=dep-info,link \
864-
-L {dir}{sep}target{sep}release{sep}deps \
865-
-L {dir}{sep}target{sep}release{sep}deps`
864+
-L dependency={dir}{sep}target{sep}release{sep}deps \
865+
-L dependency={dir}{sep}target{sep}release{sep}deps`
866866
{compiling} test v0.0.0 ({url})
867867
{running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
868868
-C opt-level=3 \
@@ -871,8 +871,8 @@ test!(verbose_release_build_deps {
871871
-C extra-filename=-[..] \
872872
--out-dir {dir}{sep}target{sep}release \
873873
--emit=dep-info,link \
874-
-L {dir}{sep}target{sep}release \
875-
-L {dir}{sep}target{sep}release{sep}deps \
874+
-L dependency={dir}{sep}target{sep}release \
875+
-L dependency={dir}{sep}target{sep}release{sep}deps \
876876
--extern foo={dir}{sep}target{sep}release{sep}deps/\
877877
{prefix}foo-[..]{suffix} \
878878
--extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`
@@ -1119,7 +1119,7 @@ test!(staticlib_rlib_and_bin {
11191119
foo::foo();
11201120
}"#);
11211121

1122-
assert_that(p.cargo_process("build"), execs().with_status(0));
1122+
assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0));
11231123
});
11241124

11251125
test!(opt_out_of_lib {
@@ -1523,3 +1523,47 @@ test!(compile_then_delete {
15231523
assert_that(p.process(cargo_dir().join("cargo")).arg("run"),
15241524
execs().with_status(0));
15251525
});
1526+
1527+
test!(transitive_dependencies_not_available {
1528+
let p = project("foo")
1529+
.file("Cargo.toml", r#"
1530+
[package]
1531+
name = "foo"
1532+
version = "0.0.1"
1533+
authors = []
1534+
1535+
[dependencies.a]
1536+
path = "a"
1537+
"#)
1538+
.file("src/main.rs", "extern crate b; extern crate a; fn main() {}")
1539+
.file("a/Cargo.toml", r#"
1540+
[package]
1541+
name = "a"
1542+
version = "0.0.1"
1543+
authors = []
1544+
1545+
[dependencies.b]
1546+
path = "../b"
1547+
"#)
1548+
.file("a/src/lib.rs", "extern crate b;")
1549+
.file("b/Cargo.toml", r#"
1550+
[package]
1551+
name = "b"
1552+
version = "0.0.1"
1553+
authors = []
1554+
"#)
1555+
.file("b/src/lib.rs", "");
1556+
1557+
assert_that(p.cargo_process("build").arg("-v"),
1558+
execs().with_status(101)
1559+
.with_stderr("\
1560+
[..] can't find crate for `b`
1561+
[..] extern crate b; [..]
1562+
[..]
1563+
error: aborting due to previous error
1564+
Could not compile `foo`.
1565+
1566+
Caused by:
1567+
[..]
1568+
"));
1569+
});

tests/test_cargo_cross_compile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ test!(linker_and_ar {
303303
--emit=dep-info,link \
304304
--target {target} \
305305
-C ar=my-ar-tool -C linker=my-linker-tool \
306-
-L {dir}{sep}target{sep}{target} \
307-
-L {dir}{sep}target{sep}{target}{sep}deps`
306+
-L dependency={dir}{sep}target{sep}{target} \
307+
-L dependency={dir}{sep}target{sep}{target}{sep}deps`
308308
",
309309
running = RUNNING,
310310
compiling = COMPILING,

tests/test_cargo_profiles.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ test!(profile_overrides {
3535
-C rpath \
3636
--out-dir {dir}{sep}target \
3737
--emit=dep-info,link \
38-
-L {dir}{sep}target \
39-
-L {dir}{sep}target{sep}deps`
38+
-L dependency={dir}{sep}target \
39+
-L dependency={dir}{sep}target{sep}deps`
4040
",
4141
running = RUNNING, compiling = COMPILING, sep = path::SEP,
4242
dir = p.root().display(),
@@ -89,8 +89,8 @@ test!(top_level_overrides_deps {
8989
-C extra-filename=-[..] \
9090
--out-dir {dir}{sep}target{sep}release{sep}deps \
9191
--emit=dep-info,link \
92-
-L {dir}{sep}target{sep}release{sep}deps \
93-
-L {dir}{sep}target{sep}release{sep}deps`
92+
-L dependency={dir}{sep}target{sep}release{sep}deps \
93+
-L dependency={dir}{sep}target{sep}release{sep}deps`
9494
{compiling} test v0.0.0 ({url})
9595
{running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
9696
-C opt-level=1 \
@@ -99,8 +99,8 @@ test!(top_level_overrides_deps {
9999
-C extra-filename=-[..] \
100100
--out-dir {dir}{sep}target{sep}release \
101101
--emit=dep-info,link \
102-
-L {dir}{sep}target{sep}release \
103-
-L {dir}{sep}target{sep}release{sep}deps \
102+
-L dependency={dir}{sep}target{sep}release \
103+
-L dependency={dir}{sep}target{sep}release{sep}deps \
104104
--extern foo={dir}{sep}target{sep}release{sep}deps/\
105105
{prefix}foo-[..]{suffix} \
106106
--extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`

0 commit comments

Comments
 (0)