Skip to content

Commit ce9d5ff

Browse files
committed
fix(bindeps): assumed host target and optional = true coexist
`{ …, artifact = "bin", target = "target" }` should also be considered to being built for `FeaturesFor::ArtifactDep` instead of `NormalOrDev`. [This line][1] requests for `ArtifactDep` but [here][2] Cargo ignore assumed host target of artifact dep. Change it to explicit set host target triple when - `{ …, target = "target" }`, and - `--target` is not presented, meaning it would be build on host platform. [1]: https://github.com/rust-lang/cargo/blob/1382b44e431f58199afdffc2b757962b0e163602/src/cargo/core/compiler/unit_dependencies.rs#L887 [2]: https://github.com/rust-lang/cargo/blob/1382b44e431f58199afdffc2b757962b0e163602/src/cargo/core/resolver/features.rs#L857
1 parent 67e14be commit ce9d5ff

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/cargo/core/resolver/features.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -853,12 +853,14 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
853853
ArtifactTarget::BuildDependencyAssumeTarget => self
854854
.requested_targets
855855
.iter()
856-
.filter_map(|kind| match kind {
857-
CompileKind::Host => None,
858-
CompileKind::Target(target) => {
859-
Some(FeaturesFor::ArtifactDep(*target))
856+
.map(|kind| match kind {
857+
CompileKind::Host => {
858+
let host_triple = self.target_data.rustc.host;
859+
CompileTarget::new(&host_triple).unwrap()
860860
}
861+
CompileKind::Target(target) => *target,
861862
})
863+
.map(FeaturesFor::ArtifactDep)
862864
.collect(),
863865
}),
864866
)

tests/testsuite/artifact_dep.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,7 +2399,6 @@ fn with_target_and_optional() {
23992399

24002400
#[cargo_test]
24012401
fn with_assumed_host_target_and_optional_build_dep() {
2402-
// This exercises an incorrect behaviour got to be fixed by the following commit.
24032402
let p = project()
24042403
.file(
24052404
"Cargo.toml",
@@ -2435,8 +2434,16 @@ fn with_assumed_host_target_and_optional_build_dep() {
24352434

24362435
p.cargo("check -Z bindeps -F d1 -v")
24372436
.masquerade_as_nightly_cargo(&["bindeps"])
2438-
.with_status(101)
2439-
.with_stderr_contains("[ERROR] failed to run custom build command for `foo v0.0.1 ([..])`")
2440-
.with_stderr_contains("[..]thread '[..]' panicked at 'called `Result::unwrap()`[..]")
2437+
.with_stderr_unordered(
2438+
"\
2439+
[COMPILING] foo v0.0.1 ([CWD])
2440+
[COMPILING] d1 v0.0.1 ([CWD]/d1)
2441+
[RUNNING] `rustc --crate-name build_script_build [..]--crate-type bin[..]
2442+
[RUNNING] `rustc --crate-name d1 [..]--crate-type bin[..]
2443+
[RUNNING] `[CWD]/target/debug/build/foo-[..]/build-script-build`
2444+
[RUNNING] `rustc --crate-name foo [..]--cfg[..]d1[..]
2445+
[FINISHED] dev [..]
2446+
",
2447+
)
24412448
.run();
24422449
}

0 commit comments

Comments
 (0)