Skip to content

Commit

Permalink
Select all matching targets, not just the first one
Browse files Browse the repository at this point in the history
This means that all binaries will be built. Additionally, tests have
been updated to validate the new behavior.
  • Loading branch information
npmccallum committed Jan 24, 2020
1 parent ab47de9 commit 88887d4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
47 changes: 23 additions & 24 deletions src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,30 +266,29 @@ fn compute_deps<'a, 'cfg>(
Some(pkg) => pkg,
None => continue,
};
let lib = match pkg.targets().iter().find(|t| t.is_lib() || t.is_bin()) {
Some(t) => t,
None => continue,
};
let mode = check_or_build_mode(unit.mode, lib);
let dep_unit_for = unit_for.with_for_host(lib.for_host());

if bcx.config.cli_unstable().dual_proc_macros && lib.proc_macro() && !unit.kind.is_host() {
let unit_dep = new_unit_dep(state, unit, pkg, lib, dep_unit_for, unit.kind, mode)?;
ret.push(unit_dep);
let unit_dep =
new_unit_dep(state, unit, pkg, lib, dep_unit_for, CompileKind::Host, mode)?;
ret.push(unit_dep);
} else {
let unit_dep = new_unit_dep(
state,
unit,
pkg,
lib,
dep_unit_for,
unit.kind.for_target(lib),
mode,
)?;
ret.push(unit_dep);

for target in pkg.targets().iter().filter(|t| t.is_lib() || t.is_bin()) {
let mode = check_or_build_mode(unit.mode, target);
let dep_unit_for = unit_for.with_for_host(target.for_host());
let proc_macros = bcx.config.cli_unstable().dual_proc_macros && target.proc_macro();

let kinds = if proc_macros && !unit.kind.is_host() {
vec![unit.kind, CompileKind::Host]
} else {
vec![unit.kind.for_target(target)]
};

for kind in kinds {
ret.push(new_unit_dep(
state,
unit,
pkg,
target,
dep_unit_for,
kind,
mode,
)?);
}
}
}

Expand Down
16 changes: 10 additions & 6 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2194,8 +2194,6 @@ fn rebuild_preserves_out_dir() {

#[cargo_test]
fn dep_no_libs() {
let exe_name = format!("bar{}", env::consts::EXE_SUFFIX);

let foo = project()
.file(
"Cargo.toml",
Expand All @@ -2211,11 +2209,17 @@ fn dep_no_libs() {
)
.file("src/lib.rs", "pub fn bar() -> i32 { 1 }")
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.0"))
.file("bar/src/main.rs", "fn main() {}")
.file("bar/src/bin/baz.rs", "fn main() {}")
.file("bar/src/bin/qux.rs", "fn main() {}")
.build();

foo.cargo("build").run();
assert!(foo.target_debug_dir().join(exe_name).exists());

let baz = format!("baz{}", env::consts::EXE_SUFFIX);
assert!(foo.target_debug_dir().join(baz).exists());

let qux = format!("qux{}", env::consts::EXE_SUFFIX);
assert!(foo.target_debug_dir().join(qux).exists());
}

#[cargo_test]
Expand Down Expand Up @@ -3400,8 +3404,8 @@ fn build_all_workspace_implicit_examples() {
assert!(!p.bin("b").is_file());
assert!(p.bin("examples/c").is_file());
assert!(p.bin("examples/d").is_file());
assert!(!p.bin("e").is_file());
assert!(!p.bin("f").is_file());
assert!(p.bin("e").is_file());
assert!(p.bin("f").is_file());
assert!(p.bin("examples/g").is_file());
assert!(p.bin("examples/h").is_file());
}
Expand Down
8 changes: 6 additions & 2 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,9 +1688,13 @@ fn selective_testing() {

println!("whole");
p.cargo("test")
// NOTE: The compilation order appears to be unpredictable.
// Therefore, the test will sporadically fail. How do I solve for this?
// I've tried reducing parallelism to 1 without success.
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
" Compiling d2 v0.0.1 ([CWD]/d2)
Compiling d1 v0.0.1 ([CWD]/d1)
Compiling foo v0.0.1 ([CWD])
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/debug/deps/foo-[..][EXE]",
)
Expand Down
8 changes: 4 additions & 4 deletions tests/testsuite/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn inferred_path_dep() {

p.cargo("build").run();
assert!(p.bin("foo").is_file());
assert!(!p.bin("bar").is_file());
assert!(p.bin("bar").is_file());

p.cargo("build").cwd("bar").run();
assert!(p.bin("foo").is_file());
Expand Down Expand Up @@ -228,13 +228,13 @@ fn transitive_path_dep() {

p.cargo("build").run();
assert!(p.bin("foo").is_file());
assert!(!p.bin("bar").is_file());
assert!(!p.bin("baz").is_file());
assert!(p.bin("bar").is_file());
assert!(p.bin("baz").is_file());

p.cargo("build").cwd("bar").run();
assert!(p.bin("foo").is_file());
assert!(p.bin("bar").is_file());
assert!(!p.bin("baz").is_file());
assert!(p.bin("baz").is_file());

p.cargo("build").cwd("baz").run();
assert!(p.bin("foo").is_file());
Expand Down

0 comments on commit 88887d4

Please sign in to comment.