Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
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
14 changes: 11 additions & 3 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2209,9 +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", "")
.file("bar/src/bin/baz.rs", "fn main() {}")
.file("bar/src/bin/qux.rs", "fn main() {}")
.build();

foo.cargo("build").run();

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 @@ -3396,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