Repository navigation
Split rustdoc and clippy out of rust_toolchain - #4354
Conversation
29eba05 to
a34a9f8
Compare
3f9376d to
38dad96
Compare
| doc = "The `cargo-clippy` binary. Can be a direct source or a filegroup containing one item.", | ||
| allow_single_file = True, | ||
| cfg = "exec", | ||
| ), |
There was a problem hiding this comment.
Unlike cargo_toolchain in #4339, which carries explicit version, iso_date, and channel attributes, these new toolchains take only binary labels and resolve rust_toolchain = ctx.toolchains[rust_common.toolchain_type] dynamically. In any Bzlmod workspace where @rules_rust registers @rust_toolchains//:all by default, if a user registers a custom rust_toolchain via --extra_toolchains=//my:rust_toolchain or register_toolchains (even when setting clippy_driver and rust_doc directly on that rust_toolchain), without also registering custom clippy_toolchain and rustdoc_toolchain targets:
//rust:toolchain_typeresolves to//my:rust_toolchain.//rust/clippy:toolchain_typeand//rust/rustdoc:toolchain_typestill resolve to@rust_toolchains's default companion toolchains.- Inside
_clippy_toolchain_impl/_rustdoc_toolchain_impl(assuming matching target/exec constraints),ctx.toolchains[rust_common.toolchain_type]resolves to//my:rust_toolchain, settingrust_sysroot_anchor = rust_toolchain.sysroot_anchorand symlinking@rust_toolchains'sclippy-driver/rustdocbinary into a derived sysroot populated with//my:rust_toolchain'slibrustc_driver-*.soandlibstd. - In
find_clippy/find_rustdoc,clippy_toolchain.rust_sysroot_anchor != rust_toolchain.sysroot_anchorevaluates to False, therust_toolchain.{clippy_driver,rust_doc}fallback is skipped, and the action fails at runtime whenlibrustc_driver-<hash>.sodoes not match.
I'd suggest we bind each generated clippy_toolchain / rustdoc_toolchain in BUILD_for_{clippy,rustdoc}_toolchain directly to its sibling rust_toolchain target, e.g., via an optional rust_toolchain = attr.label(providers = [platform_common.ToolchainInfo]) attribute. That makes rust_sysroot_anchor != rust_toolchain.sysroot_anchor genuinely detect cross-release mismatches—and when rust_toolchain came from a different sysroot and sets deprecated clippy_driver / rust_doc, find_clippy / find_rustdoc can either fail with a clear diagnostic or fall back cleanly.
This comment was marked as duplicate.
This comment was marked as duplicate.
Sorry, something went wrong.
There was a problem hiding this comment.
Implemented this! I ended up adding version info to the new toolchains in addition to rust_tooclhain so folks can choose to rely on toolchain resolution and have the same sanity checks that the toolchains matched are version aligned.
| and run the `rustdoc` it provides. Build scripts do not see it by default; a | ||
| `cargo_build_script` which needs `rustdoc` lists | ||
| `@rules_rust//rust/toolchain:current_rustdoc_toolchain` in `toolchains` and sets | ||
| `RUSTDOC` to `$(RUSTDOC)` in `build_script_env`. |
There was a problem hiding this comment.
We advise users whose cargo_build_script needs RUSTDOC to add @rules_rust//rust/toolchain:current_rustdoc_toolchain. However, _rustdoc_toolchain_alias_impl and _clippy_toolchain_alias_impl do not fall back to find_rustdoc / find_clippy when no companion toolchain is registered, breaking that documented pattern for any workspace still relying on rust_toolchain.rust_doc.
Let's add the find_clippy / find_rustdoc fallback to both alias rules and add tags = ["manual"] on current_clippy_toolchain and current_rustdoc_toolchain similarly to how we did it for cargo.
This is a followup to #4339 and aims to further minimize
rust_toolchainby removing components not strictly required by coreRustcactions by movingrustdocandclippyto their own toolchains.