Skip to content

Commit

Permalink
Start using precise -L flags
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexcrichton committed Jan 6, 2015
1 parent ba28004 commit 5be647e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package
cx: &Context,
kind: Kind) -> CargoResult<CommandPrototype> {
let layout = cx.layout(package, kind);
cmd = cmd.arg("-L").arg(layout.root());
cmd = cmd.arg("-L").arg(layout.deps());
cmd = cmd.arg("-L").arg(format!("dependency={}", layout.root().display()));
cmd = cmd.arg("-L").arg(format!("dependency={}", layout.deps().display()));

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

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

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

for filename in try!(cx.target_filenames(target)).iter() {
if filename.as_bytes().ends_with(b".a") { continue }
let mut v = Vec::new();
v.push_all(target.get_name().as_bytes());
v.push(b'=');
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cargo_build_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
-C extra-filename=-[..] \
--out-dir {dir}{sep}target \
--emit=dep-info,link \
-L {dir}{sep}target \
-L {dir}{sep}target{sep}deps`
-L dependency={dir}{sep}target \
-L dependency={dir}{sep}target{sep}deps`
",
running = RUNNING, compiling = COMPILING, sep = path::SEP,
dir = p.root().display(), url = p.url(),
Expand Down
66 changes: 55 additions & 11 deletions tests/test_cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ test!(lto_build {
--cfg ndebug \
--out-dir {dir}{sep}target{sep}release \
--emit=dep-info,link \
-L {dir}{sep}target{sep}release \
-L {dir}{sep}target{sep}release{sep}deps`
-L dependency={dir}{sep}target{sep}release \
-L dependency={dir}{sep}target{sep}release{sep}deps`
",
running = RUNNING, compiling = COMPILING, sep = path::SEP,
dir = p.root().display(),
Expand All @@ -785,8 +785,8 @@ test!(verbose_build {
-C extra-filename=-[..] \
--out-dir {dir}{sep}target \
--emit=dep-info,link \
-L {dir}{sep}target \
-L {dir}{sep}target{sep}deps`
-L dependency={dir}{sep}target \
-L dependency={dir}{sep}target{sep}deps`
",
running = RUNNING, compiling = COMPILING, sep = path::SEP,
dir = p.root().display(),
Expand Down Expand Up @@ -815,8 +815,8 @@ test!(verbose_release_build {
-C extra-filename=-[..] \
--out-dir {dir}{sep}target{sep}release \
--emit=dep-info,link \
-L {dir}{sep}target{sep}release \
-L {dir}{sep}target{sep}release{sep}deps`
-L dependency={dir}{sep}target{sep}release \
-L dependency={dir}{sep}target{sep}release{sep}deps`
",
running = RUNNING, compiling = COMPILING, sep = path::SEP,
dir = p.root().display(),
Expand Down Expand Up @@ -861,8 +861,8 @@ test!(verbose_release_build_deps {
-C extra-filename=-[..] \
--out-dir {dir}{sep}target{sep}release{sep}deps \
--emit=dep-info,link \
-L {dir}{sep}target{sep}release{sep}deps \
-L {dir}{sep}target{sep}release{sep}deps`
-L dependency={dir}{sep}target{sep}release{sep}deps \
-L dependency={dir}{sep}target{sep}release{sep}deps`
{compiling} test v0.0.0 ({url})
{running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
-C opt-level=3 \
Expand All @@ -871,8 +871,8 @@ test!(verbose_release_build_deps {
-C extra-filename=-[..] \
--out-dir {dir}{sep}target{sep}release \
--emit=dep-info,link \
-L {dir}{sep}target{sep}release \
-L {dir}{sep}target{sep}release{sep}deps \
-L dependency={dir}{sep}target{sep}release \
-L dependency={dir}{sep}target{sep}release{sep}deps \
--extern foo={dir}{sep}target{sep}release{sep}deps/\
{prefix}foo-[..]{suffix} \
--extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`
Expand Down Expand Up @@ -1119,7 +1119,7 @@ test!(staticlib_rlib_and_bin {
foo::foo();
}"#);

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

test!(opt_out_of_lib {
Expand Down Expand Up @@ -1523,3 +1523,47 @@ test!(compile_then_delete {
assert_that(p.process(cargo_dir().join("cargo")).arg("run"),
execs().with_status(0));
});

test!(transitive_dependencies_not_available {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies.a]
path = "a"
"#)
.file("src/main.rs", "extern crate b; extern crate a; fn main() {}")
.file("a/Cargo.toml", r#"
[package]
name = "a"
version = "0.0.1"
authors = []
[dependencies.b]
path = "../b"
"#)
.file("a/src/lib.rs", "extern crate b;")
.file("b/Cargo.toml", r#"
[package]
name = "b"
version = "0.0.1"
authors = []
"#)
.file("b/src/lib.rs", "");

assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(101)
.with_stderr("\
[..] can't find crate for `b`
[..] extern crate b; [..]
[..]
error: aborting due to previous error
Could not compile `foo`.
Caused by:
[..]
"));
});
4 changes: 2 additions & 2 deletions tests/test_cargo_cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ test!(linker_and_ar {
--emit=dep-info,link \
--target {target} \
-C ar=my-ar-tool -C linker=my-linker-tool \
-L {dir}{sep}target{sep}{target} \
-L {dir}{sep}target{sep}{target}{sep}deps`
-L dependency={dir}{sep}target{sep}{target} \
-L dependency={dir}{sep}target{sep}{target}{sep}deps`
",
running = RUNNING,
compiling = COMPILING,
Expand Down
12 changes: 6 additions & 6 deletions tests/test_cargo_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ test!(profile_overrides {
-C rpath \
--out-dir {dir}{sep}target \
--emit=dep-info,link \
-L {dir}{sep}target \
-L {dir}{sep}target{sep}deps`
-L dependency={dir}{sep}target \
-L dependency={dir}{sep}target{sep}deps`
",
running = RUNNING, compiling = COMPILING, sep = path::SEP,
dir = p.root().display(),
Expand Down Expand Up @@ -89,8 +89,8 @@ test!(top_level_overrides_deps {
-C extra-filename=-[..] \
--out-dir {dir}{sep}target{sep}release{sep}deps \
--emit=dep-info,link \
-L {dir}{sep}target{sep}release{sep}deps \
-L {dir}{sep}target{sep}release{sep}deps`
-L dependency={dir}{sep}target{sep}release{sep}deps \
-L dependency={dir}{sep}target{sep}release{sep}deps`
{compiling} test v0.0.0 ({url})
{running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
-C opt-level=1 \
Expand All @@ -99,8 +99,8 @@ test!(top_level_overrides_deps {
-C extra-filename=-[..] \
--out-dir {dir}{sep}target{sep}release \
--emit=dep-info,link \
-L {dir}{sep}target{sep}release \
-L {dir}{sep}target{sep}release{sep}deps \
-L dependency={dir}{sep}target{sep}release \
-L dependency={dir}{sep}target{sep}release{sep}deps \
--extern foo={dir}{sep}target{sep}release{sep}deps/\
{prefix}foo-[..]{suffix} \
--extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`
Expand Down

0 comments on commit 5be647e

Please sign in to comment.