-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(bindeps): do not propagate artifact dependency to proc macro or build deps #15788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
r? @weihanglo rustbot has assigned @weihanglo. Use |
|
This PR should fix #12358 too. |
|
Hi @weihanglo , it has been a few months, do you have any feedbacks on this PR? Thank you! |
|
Oops. It completely slipped off my radar 😅. I'll find some time to review it this week. Sorry for the huge delay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Looks pretty good to me. And sorry for the extremely long delay 🙇🏾♂️.
| } else { | ||
| self.panic_setting | ||
| }; | ||
| let artifact_target_for_features = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a simple comment here explaining why we clearing the marker here? Like build.rs itself (not build-deps) and proc macros are always for host.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| r#"pub fn add(a: i32, b: i32) -> i32 { a + b }"#, | ||
| ) | ||
| .build(); | ||
| p.cargo("test -Z bindeps") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind adding with_stderr_data(str![[""]]) to ensure that we really build arch? Ditto for proc macro test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll need to set env SNAPSHOTS=overwrite to regenerate test snapshot locally and commit it btw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @Lencerf!
https://github.com/rust-lang/cargo/actions/runs/19524318318/job/55893849063?pr=15788#step:15:4772
I know it is annoying, but we also need to append [EXE] for binary paths for windows compatibility
- [RUNNING] unittests src/main.rs (target/debug/deps/foo-[HASH])
+ [RUNNING] unittests src/main.rs (target/debug/deps/foo-[HASH][EXE])There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback! CI now passes!
Add 2 test cases to reproduce a bug of `-Zbindeps`.
Basically, if
- a package `foo` has an artifact dependency `artifact` with a specified
target TARGET_ARTIFACT different from host TARGET_HOST,
- `artifact` depends on proc macro `macro`,
- `macro` conditionally depends on `arch` on TARGET_HOST,
cargo build would panic on TARGET_HOST with the following error message:
```
did not find features for (PackageId { name: "arch", version: "0.0.1", source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo/arch" }, ArtifactDep(CompileTarget { name: "x86_64-apple-darwin" })) within activated_features:
[
(
PackageId {
name: "foo",
version: "0.0.1",
source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo",
},
NormalOrDev,
),
(
PackageId {
name: "macro",
version: "0.0.1",
source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo/macro",
},
ArtifactDep(
CompileTarget {
name: "x86_64-apple-darwin",
},
),
),
(
PackageId {
name: "artifact",
version: "0.0.1",
source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo/artifact",
},
ArtifactDep(
CompileTarget {
name: "x86_64-apple-darwin",
},
),
),
]
```
Similar panic happens when
- a package `foo` has an artifact dependency `artifact` with a specified
target TARGET_ARTIFACT different from host TARGET_HOST,
- `artifact` has a build dependency `builder`,
- `builder` conditionally depends on `arch` on TARGET_HOST.
Signed-off-by: Changyuan Lyu <[email protected]>
b546338 to
a5bedb3
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
bfe05fc to
7877719
Compare
…uild deps
As reproduced in the 2 fixed test cases of this commit, cargo panicked
when
- a package `foo` has an artifact dependency `artifact` with a specified
target TARGET_ARTIFACT different from host TARGET_HOST,
- `artifact` depends on proc macro `macro`,
- `macro` conditionally depends on `arch` on TARGET_HOST,
with the following message
```
did not find features for (PackageId { name: "arch", version: "0.0.1", source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo/arch" }, ArtifactDep(CompileTarget { name: "x86_64-apple-darwin" })) within activated_features:
[
(
PackageId {
name: "foo",
version: "0.0.1",
source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo",
},
NormalOrDev,
),
(
PackageId {
name: "macro",
version: "0.0.1",
source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo/macro",
},
ArtifactDep(
CompileTarget {
name: "x86_64-apple-darwin",
},
),
),
(
PackageId {
name: "artifact",
version: "0.0.1",
source: "/Users/lencerf/Developer/cargo/target/tmp/cit/t0/foo/artifact",
},
ArtifactDep(
CompileTarget {
name: "x86_64-apple-darwin",
},
),
),
]
```
From the above message, it is clear that proc macro `macro` was wrongly
associated with `FeaturesFor::ArtifactDep` instead of
`FeaturesFor::HostDep`. Package `arch` was later ignored because cargo
thought `macro` should be built for TARGET_ARTIFACT
(x86_64-apple-darwin), while `arch` was conditionally needed on
TARGET_HOST (aarch64-apple-darwin).
Similar analyses apply to the other test case.
This commit fixes 2 paths:
- when resolving features, if we encounter build dependencies or proc
macros, always associate them with `FeaturesFor::HostDep`.
- when deriving UnitFor for dependencies, stop propagating
artifact_target_for_features if the the dependency is a build
dependency or a proc macro.
Signed-off-by: Changyuan Lyu <[email protected]>
7877719 to
0360309
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
Update cargo submodule 7 commits in 5c0343317ce45d2ec17ecf41eaa473a02d73e29c..9fa462fe3a81e07e0bfdcc75c29d312c55113ebb 2025-11-18 19:05:44 +0000 to 2025-11-21 20:49:51 +0000 - Enable CARGO_CFG_DEBUG_ASSERTIONS in build scripts based on profile (rust-lang/cargo#16160) - fix(config-include): disallow glob and template syntax (rust-lang/cargo#16285) - test(config-include): include always relative to including config (rust-lang/cargo#16286) - docs(guide): When suggesting alt dev profile, link to related issue (rust-lang/cargo#16275) - refactor(timings): separate data collection and presentation (rust-lang/cargo#16282) - test(build-std): Add test for LTO (rust-lang/cargo#16277) - fix(bindeps): do not propagate artifact dependency to proc macro or build deps (rust-lang/cargo#15788) r? ghost
Thanks for the pull request 🎉!
Please read the contribution guide: https://doc.crates.io/contrib/.
What does this PR try to resolve?
This PR fixes a bug for the nightly feature
bindeps. Basically, iffoohas an artifact dependencyartifactwith a specified target TARGET_ARTIFACT different from host TARGET_HOST,artifactdepends on proc macromacro,macroconditionally depends onarchon TARGET_HOST,cargo build would panic on TARGET_HOST with the following error message:
Similar panic happens when
foohas an artifact dependencyartifactwith a specified target TARGET_ARTIFACT different from host TARGET_HOST,artifacthas a build dependencybuilder,builderconditionally depends onarchon TARGET_HOST.From the above message, it is clear that proc macro
macrowas wrongly associated withFeaturesFor::ArtifactDepinstead ofFeaturesFor::HostDep. Packagearchwas later ignored because cargo thoughtmacroshould be built for TARGET_ARTIFACT (x86_64-apple-darwin), whilearchwas conditionally needed on TARGET_HOST (aarch64-apple-darwin).Similar analyses apply to the other test case.
This commit fixes 2 paths:
FeaturesFor::HostDep.How to test and review this PR?
This PR contains 2 commits
#[should_panic]#[should_panic]from the 2 test cases.cargo testcan pass on each commit.