Repository navigation
Add a Cargo toolchain - #4339
Conversation
0df47a9 to
36cc32c
Compare
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| cargo_toolchain_alias( |
There was a problem hiding this comment.
This breaks bazel build @rules_rust//cargo/... when no cargo_toolchain is registered. Let's:
- add
tags = ["manual"](matchingcurrent_rust_analyzer_toolchain), and - (maybe?) have
_cargo_toolchain_alias_implfall back torust_toolchain.cargo(temporarily, until fully removed).
| load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") | ||
| load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES") | ||
| load("@rules_cc//cc/common:cc_common.bzl", "cc_common") | ||
| load("//cargo:cargo_toolchain.bzl", "cargo_version_mismatch", "find_cargo") |
There was a problem hiding this comment.
nit: load these from //cargo/private instead.
(internally we have some bzl_lib consistency checks that are unfortunately not available upstream, and this avoids a potential //cargo:bzl_lib -> //cargo/private:bzl_lib -> //cargo:bzl_lib cycle)
(this currently is not flagged upstream because the deps of bzl_libs are not accurate and there is no enforcement mechanism available)
|
|
||
| def _crates_vendor_impl(ctx): | ||
| toolchain = ctx.toolchains[Label("@rules_rust//rust:toolchain_type")] | ||
| cargo = find_cargo(ctx, toolchain) |
There was a problem hiding this comment.
- This could be
None(and then thecargo.cargobelow will fail with unclear error message). - Consider adding a
cargo_version_mismatchcheck.
| @@ -1,9 +1,20 @@ | |||
| load("@bazel_skylib//:bzl_library.bzl", "bzl_library") | |||
There was a problem hiding this comment.
(not for this BUILD file but I can't figure out how to leave a comment for a file outside the PR without submitting a partial review, so bear with me...)
rules_rust//rust/toolchain:current_cargo_files still uses toolchain_files(tool = "cargo") (reading the deprecated rust_toolchain.cargo), and internal clients still depend on it. Consider aliasing/deprecating current_cargo_files to //cargo:current_cargo_toolchain (just as current_rustfmt_files was aliased).
There was a problem hiding this comment.
@rules_rust//rust/toolchain:current_cargo_files is now a deprecated alias
| "exec_compatible_with": tc_exec_compatible_with, | ||
| "name": companion_name, | ||
| "target_compatible_with": tc_target_compatible_with, | ||
| "target_settings": target_settings, |
There was a problem hiding this comment.
(this is pre-existing also at new line 1212 above, but pointing it out as I noticed possible inconsistency): this drops channel_target_settings from all_toolchain_details, possibly might be better to update both to "target_settings": channel_target_settings + target_settings.
There was a problem hiding this comment.
It's preexisting but I fixed it here
There was a problem hiding this comment.
This ended up being the source of a bug so I'll defer to another change.
| // The deprecated `rust_toolchain.cargo` is a symlink inside the | ||
| // generated sysroot, under a `rust_toolchain/` directory. | ||
| assert!( | ||
| !cargo.contains("/rust_toolchain/"), |
There was a problem hiding this comment.
nit
!cargo.replace('\\', "/").contains("/rust_toolchain/") for Windows path compatibility.
| @@ -0,0 +1,22 @@ | |||
| load("//cargo:defs.bzl", "cargo_build_script") | |||
There was a problem hiding this comment.
consider placing this test package under cargo/tests/cargo_build_script/cargo_toolchain along with other pre-existing cargo tests.
This is a followup to bazelbuild#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.
Upgrades `rules_rust` from 0.74.0 to [0.75.0](https://github.com/bazelbuild/rules_rust/releases/tag/0.75.0), the latest release. ## Changes - **`bazel/rust.MODULE.bazel`**: version bump. BCR's `rules_rust/0.75.0` has no patches of its own, and `rules_rust` is still depended on only by the root module (`bazel mod explain rules_rust`). - **`bazel/rules_rust_static_runtime.patch`**: content unchanged. Only the `index` lines and hunk positions are regenerated, so the patch applies to the 0.75.0 release tarball with zero fuzz and zero offset (the old one applied with offsets of up to 102 lines). The patch is still needed, because 0.75.0 still links the *dynamic* C++ runtime into dylib/cdylib crates. It also still chooses the runtime in exactly the three places the patch routes through `cc_runtime_libs` (`collect_inputs`, `_add_native_link_flags`, and rustdoc's doc-test link flags). Unlike the last bump, no new selection site appeared that the patch would miss. - **`Cargo.Bazel.json.lock`**: repinned with `./bin/bazel-pin.sh --force`. Only the `checksum` changes, since it covers the `cargo-bazel` version. The generated crate graph is identical. - **Four Rust files, via the Autofix commit**: whitespace-only, see below. ## Formatting changes from the Autofix commit We don't set `rustfmt_version`, so `bazel run :rustfmt`, which CI's Autofix job runs, uses rules_rust's default nightly rustfmt. 0.75.0 moves that from `nightly/2026-08-20` to `nightly/2026-10-15` (rustfmt 1.11.0-nightly). The newer nightly indents `*` continuation lines that start at column 0 in block comments by one space, aligning them under the `*` of `/*`. Autofix applied that to four files in 82449b5, and all 50 changed lines differ only by that one space. Without this commit, every later PR would get the same Autofix commit. Stable `cargo fmt -- --check` (rustfmt 1.10.0-stable, which `ci/scripts/rust-lint.sh` runs) passes on the result, so the two formatters still agree. ## Upstream changes that touch our setup - **The rustc 1.99.1 toolchain downloads are now checksum-verified.** 0.74.0's built-in `known_shas.bzl` has no 1.99.x entries and we pass no `sha256s` to `rust.toolchain`, so those archives were fetched with an empty `sha256`. 0.75.0 ships their checksums ([bazelbuild/rules_rust#4311](bazelbuild/rules_rust#4311)). - [bazelbuild/rules_rust#4347](bazelbuild/rules_rust#4347) declares the C++ toolchain type through rules_cc's `use_cc_toolchain()`. With our rules_cc 0.2.22 that is `@bazel_tools//tools/cpp:toolchain_type`, the same type the hermetic-llvm wrapper toolchains in `//bazel` register under. This needed checking because rules_rust requests that type with `mandatory = False`, so a mismatch would silently resolve no C++ toolchain instead of failing. - [bazelbuild/rules_rust#4339](bazelbuild/rules_rust#4339) adds a `cargo_toolchain`, and `cargo_build_script` now fails when the Cargo and Rust toolchains come from different releases. The `rust` extension registers a matching `cargo_toolchain` next to every `rust_toolchain`, and we register only 1.99.1, so the two can't disagree. - [bazelbuild/rules_rust#4271](bazelbuild/rules_rust#4271) changes how legacy doc tests map paths into runfiles: the writer now strips the root of every action input. That replaces the explicit runtime-lib handling our hermetic-llvm doc-test links relied on. The runtime libs still reach those inputs through the patched `collect_inputs`, so they stay covered. - [bazelbuild/rules_rust#4326](bazelbuild/rules_rust#4326) drops `-lresolv` from the default macOS link flags. No first-party code calls resolver functions; the macOS CI jobs cover third-party crates. ## Verification - `bazel build //... --nobuild`: all 3387 targets analyze. - `//rs/ic_os/networking/nss_icos`, our only `rust_shared_library` and the case the patch exists for, links the static LLVM libunwind. Its `_Unwind_*` symbols are defined locally, and every undefined dynamic symbol is a versioned glibc one. - All 60 non-manual `rust_doc_test` targets pass. - These build: `//rs/replica`, `//rs/orchestrator`, `//rs/pocket_ic_server:pocket-ic-server`, `//rs/canister_sandbox`, the NNS governance and ICRC-1 ledger canisters (wasm), `//:rustfmt` and `//:gen_rust_project`. - CI covers the full build and test suite. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: IDX GitHub Automation <infra+github-automation@dfinity.org>
This change adds a stand-alone toolchain for Cargo. This change aims to help reduce the size of
rust_toolchainby removing components not needed by core@rules_rust//rust/....