Skip to content

Resolve the C++ toolchain through rules_cc - #4347

Merged
UebelAndre merged 1 commit into
bazelbuild:mainfrom
UebelAndre:rules_cc
Oct 26, 2026
Merged

UebelAndre merged 1 commit into
bazelbuild:mainfrom
UebelAndre:rules_cc

Conversation

@UebelAndre

Copy link
Copy Markdown
Collaborator

Rules which consult a C++ toolchain declared the type as @bazel_tools//tools/cpp:toolchain_type while looking it up through rules_cc's find_cc_toolchain. Declare it through rules_cc too: rule definitions take use_cc_toolchain() from
@rules_cc//cc:find_cc_toolchain.bzl, so the type they require is whatever rules_cc resolves, and plain label sites (test and example toolchain() declarations, string toolchains lists) name @rules_cc//cc:toolchain_type.

Rules which consult a C++ toolchain declared the type as
`@bazel_tools//tools/cpp:toolchain_type` while looking it up through
rules_cc's `find_cc_toolchain`. Declare it through rules_cc too:
rule definitions take `use_cc_toolchain()` from
`@rules_cc//cc:find_cc_toolchain.bzl`, so the type they require is
whatever rules_cc resolves, and plain label sites (test and example
`toolchain()` declarations, string `toolchains` lists) name
`@rules_cc//cc:toolchain_type`.
@UebelAndre
UebelAndre added this pull request to the merge queue Oct 25, 2026
Merged via the queue into bazelbuild:main with commit 51f45f7 Oct 26, 2026
3 checks passed
AleDema pushed a commit to AleDema/ic that referenced this pull request Nov 18, 2026
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 <[email protected]>
Co-authored-by: IDX GitHub Automation <[email protected]>
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