Skip to content
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

artifact deps should works when target field specified coexists with optional = true #11434

Merged
merged 5 commits into from
Dec 14, 2022

Conversation

weihanglo
Copy link
Member

What does this PR try to resolve?

Another attempt to fix #10526 after #11183 failed.
You can find an explanation of the bug in #11183 or in the commit message.

How should we test and review this PR?

This first two commits log the current "incorrect" behaviour.
Other commits contain fixes respectively.

You may find more details in the commit messages.

@rustbot
Copy link
Collaborator

rustbot commented Nov 28, 2022

r? @ehuss

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 28, 2022
> Adapted from rust-lang#11183

Previously, `is_dep_activated` depends on `activated_dependencies`,
which is a map of `PackageFeaturesKey` to its own activated `DepFeature`s.
`PackageFeaturesKey` in feature resolver is always comprised of

* A `PackageId` of a given dependency, and
* A enum value that helps decoupling activated features for that dependency.
  Currently depending on the type of given dependency.

Looking into issue 10526, it has an `activated_dependencies` of

```
{
    (mycrate, NormalOrDev) -> [dep:mybindep]
}
```

However, this [line][1] accidentally use a parent's `pkgid`
and a dependency's `FeaturesFor` to compose a key:

```
(mycrate, ArtifactDep("x86_64-unknown-linux-gnu"))
```

That is never a valid key to query features for artifacts dependency.
A valid key should be comprised of components both from the parent:

```
(mycrate, NormalOrDev)
```

Or both from the dependency itself:

```
(mybindep, ArtifactDep("x86_64-unknown-linux-gnu"))
```

This `unit_for` is from parent and should already contain its own
artifact dep information inside `artifact_target_for_features`,
so we don't need to map any dependency artifact from `dep.artifact()`.

[1]: https://github.com/rust-lang/cargo/blob/a2ea66bea6fe8156444144e98911d073d56c2c0c/src/cargo/core/compiler/unit_dependencies.rs#L1106-L1107
`{ …, 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
@ehuss
Copy link
Contributor

ehuss commented Dec 13, 2022

Was a regression test ever added that would catch the regression in #11330?

@weihanglo
Copy link
Member Author

I believe the regression test was done in #11342

@ehuss
Copy link
Contributor

ehuss commented Dec 13, 2022

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Dec 13, 2022

📌 Commit eca3e23 has been approved by ehuss

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 13, 2022
@bors
Copy link
Collaborator

bors commented Dec 14, 2022

⌛ Testing commit eca3e23 with merge cc0a320...

@bors
Copy link
Collaborator

bors commented Dec 14, 2022

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing cc0a320 to master...

@bors bors merged commit cc0a320 into rust-lang:master Dec 14, 2022
@weihanglo weihanglo deleted the issue/10526 branch December 14, 2022 15:58
weihanglo added a commit to weihanglo/rust that referenced this pull request Dec 14, 2022
8 commits in 70898e522116f6c23971e2a554b2dc85fd4c84cd..cc0a320879c17207bbfb96b5d778e28a2c62030d
2022-12-05 19:43:44 +0000 to 2022-12-14 14:46:57 +0000
- artifact deps should works when target field specified coexists with `optional = true` (rust-lang/cargo#11434)
- Add `home` crate to cargo crates (rust-lang/cargo#11359)
- Use proper git URL for GitHub repos (rust-lang/cargo#11475)
- Fixes flock(fd, LOCK_UN) emulation on Solaris. (rust-lang/cargo#11474)
- Allow Check targets needed for optional doc-scraping to fail without killing the build (rust-lang/cargo#11450)
- fix: gleaning rustdocflags from `target.cfg(…)` is not supported (rust-lang/cargo#11323)
- Fix typo (rust-lang/cargo#11470)
- resolver.md: Fix naming in example (rust-lang/cargo#11469)
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 14, 2022
Update cargo

8 commits in 70898e522116f6c23971e2a554b2dc85fd4c84cd..cc0a320879c17207bbfb96b5d778e28a2c62030d 2022-12-05 19:43:44 +0000 to 2022-12-14 14:46:57 +0000
- artifact deps should works when target field specified coexists with `optional = true` (rust-lang/cargo#11434)
- Add `home` crate to cargo crates (rust-lang/cargo#11359)
- Use proper git URL for GitHub repos (rust-lang/cargo#11475)
- Fixes flock(fd, LOCK_UN) emulation on Solaris. (rust-lang/cargo#11474)
- Allow Check targets needed for optional doc-scraping to fail without killing the build (rust-lang/cargo#11450)
- fix: gleaning rustdocflags from `target.cfg(…)` is not supported (rust-lang/cargo#11323)
- Fix typo (rust-lang/cargo#11470)
- resolver.md: Fix naming in example (rust-lang/cargo#11469)

r? `@ghost`
@ehuss ehuss added this to the 1.68.0 milestone Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Binary dependency is never built if specified with both optional and target keys
4 participants