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

Depend on a copy of rustfmt for the target #2685

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

EdSchouten
Copy link
Contributor

The toolchain_files() and current_rust_toolchain() rules return files for the current 'exec' platform. This is perfecly reasonable if you want to use these tools as part of ctx.actions.run(). But if you want to use these as part of 'data = []' (runfiles), they must be built for the target.

Fixes: #2684

These rules don't use this target as if it were a toolchain. Only as a
data argument.
@EdSchouten EdSchouten force-pushed the eschouten/20240607-rustfmt branch 3 times, most recently from 16c8856 to a4397db Compare June 7, 2024 14:30
The toolchain_files() and current_rust_toolchain() rules return files
for the current 'exec' platform. This is perfecly reasonable if you want
to use these tools as part of ctx.actions.run(). But if you want to use
these as part of 'data = []' (runfiles), they must be built for the
target.

This change adds a helper rule, toolchain_files_for_target(), which can
take the aforementioned rules as an input, transitioning it so that it
yields files for the target platform. I'm not happy with how this rule
is implemented, but there is little we can do about that until
bazelbuild/bazel#19645 is addressed.
Copy link
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.

Thanks!

transition_to_target feels like it should maybe be built in to Bazel itself? @katre any idea where would be a good place for this transition to live for real?

(Happy to host a fork of it here in the mean time!)

@illicitonion illicitonion added this pull request to the merge queue Jun 7, 2024
Merged via the queue into bazelbuild:main with commit 837b7f8 Jun 7, 2024
3 checks passed
@katre
Copy link
Member

katre commented Jun 7, 2024

@illicitonion I just read over the code, and I have a lot of questions about transition_to_target. It's a transition that sets the current target platform as an execution platform? Which makes the :current_rustfmt_toolchain dependency analyze with the toolchain (which is the rustfmt toolchain) as if the execution platform were the target platform of the actual transition_to_target?

I kind of feel like this is a lot of indirection: how many rustfmt toolchain implementations are there?

I'm happy to continue this discussion: if we made this a standard transition, it would belong in https://github.com/bazelbuild/rules_platform. Can you open a feature request there with a clear problem statement and any background context? Is this related to bazelbuild/bazel#19645? It feels similar but I'm not sure.

@EdSchouten EdSchouten deleted the eschouten/20240607-rustfmt branch June 7, 2024 16:14
@EdSchouten
Copy link
Contributor Author

Hey @katre,

It's a transition that sets the current target platform as an execution platform? Which makes the :current_rustfmt_toolchain dependency analyze with the toolchain (which is the rustfmt toolchain) as if the execution platform were the target platform of the actual transition_to_target?

Exactly!

I kind of feel like this is a lot of indirection: how many rustfmt toolchain implementations are there?

As far as I know, it's equal to the number of Rust toolchains being registered. There could be multiple versions registered, but also for multiple operating systems/hardware architectures.

I'm happy to continue this discussion: if we made this a standard transition, it would belong in https://github.com/bazelbuild/rules_platform. Can you open a feature request there with a clear problem statement and any background context? Is this related to bazelbuild/bazel#19645? It feels similar but I'm not sure.

This is indeed related to bazelbuild/bazel#19645. Note that the approach we just merged uses a transition, but there's absolutely no hard requirement for that. If bazelbuild/bazel#19645 would result in some kind of direct syntax for doing platform transitions, or having a special 'target' exec group or something, that would also be fine. I will file an issue at https://github.com/bazelbuild/rules_platform regardless.

rrbutani referenced this pull request in bazel-contrib/toolchains_llvm Jun 10, 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 | bazel_dep | minor | `0.45.1` -> `0.46.0` |
| [rules_rust](https://togithub.com/bazelbuild/rules_rust) |
http_archive | minor | `0.45.1` -> `0.46.0` |

---

### Release Notes

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

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

[Compare
Source](https://togithub.com/bazelbuild/rules_rust/compare/0.45.1...0.46.0)

##### 0.46.0

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

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

##### What's Changed

- fix: default rustfmt version to supplied rust version by
[@&#8203;mattem](https://togithub.com/mattem) in
[https://github.com/bazelbuild/rules_rust/pull/2660](https://togithub.com/bazelbuild/rules_rust/pull/2660)
- Use repo-mapping-aware runfiles API in rust-analyzer by
[@&#8203;dzbarsky](https://togithub.com/dzbarsky) in
[https://github.com/bazelbuild/rules_rust/pull/2666](https://togithub.com/bazelbuild/rules_rust/pull/2666)
- Fix protobuf generated srcs to include all sources by
[@&#8203;matts1](https://togithub.com/matts1) in
[https://github.com/bazelbuild/rules_rust/pull/2676](https://togithub.com/bazelbuild/rules_rust/pull/2676)
- Fix cargo_build_script executables. by
[@&#8203;matts1](https://togithub.com/matts1) in
[https://github.com/bazelbuild/rules_rust/pull/2675](https://togithub.com/bazelbuild/rules_rust/pull/2675)
- crate_universe: Don't include crate name in build script path. by
[@&#8203;criemen](https://togithub.com/criemen) in
[https://github.com/bazelbuild/rules_rust/pull/2663](https://togithub.com/bazelbuild/rules_rust/pull/2663)
- Ensure dynamic library dependencies end up in the runfiles directory
by [@&#8203;EdSchouten](https://togithub.com/EdSchouten) in
[https://github.com/bazelbuild/rules_rust/pull/2671](https://togithub.com/bazelbuild/rules_rust/pull/2671)
- use bazel_ci_rules bazel_dep instead of http_archive by
[@&#8203;mmorel-35](https://togithub.com/mmorel-35) in
[https://github.com/bazelbuild/rules_rust/pull/2678](https://togithub.com/bazelbuild/rules_rust/pull/2678)
- Ensure that running `bazel build` on a cargo_build_script target
actually runs the build script by
[@&#8203;matts1](https://togithub.com/matts1) in
[https://github.com/bazelbuild/rules_rust/pull/2680](https://togithub.com/bazelbuild/rules_rust/pull/2680)
- Allow overriding crate universe packages to local packages by
[@&#8203;ograff](https://togithub.com/ograff) in
[https://github.com/bazelbuild/rules_rust/pull/2674](https://togithub.com/bazelbuild/rules_rust/pull/2674)
- Depend on a copy of rustfmt for the target by
[@&#8203;EdSchouten](https://togithub.com/EdSchouten) in
[https://github.com/bazelbuild/rules_rust/pull/2685](https://togithub.com/bazelbuild/rules_rust/pull/2685)
- \[Bugfix] Convert metadata keys to screaming snake case instead of
screaming kebab case in `cargo_build_script_runner` by
[@&#8203;Pagten](https://togithub.com/Pagten) in
[https://github.com/bazelbuild/rules_rust/pull/2682](https://togithub.com/bazelbuild/rules_rust/pull/2682)
- Add support for override_target when using bzlmod by
[@&#8203;AmeliasCode](https://togithub.com/AmeliasCode) in
[https://github.com/bazelbuild/rules_rust/pull/2683](https://togithub.com/bazelbuild/rules_rust/pull/2683)
- Release 0.46.0 by
[@&#8203;illicitonion](https://togithub.com/illicitonion) in
[https://github.com/bazelbuild/rules_rust/pull/2686](https://togithub.com/bazelbuild/rules_rust/pull/2686)

##### New Contributors

- [@&#8203;mattem](https://togithub.com/mattem) made their first
contribution in
[https://github.com/bazelbuild/rules_rust/pull/2660](https://togithub.com/bazelbuild/rules_rust/pull/2660)
- [@&#8203;EdSchouten](https://togithub.com/EdSchouten) made their first
contribution in
[https://github.com/bazelbuild/rules_rust/pull/2671](https://togithub.com/bazelbuild/rules_rust/pull/2671)
- [@&#8203;mmorel-35](https://togithub.com/mmorel-35) made their first
contribution in
[https://github.com/bazelbuild/rules_rust/pull/2678](https://togithub.com/bazelbuild/rules_rust/pull/2678)
- [@&#8203;ograff](https://togithub.com/ograff) made their first
contribution in
[https://github.com/bazelbuild/rules_rust/pull/2674](https://togithub.com/bazelbuild/rules_rust/pull/2674)
- [@&#8203;Pagten](https://togithub.com/Pagten) made their first
contribution in
[https://github.com/bazelbuild/rules_rust/pull/2682](https://togithub.com/bazelbuild/rules_rust/pull/2682)

**Full Changelog**:
bazelbuild/rules_rust@0.45.1...0.46.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 these
updates 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:eyJjcmVhdGVkSW5WZXIiOiIzNy4zOTMuMCIsInVwZGF0ZWRJblZlciI6IjM3LjM5My4wIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=-->

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.

@rules_rust//:rustfmt depends on a copy of rustfmt built for the 'exec' platform, not the 'target' platform
3 participants