Skip to content

Split rustdoc and clippy out of rust_toolchain - #4354

Merged
UebelAndre merged 5 commits into
bazelbuild:mainfrom
UebelAndre:rules_cc
Nov 6, 2026
Merged

UebelAndre merged 5 commits into
bazelbuild:mainfrom
UebelAndre:rules_cc

Conversation

@UebelAndre

Copy link
Copy Markdown
Collaborator

This is a followup to #4339 and aims to further minimize rust_toolchain by removing components not strictly required by core Rustc actions by moving rustdoc and clippy to their own toolchains.

@UebelAndre
UebelAndre force-pushed the rules_cc branch 2 times, most recently from 29eba05 to a34a9f8 Compare October 26, 2026 18:53
@UebelAndre
UebelAndre marked this pull request as draft October 27, 2026 00:13
@UebelAndre
UebelAndre force-pushed the rules_cc branch 9 times, most recently from 3f9376d to 38dad96 Compare October 31, 2026 23:18
@UebelAndre
UebelAndre marked this pull request as ready for review November 1, 2026 22:29
@UebelAndre
UebelAndre requested a review from krasimirgg November 1, 2026 22:29
doc = "The `cargo-clippy` binary. Can be a direct source or a filegroup containing one item.",
allow_single_file = True,
cfg = "exec",
),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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_type resolves to //my:rust_toolchain.
  • //rust/clippy:toolchain_type and //rust/rustdoc:toolchain_type still 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, setting rust_sysroot_anchor = rust_toolchain.sysroot_anchor and symlinking @rust_toolchains's clippy-driver / rustdoc binary into a derived sysroot populated with //my:rust_toolchain's librustc_driver-*.so and libstd.
  • In find_clippy / find_rustdoc, clippy_toolchain.rust_sysroot_anchor != rust_toolchain.sysroot_anchor evaluates to False, the rust_toolchain.{clippy_driver,rust_doc} fallback is skipped, and the action fails at runtime when librustc_driver-<hash>.so does 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done!

@krasimirgg krasimirgg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

@UebelAndre
UebelAndre added this pull request to the merge queue Nov 6, 2026
Merged via the queue into bazelbuild:main with commit d08ddac Nov 6, 2026
3 checks passed
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.

3 participants