Skip to content

chore(bazel): upgrade rules_rust to 0.75.0 - #12135

Merged
basvandijk merged 2 commits into
masterfrom
bas/rules-rust-0.75.0
Nov 17, 2026
Merged

basvandijk merged 2 commits into
masterfrom
bas/rules-rust-0.75.0

Conversation

@basvandijk

@basvandijk basvandijk commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Upgrades rules_rust from 0.74.0 to 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#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 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 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 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

Bumps rules_rust from 0.74.0 to 0.75.0, the latest release.

The static-runtime patch's content is unchanged: only its index lines
and hunk positions are regenerated, so it applies to the 0.75.0 release
tarball with zero fuzz and zero offset. 0.75.0 still links the dynamic
C++ runtime into dylib/cdylib crates, and still chooses the runtime in
the same three places the patch routes through `cc_runtime_libs`.

Cargo.Bazel.json.lock is repinned with `./bin/bazel-pin.sh --force`;
only its checksum changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@basvandijk
basvandijk requested a balanced review from Copilot November 17, 2026 13:41
@github-actions github-actions Bot added the chore label Nov 17, 2026
@basvandijk
basvandijk marked this pull request as ready for review November 17, 2026 13:43
@basvandijk
basvandijk requested a review from a team as a code owner November 17, 2026 13:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the rules_rust 0.75.0 upgrade.

No open issues 🎉

What changed in this PR

Upgrades the codebase’s Bazel Rust integration from rules_rust 0.74.0 to 0.75.0 while preserving the existing static-runtime linking patch and crate dependency graph.

Changes:

  • Bumps the rules_rust dependency to 0.75.0.
  • Refreshes patch metadata and hunk positions without changing patch behavior.
  • Updates the Cargo Bazel lockfile checksum after repinning.
File Description
Cargo.Bazel.json.lock Updates the checksum; the crate graph remains unchanged.
bazel/​rust.MODULE.bazel Sets rules_rust to version 0.75.0.
bazel/​rules_rust_static_runtime.patch Refreshes patch metadata to match the new release.

Review effort: Balanced

@pr-creation-bot-dfinity-ic
pr-creation-bot-dfinity-ic Bot requested a review from a team as a code owner November 17, 2026 13:44
Copilot AI balanced review requested due to automatic review settings November 17, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the rules_rust 0.75.0 upgrade.

No open issues 🎉

Review effort: Balanced

@basvandijk
basvandijk added this pull request to the merge queue Nov 17, 2026
Merged via the queue into master with commit 676151a Nov 17, 2026
43 of 44 checks passed
@basvandijk
basvandijk deleted the bas/rules-rust-0.75.0 branch November 17, 2026 15:24
AleDema pushed a commit to AleDema/ic that referenced this pull request Nov 18, 2026
Upgrades `llvm`
([hermetic-llvm](https://github.com/hermeticbuild/hermetic-llvm), our
hermetic C/C++ toolchain) from 0.8.16 to
[0.8.27](https://github.com/hermeticbuild/hermetic-llvm/releases/tag/v0.8.27),
its latest release. This moves the compiler, linker and runtimes from
LLVM 22.1.8 to LLVM 23.1.2.

## Changes

- **`MODULE.bazel`**:
  - `llvm` 0.8.16 → 0.8.27.
- `rules_cc` 0.2.22 → 0.2.28 and `rules_shell` 0.6.1 → 0.10.0. llvm
0.8.27 requires `rules_cc` ≥ 0.2.25 and `rules_shell` ≥ 0.8.0, and the
root module should declare what is actually resolved. These are the same
one-line changes as in dfinity#12156 and dfinity#12152, so whichever of these PRs
lands first, the others still merge cleanly. Those PRs cover the
upstream changes of the two modules.
- `rules_go` stays at 0.62.0. llvm 0.8.27 still requires 0.62.0 (through
a `repo_name = None` edge), so the resolved version stays 0.62.0 and the
comment above the declaration ("pulled in via the llvm module") stays
true. dfinity#12148 bumps `rules_go` and rewrites that comment, and its new
comment stays true with llvm 0.8.27 as well.

`git merge-tree` merges this branch with the branches of dfinity#12156, dfinity#12152
and dfinity#12148, one after the other, without conflicts.
- **`bazel/hermetic_llvm_unwindlib.patch`**: still needed. 0.8.27 still
passes a bare `--unwindlib=none` to every link, and
[hermeticbuild/hermetic-llvm#304](hermeticbuild/hermetic-llvm#304)
is still open. The hunk itself is unchanged. Only its position moves
from line 902 to line 1175, so the patch applies to the 0.8.27 release
with zero offset and zero fuzz (`patch --dry-run -F0`). The TODO now
says to drop the patch once that issue is fixed. Before, it said to drop
it "on the next version bump".
- **`bazel/BUILD.bazel`**: comment only. `@llvm_toolchains` now also
declares `cc_runtimes_<os>` toolchains (see below). The comment now says
that our `//bazel` wrappers mirror only the C/C++ toolchains, and why.

## Module graph

Besides the three bumps above, `bazel mod graph` changes in two ways:

- `apple_support` resolves to 2.9.1 instead of 2.5.2, as required by
rules_cc 0.2.28.
- llvm 0.8.27 adds `libxml2` 2.15.3, `mimalloc` 3.5.3, `windows_support`
0.4.1 and `zlib-ng` 2.3.3.bcr.2. hermetic-llvm uses them to build LLVM
from source and for Windows targets, and none of them is in the
dependency graph of the release artifacts (`bazel cquery
'deps(//ic-os/guestos/envs/prod:bundle-update +
//publish/binaries:bundle)'`). It also depends on `zstd` 1.5.7.bcr.1,
which we already declare.

Resolution prints no new warnings. The only one is the existing
`rules_qemu` `use_repo` warning.

## Upstream changes that touch our setup

- **LLVM 22.1.8 → 23.1.2.** 0.8.19 moved to LLVM 23.1.0
([dfinity#719](hermeticbuild/hermetic-llvm#719)), and
0.8.24 moved to 23.1.2
([dfinity#786](hermeticbuild/hermetic-llvm#786)).
0.8.27 uses the `llvm-23.1.2-3` prebuilts
([dfinity#935](hermeticbuild/hermetic-llvm#935)). Since
0.8.17 the prebuilt compiler follows the `llvm` extension's
`llvm.version`
([dfinity#653](hermeticbuild/hermetic-llvm#653)). We
don't set it, so we get the module's 23.1.2. The runtimes we link
statically (libc++, libc++abi, libunwind and the compiler-rt builtins)
are now built from the 23.1.2 sources. So are the libunwind headers that
`//bazel:libunwind_include` exposes to `//rs/canister_sandbox`.
- **Every Linux ELF now has a build ID**
([dfinity#941](hermeticbuild/hermetic-llvm#941)).
`-Wl,--build-id=sha1` is now a default Linux link flag, so rustc links
get it too. lld computes the ID from the linked output, so it is as
reproducible as the binary itself. This changes what we ship in two
ways:
- `//publish/binaries` and `//rs/ic_os/release` run `objcopy -R
.note.gnu.build-id`, which removes the note but doesn't relink. The 36
bytes the note took stay behind as a gap, and `.dynsym` and the sections
after it keep the addresses the linker gave them behind the note. So the
build ID by itself changes these binaries, on top of the compiler change
(see [Release artifacts](#release-artifacts)).
- GuestOS installs `//rs/ic_os/os_tools/guest_disk`,
`//rs/ic_os/remote_attestation/server`,
`//rs/ic_os/guest_upgrade/client` and `//rs/ic_os/open_rootfs`
(`:client_dev` and `:open_rootfs_dev` in dev images) straight from their
`rust_binary` targets, without `objcopy`. They now ship with a build ID.
HostOS and SetupOS install Rust binaries only from `//rs/ic_os/release`.

This PR keeps upstream's default. Shipping binaries without a build ID
again would take an explicit `--build-id=none` link flag, which is a
separate decision.
- **The runtimes are built with `-ffunction-sections -fdata-sections`**
([dfinity#942](hermeticbuild/hermetic-llvm#942)).
`--gc-sections` can therefore drop unused runtime code from our
statically linked binaries.
- **`cc_library` can produce shared libraries on Linux glibc**
([dfinity#865](hermeticbuild/hermetic-llvm#865)). The
toolchain now enables `supports_dynamic_linker`, which dynamically
linked consumers such as `cc_test` would use. Our builds aren't
affected:
  - We have no non-manual `cc_test`.
  - rules_rust links the static archives.
- Our `rules_foreign_cc` targets only consume static outputs of other
`rules_foreign_cc` targets (libfuse for e2fsprogs).
- **Compile and link actions now get `-resource-dir=`** with
execroot-relative paths
([dfinity#751](hermeticbuild/hermetic-llvm#751),
[dfinity#755](hermeticbuild/hermetic-llvm#755)).
Compile actions previously found the builtin headers through `-Xclang
-internal-isystem`. cc-rs build scripts get these flags through `CFLAGS`
and `LDFLAGS`, where rules_rust 0.75.0 already prefixes `-resource-dir=`
with `${pwd}`.
- **C++ runtimes toolchain on Bazel 9**
([dfinity#764](hermeticbuild/hermetic-llvm#764)).
`@llvm_toolchains` now also declares `cc_runtimes_<os>` toolchains. They
add libc++ as an implicit dependency of every C++ target, so that
targets using Clang header modules import a single compiled libc++
module. We register our `//bazel` wrappers instead of
`@llvm_toolchains//:all`, so these toolchains aren't registered, and
libc++'s headers stay textual as before. The toolchain's module map
still declares those headers, so `layering_check` doesn't need the
runtimes toolchain either.
- **glibc**: a few things stay the same:
  - the `gnu.2.31` constraint that `//:linux-glibc-2.31` pins;
  - the 2.28 default that the comment there mentions;
  - the 5.7.19 kernel headers for glibc 2.31.

The link-time glibc stubs changed
([dfinity#849](hermeticbuild/hermetic-llvm#849),
[dfinity#901](hermeticbuild/hermetic-llvm#901)). The
binaries checked below still need no symbol version newer than
`GLIBC_2.30`.

## Verification

Unless noted, all of this ran in the dev container:

- `bazel mod graph` and `bazel mod explain`: the results are described
above.
- `bazel build //... --nobuild`: all 3387 targets analyze.
- The checks of the CI Linter job all pass: `shfmt-check`, `ruff-check`,
`buf-check`, `DFINITY-capitalization-check`, `do-not-merge-check`,
`buildifier-check`, `gazelle-check` and `buf-breaking-check`. After
`buildifier-fix`, `shfmt-fix`, `ruff-fix` and `gazelle`, `git status`
shows no changes.
- I built these targets:
  - `//rs/replica`
  - `//rs/canister_sandbox`, `:sandbox_launcher` and `:compiler_sandbox`
  - `//rs/ic_os/networking/nss_icos`
  - `//:mke2fs`, `//:fuse2fs` and `//:debugfs` (rules_foreign_cc)
- `//publish/binaries:replica.gz` and
`//publish/binaries:canister_sandbox.gz`
  - `//publish/canisters:bundle`

This rebuilt nearly everything: 7858 of the 10612 actions of the first
build ran locally. None of the links printed a `linker stderr` warning,
so the unwindlib patch still works.
- `readelf -p .comment` on the replica shows `clang version 23.1.2` and
`Linker: LLD 23.1.2`.
- `nss_icos`, our only `rust_shared_library` (see dfinity#12135), links the
static LLVM libunwind:
  - It defines 12 `_Unwind_*` symbols locally and leaves none undefined.
- Its only `NEEDED` entries are glibc's: `libpthread`, `libdl`, `libc`
and `ld-linux-x86-64`.
  - It loads with `dlopen(RTLD_NOW)`.
- glibc floor (`objdump -T`):
- `replica`, `canister_sandbox`, `sandbox_launcher`, `compiler_sandbox`
and `nss_icos` need at most `GLIBC_2.30`.
- So do `ic-recovery` and the six GuestOS targets listed under the build
ID change above.
  - `mke2fs` and `debugfs` need at most `GLIBC_2.25`.
  - `fuse2fs` needs at most `GLIBC_2.28`.
- Build IDs (`readelf -n`, `readelf -SW`):
- Each of the six GuestOS targets has one build ID note, at 0x20031c,
right after `.note.ABI-tag`. `guest_disk`, `remote_attestation/server`,
`guest_upgrade/client` and `open_rootfs` built with master's toolchain
(clang 22.1.8) have none.
- `bazel cquery` shows that the GuestOS prod and dev images use these
targets in the same configuration as a plain `bazel build`.
- Re-linking `guest_disk` with the disk cache and remote cache reads
disabled gives the same build ID and a byte-identical binary.
- `//publish/binaries:replica`, `:canister_sandbox` and `:ic-recovery`
have no build ID note.
- On the host, the repo's `objcopy` command turns the `ic-recovery` that
lld produced (the genrule's input) into the published file byte for
byte, and every remaining section keeps its address.
- `mke2fs` creates an ext4 image, and `debugfs` reads it back.
- `bazel test` passes for:
  - all 60 non-manual `rust_doc_test` targets;
- `//rs/canister_sandbox:backend_lib_test`, whose `backtrace.c` the
cc-rs build script compiles;
  - `//rs/artifact_pool:artifact_pool_test`, which uses LMDB.
- With `--config=fuzzing`,
`//rs/fuzzers/bitcoin:deserialize_bitcoin_transaction` builds. It
contains libFuzzer and the C code of secp256k1. It defines `__asan_init`
exactly once and runs 100 iterations.

### Release artifacts

I didn't run the byte-identity build of the IC-OS images, because a
compiler change rebuilds nearly every action. Instead I compared these
outputs against the unstamped master baseline (c712eb2):

- **Canisters are byte-identical**: all 88 files of
`//publish/canisters:bundle`.
- **The Linux binaries differ**, as expected. `replica.gz` and
`canister_sandbox.gz` from `//publish/binaries` differ for two reasons:
- **The compiler moved from LLVM 22.1.8 to 23.1.2.** Their C code is
compiled by clang 23.1.2, the statically linked runtimes are built from
23.1.2, and lld 23.1.2 links them.
- **The new build ID.** `objcopy` removes the note, but not the gap it
leaves:
- In master's `replica` and `ic-recovery` (their `.gz` match the
baseline), `.dynsym` starts at 0x200320, right after `.note.ABI-tag`.
- In this PR's published `replica`, `canister_sandbox` and
`ic-recovery`, `.dynsym` starts at 0x200340, after the 0x24 bytes the
note took.
- A controlled link on the host isolates this effect: one object linked
by the host's lld 18 with `--build-id=none` and with `--build-id=sha1`
gives two different files after our `objcopy` command. In the second
file, `.dynsym`, `.rodata` and `.text` sit 0x20 bytes later.

The IC-OS images contain these binaries, so they change as well. The
GuestOS images also contain the four binaries above that keep their
build ID.

I didn't verify locally:

- **macOS.** There, the hermetic toolchain only builds wasm32. This PR
also brings apple_support 2.9.1 through rules_cc 0.2.28.
- **arm64 Linux.**
- **System tests and the full test suite.**

The `Bazel Test arm64-*` CI jobs cover macOS and arm64 Linux, and CI
runs the full build and test suite.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants