Skip to content

Use cargo tree to determine feature dependent optional deps#2636

Merged
UebelAndre merged 4 commits intobazelbuild:mainfrom
UebelAndre:crate_universe_update
May 8, 2024
Merged

Use cargo tree to determine feature dependent optional deps#2636
UebelAndre merged 4 commits intobazelbuild:mainfrom
UebelAndre:crate_universe_update

Conversation

@UebelAndre
Copy link
Copy Markdown
Collaborator

@UebelAndre UebelAndre commented May 1, 2024

The Cargo Feature Resolver version 2 behavior is currently not supported by the cargo metadata sub command (rust-lang/cargo#9863) which crate_universe uses to determine the dependencies of a target, leading to inaccuracies when dependencies are introduced via feature resolution for a particular configuration.

In #1710 functionality was added to use cargo tree to perform feature resolution for each supported platform. This change expands on this trick to collect dependency information at the same time and use that to determine whether or not to include optional dependencies located in standard cargo metadata output in the rendered Bazel targets. Non optional or target.cfg (conditional) dependencies behave as they did before this change.

Implementation details:

  • FeatureGenerator was replaced by TreeResolver
  • Optional dependencies are now rendered as selects on explicit platforms. This will expand the size of cargo-bazel-lock.json files but is expected to be more correct.

@UebelAndre UebelAndre force-pushed the crate_universe_update branch 7 times, most recently from 3eab4cb to 80ab8f0 Compare May 1, 2024 14:58
@UebelAndre UebelAndre force-pushed the crate_universe_update branch 4 times, most recently from 5fae2ea to 3ac66cd Compare May 3, 2024 05:30
@UebelAndre UebelAndre marked this pull request as ready for review May 4, 2024 01:47
@UebelAndre UebelAndre requested a review from illicitonion May 4, 2024 01:48
@UebelAndre UebelAndre force-pushed the crate_universe_update branch from 3ac66cd to 6747d08 Compare May 4, 2024 01:48
@UebelAndre UebelAndre changed the title Use cargo tree to determine resolver = 2 dep trees Use cargo tree to determine feature dependent optional deps May 4, 2024
@UebelAndre UebelAndre force-pushed the crate_universe_update branch from 6747d08 to 2129099 Compare May 4, 2024 15:10
@UebelAndre
Copy link
Copy Markdown
Collaborator Author

I recommend reviewers take this change one commit at a time. There are two very noisy commits with a bunch of rendered output.

@UebelAndre
Copy link
Copy Markdown
Collaborator Author

UebelAndre commented May 4, 2024

I also don't think this closes #2212 since if I understand the issue correctly, [build-dependencies] are always evaluated by the current host triple so if there are any platform specific [build-dependencies] then there's no current way to get cargo tree to resolve those for a different platform than the current platform. I'm unlinking that issue to this PR.

@UebelAndre UebelAndre force-pushed the crate_universe_update branch from 2129099 to f04b4e5 Compare May 7, 2024 14:03
@UebelAndre UebelAndre mentioned this pull request May 7, 2024
@UebelAndre UebelAndre force-pushed the crate_universe_update branch from f04b4e5 to 2370c5c Compare May 8, 2024 15:11
Copy link
Copy Markdown
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Thank you!!

@UebelAndre UebelAndre added this pull request to the merge queue May 8, 2024
Merged via the queue into bazelbuild:main with commit f22926a May 8, 2024
rrbutani referenced this pull request in bazel-contrib/toolchains_llvm May 9, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [rules_rust](https://togithub.com/bazelbuild/rules_rust) |
http_archive | minor | `0.42.1` -> `0.43.0` |

---

### Release Notes

<details>
<summary>bazelbuild/rules_rust (rules_rust)</summary>

###
[`v0.43.0`](https://togithub.com/bazelbuild/rules_rust/releases/tag/0.43.0)

[Compare
Source](https://togithub.com/bazelbuild/rules_rust/compare/0.42.1...0.43.0)

### 0.43.0

```python
load("@&#8203;bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_rust",
    integrity = "sha256-SnzocNvQp1YK1TW/aUVhR6RSROo1l2RilE1V20WFnK0=",
    urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.43.0/rules_rust-v0.43.0.tar.gz"],
)
```

Additional documentation can be found at:
https://bazelbuild.github.io/rules_rust/#setup

#### What's Changed

- Bzlmod-aware runfiles library by
[@&#8203;dzbarsky](https://togithub.com/dzbarsky) in
[https://github.com/bazelbuild/rules_rust/pull/2566](https://togithub.com/bazelbuild/rules_rust/pull/2566)
- Add clippy_flag flag to allow flags to be added in succession. by
[@&#8203;granaghan](https://togithub.com/granaghan) in
[https://github.com/bazelbuild/rules_rust/pull/2625](https://togithub.com/bazelbuild/rules_rust/pull/2625)
- Add aspect_rules_js to MODULE.bazel by
[@&#8203;dzbarsky](https://togithub.com/dzbarsky) in
[https://github.com/bazelbuild/rules_rust/pull/2618](https://togithub.com/bazelbuild/rules_rust/pull/2618)
- Register a default rust toolchain. by
[@&#8203;matts1](https://togithub.com/matts1) in
[https://github.com/bazelbuild/rules_rust/pull/2624](https://togithub.com/bazelbuild/rules_rust/pull/2624)
- Nit: Fix link to example in rust_bindgen.md by
[@&#8203;hauserx](https://togithub.com/hauserx) in
[https://github.com/bazelbuild/rules_rust/pull/2628](https://togithub.com/bazelbuild/rules_rust/pull/2628)
- Add context to error messages by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[https://github.com/bazelbuild/rules_rust/pull/2408](https://togithub.com/bazelbuild/rules_rust/pull/2408)
- Update `cargo_bootstrap_repository` interface to match dependency
macros by [@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[https://github.com/bazelbuild/rules_rust/pull/2630](https://togithub.com/bazelbuild/rules_rust/pull/2630)
- Added debug logging for spliced manifests to crate_universe by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[https://github.com/bazelbuild/rules_rust/pull/2629](https://togithub.com/bazelbuild/rules_rust/pull/2629)
- also rewrite -isystem in addition to -sysroot by
[@&#8203;adrianimboden](https://togithub.com/adrianimboden) in
[https://github.com/bazelbuild/rules_rust/pull/2631](https://togithub.com/bazelbuild/rules_rust/pull/2631)
- Support loading http credentials from netrc by
[@&#8203;golovasteek](https://togithub.com/golovasteek) in
[https://github.com/bazelbuild/rules_rust/pull/2623](https://togithub.com/bazelbuild/rules_rust/pull/2623)
- Updated Buildifier version for crate_universe by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[https://github.com/bazelbuild/rules_rust/pull/2634](https://togithub.com/bazelbuild/rules_rust/pull/2634)
- Follow-up documentation/fixes to lockfile API by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[https://github.com/bazelbuild/rules_rust/pull/2637](https://togithub.com/bazelbuild/rules_rust/pull/2637)
- Add docs and examples of complicated build scripts by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[https://github.com/bazelbuild/rules_rust/pull/2635](https://togithub.com/bazelbuild/rules_rust/pull/2635)
- Added Rust 1.78.0 by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[https://github.com/bazelbuild/rules_rust/pull/2639](https://togithub.com/bazelbuild/rules_rust/pull/2639)
- Remove `incompatible_test_attr_crate_and_srcs_mutually_exclusive` by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[https://github.com/bazelbuild/rules_rust/pull/2641](https://togithub.com/bazelbuild/rules_rust/pull/2641)
- Minor cleanup for crate_universe by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[https://github.com/bazelbuild/rules_rust/pull/2644](https://togithub.com/bazelbuild/rules_rust/pull/2644)
- Use `cargo tree` to determine feature dependent optional deps by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[https://github.com/bazelbuild/rules_rust/pull/2636](https://togithub.com/bazelbuild/rules_rust/pull/2636)
- Release 0.43.0 by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[https://github.com/bazelbuild/rules_rust/pull/2642](https://togithub.com/bazelbuild/rules_rust/pull/2642)
- Update cross to fix crate_universe builds in releases by
[@&#8203;UebelAndre](https://togithub.com/UebelAndre) in
[https://github.com/bazelbuild/rules_rust/pull/2645](https://togithub.com/bazelbuild/rules_rust/pull/2645)

#### New Contributors

- [@&#8203;hauserx](https://togithub.com/hauserx) made their first
contribution in
[https://github.com/bazelbuild/rules_rust/pull/2628](https://togithub.com/bazelbuild/rules_rust/pull/2628)
- [@&#8203;adrianimboden](https://togithub.com/adrianimboden) made their
first contribution in
[https://github.com/bazelbuild/rules_rust/pull/2631](https://togithub.com/bazelbuild/rules_rust/pull/2631)
- [@&#8203;golovasteek](https://togithub.com/golovasteek) made their
first contribution in
[https://github.com/bazelbuild/rules_rust/pull/2623](https://togithub.com/bazelbuild/rules_rust/pull/2623)

**Full Changelog**:
bazelbuild/rules_rust@0.42.1...0.43.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/bazel-contrib/toolchains_llvm).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNTEuMiIsInVwZGF0ZWRJblZlciI6IjM3LjM1MS4yIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants