Skip to content

chore(bazel): upgrade rules_go from 0.62.0 to 0.65.0 - #12148

Merged
basvandijk merged 2 commits into
masterfrom
bas/rules-go-0.65.0
Nov 18, 2026
Merged

basvandijk merged 2 commits into
masterfrom
bas/rules-go-0.65.0

Conversation

@basvandijk

@basvandijk basvandijk commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Upgrades rules_go from 0.62.0 to 0.65.0, its latest release.

The repository has no Go sources and no go_* targets of its own. rules_go builds //:gazelle (which //pre-commit:gazelle-check and the Linter job's autofix run) and //:gazelle-update-repos, and provides the go tool behind //:gobin. bazel query 'rdeps(//..., @rules_go//:go_context_data)' lists only those targets in the main repository.

Changes

  • MODULE.bazel: version bump, and a rewritten comment above it. The old comment said that 0.62.0 matched the resolved graph because the llvm module pulled it in. The llvm module (0.8.16, and also the latest 0.8.27) declares bazel_dep(name = "rules_go", version = "0.62.0", repo_name = None), so it only sets a minimum version. gazelle 0.51.3 requires 0.59.0 and rules_buf 0.5.2 requires 0.42.0. The root module's 0.65.0 is now the highest requirement, so it's the version that resolution selects. BCR's rules_go/0.65.0 has only the usual module_dot_bazel_version.patch, and we carry no patch or override for rules_go.

In the module graph, only rules_go's version changes. It also gains an edge to package_metadata: 0.65.0 requires 0.0.5, which already resolves to 0.0.7. On a fresh Bazel server the warnings are the same as on master (only the existing rules_qemu use_repo one). That includes gazelle's go_deps extension, which prints no warnings.

What changes for us

  • Default Go SDK 1.25.0 → 1.26.7. We don't declare a go_sdk, and no other module in our graph does outside its dev dependencies. bazel mod show_extension @rules_go//go:extensions.bzl%go_sdk shows only rules_go's own go_sdk.from_file(name = "go_default_sdk", go_mod = "//:go.mod"); gazelle only imports go_host_compatible_sdk_label. That SDK's version comes from the toolchain line of rules_go's own go.mod, which bazel-contrib/rules_go#4697 bumped from go1.25.0 to go1.26.7 (released in 0.64.0). So Gazelle is now compiled with Go 1.26.7, and bazel run //:gobin -- version prints go1.26.7 instead of go1.25.0.

  • Go modules in the Gazelle build. gazelle's go_deps extension resolves the Go modules that all Bazel modules' go.mod files require, and the highest version wins. rules_go's go.mod now raises the following (from bazel mod show_repo, master → this PR):

    • compiled into Gazelle: golang.org/x/mod v0.25.0 → v0.41.0, golang.org/x/sync v0.15.0 → v0.23.0 and golang.org/x/sys v0.33.0 → v0.48.0.
    • golang.org/x/tools v0.34.0 → v0.51.0 (#4701, #4740). Its goyacc generates the BUILD-file parser of buildtools during the Gazelle build.

    Gazelle's other dependencies (buildtools, doublestar, go-difflib, x/tools/go/vcs) don't change. rules_go's go.mod requires none of the Go modules that our go.mod requires directly.

Upstream changes that touch our setup

  • #4762 raises the minimum Bazel version to 7.7.0 (bazel_compatibility). We use 9.3.2.

  • #4761 removes the //go/private:request_nogo setting. We don't configure nogo, and neither gazelle 0.51.3 nor 0.54.0 references that setting. Gazelle 0.51.3's gazelle_binary uses go_context, new_go_info, GoArchive and CGO_ATTRS/CGO_FRAGMENTS/CGO_TOOLCHAINS, which all still exist. Gazelle 0.54.0 (chore(bazel): upgrade gazelle from 0.51.3 to 0.54.0 #12149) uses go_binary, GoArchive, go_context and the same CGO_* symbols.

  • cgo, which the hermetic LLVM toolchain compiles:

    • #4671 replaces cgo's default -fdebug-prefix-map flags with -ffile-prefix-map, which clang supports, so __FILE__ no longer embeds absolute paths. This also covers the cgo part of the standard library build.
    • #4739 also makes -internal-externc-isystem/-stdlib++-isystem header paths absolute. llvm 0.8.16 (and 0.8.27) passes neither and uses -Xclang -internal-isystem, which rules_go already handled.
    • #4667 turns off path mapping for cgo standard library builds. We don't enable path mapping.
  • #4689 and #4704 change how the static, pure and linkmode settings reach Go tool binaries. #4706 applies the static attribute at link time instead of through a transition. We set none of the //go/config flags or those attributes.

  • #4728 changes the build IDs of the Go binaries that rules_go links. 0.62.0 linked them with -buildid=redacted. 0.65.0 links with a placeholder, then overwrites it with a SHA-256 of the linked binary:

    • ELF: the Go build ID, and the GNU build ID if the binary has one.
    • Mach-O: the Go build ID and LC_UUID. If the binary is code-signed (Go's linker signs darwin/arm64 binaries), rules_go's builder then re-signs it ad hoc in Go, without Apple's codesign.

    For us this affects Gazelle, the go tool runner behind //:gobin, and goyacc, which the Gazelle build runs. I checked the first two on Linux and cross-compiled for macOS (see Verification).

Verification (dev container)

  • bazel mod graph, bazel mod explain rules_go/gazelle/package_metadata and bazel mod show_extension/show_repo give the resolution described above, compared with the same commands on master.
  • bazel build //... --nobuild: all 3387 targets analyze.
  • Linter-job parity: shfmt-check, ruff-check, buf-check, DFINITY-capitalization-check, do-not-merge-check, buildifier-check, gazelle-check and buf-breaking-check pass. After them, buildifier-fix, shfmt-fix, ruff-fix and bazel run //:gazelle leave the tree unchanged.
  • //:gazelle, //:gazelle-update-repos and //:gobin build, with Gazelle and the Go standard library rebuilt with Go 1.26.7.
  • With no Go code to test, I exercised rules_go's rules and cgo through the "Hello World" workflow in bazel/README.md. I used a temporary package that isn't committed: a main.go with a C function and os/user, plus a main_test.go.
    • bazel run //:gazelle generated a go_library (cgo = True), a go_binary and a go_test.
    • The binary printed hello world from go1.26.7: 1+2=3, and the test passed.
    • Its build compiled the standard library with CGO_ENABLED=1 and the hermetic clang 22.1.8 as CC.
  • After chore(bazel): upgrade gazelle from 0.51.3 to 0.54.0 #12149 (gazelle 0.54.0) landed, I merged master into this branch. Its gazelle line sits next to this PR's rules_go line; the resolution keeps both. Against master, bazel mod graph changes only rules_go (0.62.0 → 0.65.0) with no new warnings, bazel build //... --nobuild analyzes all 3389 targets, and bazel run //:buildifier changes nothing.
  • Before that, I repeated this with gazelle temporarily bumped to 0.54.0, as in chore(bazel): upgrade gazelle from 0.51.3 to 0.54.0 #12149. It resolves to gazelle 0.54.0 and rules_go 0.65.0 without new warnings, Gazelle builds, gazelle-check leaves the tree clean, and the temporary package builds, runs and passes its test.
  • Release artifacts: I didn't run the byte-identity rebuild. I ran bazel cquery 'deps(...)' over the seven release targets: the IC-OS bundles that ci/container/build-ic.sh --icos builds, //publish/binaries:bundle and //publish/canisters:bundle. None of the 110,935 configured targets it lists references rules_go, gazelle or a Go SDK or toolchain repo. No other module's resolved version changes either, so this upgrade can't change what we ship.
  • Build IDs (#4728), which I read from the binaries with a small Python script:
    • Linux: the Go build IDs of Gazelle and the go tool runner are now content hashes in go build's format (four 20-character chunks), not redacted. The runner's GNU build ID matches its Go build ID. Gazelle's binary has no GNU build ID note, so only its Go build ID is rewritten.
    • macOS, cross-compiled on Linux: I built @gazelle//cmd/gazelle and @rules_go//go/tools/go_bin_runner with --platforms=@rules_go//go/toolchain:darwin_arm64, and again with darwin_amd64. These platforms turn cgo off, so Go's internal linker links the binaries. In all four binaries, the Go build ID and LC_UUID come from the same content hash. The two arm64 binaries have a valid ad hoc signature: every CodeDirectory page hash (2,861 and 945 of them) matches the file. The amd64 binaries have no signature, because Go's linker signs only darwin/arm64 binaries.
  • Not verified on a Mac, either locally or in CI. CI's Bazel Test arm64-darwin job builds three //publish/binaries targets (pocket-ic.gz also for x86_64), //rs/... and //packages/.... Of those, it tests the targets tagged test_all_platforms or test_all_platforms_slow.
    • bazel query 'deps(...)' over these targets follows every select() branch. It lists 79,392 labels, and none comes from rules_go, gazelle, a Go SDK or a Go module repository.
    • Across the whole workspace, a bazel query for main-repository targets that depend on such a label finds only the targets named at the top and their two -runner targets.
    • On a Mac, those targets now build with Go 1.26.7. On Apple silicon, the Go binaries involved (Gazelle, the go tool runner and goyacc) are re-signed after linking, as described above. The cross-compiled binaries don't show that they build and run on a Mac.
    • Before merging, could someone on a Mac run bazel run //:gazelle and bazel run //:gobin -- version on this branch? The second should print go1.26.7.
  • On Linux, CI covers the rest. Because this PR changes MODULE.bazel, CI builds and tests all of //..., not just the affected targets (PR runs still skip long_tests). The Linter job also runs gazelle-check.

🤖 Generated with Claude Code

Bump the rules_go bazel_dep to its latest release and reword the comment
above it: the llvm module still requires rules_go 0.62.0 or later, and the
root module's declaration is what the resolved graph selects.

Only rules_go's resolved version changes in the module graph. Through its
go.mod, rules_go's default Go SDK moves from 1.25.0 to 1.26.7, and the
golang.org/x/{mod,sync,sys} modules compiled into //:gazelle (and the
x/tools goyacc that generates part of it) move to the versions rules_go
0.65.0 requires. rules_go is not in the build graph of the release
artifacts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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 were identified for the rules_go version bump and accompanying comment clarification.

No open issues 🎉

What changed in this PR

Upgrades rules_go from 0.62.0 to 0.65.0 for the repository’s Gazelle tooling and gobin target. The repository has no Go sources or Go targets of its own.

Changes:

  • Bumps the root rules_go dependency to 0.65.0.
  • Rewrites the accompanying comment to clarify LLVM’s minimum-version requirement and dependency resolution.
File Description
MODULE.bazel Updates rules_go and clarifies the version-selection comment.

Review effort: Balanced

@basvandijk
basvandijk requested a balanced review from Copilot November 17, 2026 23:50

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.

🔵 Needs a closer look

Native macOS validation of Gazelle and gobin remains outstanding after the Go SDK and Mach-O signing changes, and cross-compilation and signature checks do not establish that these tools build and run there.

No open issues 🎉

Review effort: Balanced

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.

🔵 Needs a closer look

Native macOS validation of //:gazelle and //:gobin -- version remains outstanding, and cross-compilation cannot confirm that the upgraded Go SDK and re-signed binaries execute successfully on macOS.

No open issues 🎉

Review effort: Balanced

@basvandijk
basvandijk marked this pull request as ready for review November 18, 2026 08:11
@basvandijk
basvandijk requested a review from a team as a code owner November 18, 2026 08:11
master now has #12149 (gazelle 0.51.3 -> 0.54.0), which changed the gazelle
line next to this PR's rules_go line. The resolution keeps both: rules_go
0.65.0 with this PR's comment, and gazelle 0.54.0 from master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 10:46

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.

🔵 Needs a closer look

Native macOS execution remains unverified for the Go SDK upgrade’s Mach-O build-ID and ad-hoc signing changes, requiring a Mac maintainer to run //:gazelle and //:gobin -- version before merge.

No open issues 🎉

Review effort: Balanced

@basvandijk
basvandijk added this pull request to the merge queue Nov 18, 2026
Merged via the queue into master with commit 540daf3 Nov 18, 2026
42 checks passed
@basvandijk
basvandijk deleted the bas/rules-go-0.65.0 branch November 18, 2026 12:24
AleDema pushed a commit to AleDema/ic that referenced this pull request Nov 18, 2026
Upgrades `gazelle` from 0.51.3 to
[0.54.0](https://github.com/bazel-contrib/bazel-gazelle/releases/tag/v0.54.0),
its latest release. The BCR's `1.0.0-beta.1` and `2.0.0-beta.*` are
pre-releases.

The repository has no Go sources. We use gazelle in two places:

- `//:gazelle`, which CI's Linter job runs as
`//pre-commit:gazelle-check` and again as an autofix. This PR moves its
definition to `//bazel/gazelle` and keeps `//:gazelle` as an alias (see
Changes).
- The `go_deps` extension, which creates the `go.mod` repos
(`@com_github_fatih_color`, ...). It also writes the config that
`@rules_go//go` (our `//:gobin`) reads.

Nothing gazelle builds ends up in what we ship.

## Changes

- **`MODULE.bazel`**: version bump. The [BCR
entry](https://bcr.bazel.build/modules/gazelle/0.54.0/MODULE.bazel) of
0.54.0 adds two dependencies. One is `platforms` 1.1.0, which we already
resolve; the other, `rules_testing`, is dev-only. Its only BCR patch
sets the module version. gazelle is also required by `rules_go` 0.62.0
(0.51.3) and `rules_buf` 0.5.2 (0.34.0), so the root module's
requirement decides the version. No other module's resolved version
changes.
- **`BUILD.bazel` and the new `bazel/gazelle/BUILD.bazel`**: the
`gazelle` and `gazelle-update-repos` targets move from the root package
to `//bazel/gazelle`. With 0.54.0, loading `@gazelle//:def.bzl` fetches
the Go SDK, and every build on Linux loads the root package (see the
`go_deps` item below). The root package keeps `//:gazelle` and
`//:gazelle-update-repos` as aliases, so `bazel run //:gazelle`,
`//pre-commit:gazelle-check`, CI's Autofix step and `bazel/README.md`
work unchanged. It also keeps the `# gazelle:prefix` and `#
gazelle:proto disable` directives, which apply to the whole repository.
Gazelle takes its working directory from `BUILD_WORKSPACE_DIRECTORY`, so
the package that defines the target doesn't change what it processes.

dfinity#12151 (rules_buf 0.6.1, which requires gazelle 0.54.0) is stacked on
this PR. dfinity#12148 (rules_go 0.65.0) rewrites the comment and the
`rules_go` line right above the gazelle `bazel_dep` in `MODULE.bazel`,
so git reports a merge conflict between the two: whichever lands second
needs master merged in, keeping both new lines.

## Upstream changes that touch our setup

- **The Gazelle binary is now a plain `go_binary`**
([bazel-contrib/bazel-gazelle#2386](bazel-contrib/bazel-gazelle#2386)).
Its update command now drives the built-in (v1) language extensions
through v2 compatibility wrappers
([dfinity#2423](bazel-contrib/bazel-gazelle#2423)), and
the directory walk moved to the v2 packages
([dfinity#2330](bazel-contrib/bazel-gazelle#2330)).
CI's `gazelle-check` and Autofix steps run this binary. With 0.54.0,
`bazel run //:gazelle` builds and leaves the tree unchanged, as it did
with 0.51.3, so the upgrade causes no Autofix commit.
- **`go_deps` now computes the Go environment itself**
([dfinity#2392](bazel-contrib/bazel-gazelle#2392)), and
records `GOROOT` as a label
([dfinity#2374](bazel-contrib/bazel-gazelle#2374),
[dfinity#2385](bazel-contrib/bazel-gazelle#2385)). This
has two effects for us:
- The `go_env.bzl` and `config.json` of
`@bazel_gazelle_go_repository_config` used to hold an empty environment.
They now hold `GOROOT = "@@rules_go++go_sdk+go_default_sdk//:ROOT"` and
`GOTOOLCHAIN = "local"`. Both places where we use them replace that
`GOROOT` with the SDK's path. The `//:gazelle` runner script does it in
its `set_goroot`. rules_go's `go_bin_runner`, behind `//:gobin`, appends
`GOROOT=<sdk path>` after the config values. `bazel run //:gobin -- env
GOROOT GOTOOLCHAIN GOMOD` prints the SDK path, `local` and our `go.mod`.
- Evaluating `go_deps` now fetches rules_go's Go SDK: go1.25.0, a 57 MiB
archive that takes 242 MiB on disk once extracted. Its `compute_env`
resolves the SDK's `ROOT` file, and `go_deps.bzl` now loads
`@bazel_gazelle_go_repository_cache//:def.bzl`. `@gazelle//:def.bzl`
loads the `go_env.bzl` that `go_deps` generates, so loading `def.bzl`
evaluates `go_deps`. The root `BUILD.bazel` loaded it, and on Linux
every `bazel build`, `test`, `run`, `cquery` and `aquery` loads the root
package, because `bazel/conf/.bazelrc.build` points `--platforms` and
`--host_platform` at `//:linux-glibc-2.31`. So with the version bump
alone (the first commit), every build on Linux fetched the SDK, also for
targets without Go, which don't fetch it with 0.51.3. On a cold cache,
that means downloading and extracting it. That's why this PR moves the
gazelle targets out of the root package; the measurements are under
Verification. Builds that include the gazelle targets or `//:gobin`,
such as `//...`, still fetch the SDK, as they did with 0.51.3.
- **`go_repository` moves its generated package metadata targets to a
`_gazelle_generated` package**
([dfinity#2407](bazel-contrib/bazel-gazelle#2407)).
Their PURLs now include the `go.sum` checksum
([dfinity#2409](bazel-contrib/bazel-gazelle#2409)). For
our five `go_deps` repos, this is the only difference in the generated
`BUILD.bazel` and `REPO.bazel` files (compared file by file), and the
generated Go rules are identical. Nothing in this repository reads that
metadata.
- **Module downloads**: `fetch_repo` now checks module sums against the
JSON output of `go mod download`
([dfinity#2366](bazel-contrib/bazel-gazelle#2366)). All
our `go_deps` repos fetch, and their sums verify.
- `rules_buf` 0.5.2 imports `bazel_gazelle_go_repository_tools` from
gazelle's internal `non_module_deps` extension. 0.54.0 still provides
that repo under the same name. We only use rules_buf's prebuilt `buf`,
and `buf-check` and `buf-breaking-check` pass.

## Verification

All of the following except the CI results ran in the dev container. The
module graph, `go_deps` repos and `//:gobin` checks ran on the first
commit; the second commit doesn't change `MODULE.bazel` or anything
those checks use. The other checks ran on the final state.

- **Module graph**: `bazel mod explain gazelle` shows 0.54.0, required
by the root module, `rules_go` 0.62.0 and `rules_buf` 0.5.2. Compared
with the base commit, the full `bazel mod graph` differs only in
gazelle's version and its new `platforms` edge. There are no new
warnings; the only one is the existing `rules_qemu` `use_repo` warning.
- **Analysis**: `bazel build //... --nobuild` analyzes all 3389 targets.
That's 2 more than on the first commit (3387): the `//...` pattern
matches the new aliases `//:gazelle` and `//:gazelle-update-repos`,
while the `gazelle` macro tags the `sh_binary` targets it creates
`manual`.
- **Linter job**:
`//pre-commit:{shfmt-check,ruff-check,buf-check,DFINITY-capitalization-check,do-not-merge-check,buildifier-check,gazelle-check,buf-breaking-check}`
all pass. The autofixes (`buildifier-fix`, `shfmt-fix`, `ruff-fix` and
`bazel run //:gazelle`) leave `git status` clean.
- **Gazelle**: `bazel run //:gazelle` (through the alias), `bazel run
//bazel/gazelle` and `bazel run //:gazelle -- -mode=diff` exit 0 and
change no files. `bazel run //:gazelle-update-repos`, which
`bazel/README.md` documents, fails with `loading WORKSPACE file: ... no
such file or directory`, as it does with 0.51.3 at the base commit. The
repository has no `WORKSPACE` file.
- **Repos fetched by builds without Go**: `bazel build --nobuild` of two
targets, each in a fresh output base, then the repos under `external/`:

  | | `//.github:CODEOWNERS` | `//rs/types/base_types:base_types` |
  |---|---|---|
  | Base commit (0.51.3) | 27 repos, no Go SDK | 304 repos, no Go SDK |
| First commit (0.54.0, gazelle targets in the root package) | 29: adds
`rules_go++go_sdk+go_default_sdk` and
`gazelle++non_module_deps+bazel_gazelle_go_repository_cache` | 306: adds
the same two |
| This PR (0.54.0, gazelle targets in `//bazel/gazelle`) | 19: none from
gazelle, rules_go or rules_buf | 300: no Go SDK and no gazelle repos;
the Go-related ones left (`rules_go+`, `go_toolchains`,
`io_bazel_rules_nogo`) are in the base commit's list too |

- **`go_deps` repos**: I ran `bazel test --keep_going` over `//...` of
the five repos we import (`@com_github_fatih_color`,
`@com_github_google_go_cmp`, `@com_github_schollz_closestmatch`,
`@com_github_spf13_cobra`, `@com_github_stretchr_testify`). I ran it
with 0.54.0 first, then with 0.51.3, in the same output base.
  - 10 of the 14 tests pass with both versions.
- The other four fail the same way with both versions, for reasons
unrelated to gazelle. For example, `closestmatch` reads
`test/books.list`, which the generated `go_test` doesn't list as data,
and testify's `suite` test runs `go` from the `PATH`.
- `@com_github_spf13_cobra//doc` doesn't analyze with either version,
because our `go.mod` doesn't include `go-md2man`.
- In the 0.51.3 run, every compile and link action and the 10 passing
tests were cache hits from the 0.54.0 run. So the Go rules that gazelle
generates produce identical actions.
- **`//:gobin`**: `version`, `env` and `mod verify` work ("all modules
verified").
- **Release artifacts**: I didn't run the byte-identity build, because
gazelle isn't in the release artifacts' build graph. I ran `bazel cquery
'deps(...)'` over the GuestOS (prod disk and update, recovery update),
HostOS and SetupOS bundles plus `//publish/binaries:bundle` and
`//publish/canisters:bundle`. Of its 110,935 labels, none comes from
gazelle, its repos, rules_go or the Go SDK. On the final state,
intersected with the root package and `//bazel/gazelle`, the same query
returns only `//:linux-glibc-2.31`, `//:mainnet-routing-table.json`,
`//:mke2fs`, `//:debugfs`, `//:e2fsdroid` and `//:ovmfsev_code`, none of
which this PR changes.
- **CI on the first commit** passed, including the darwin job. Its
`Build pocket-ic-server x86_64-darwin` step builds with
`--platforms=//:macos-intel`, a platform in the root package, so that
run evaluated 0.54.0's `go_deps` on macOS. The job log doesn't list
repository fetches, so it doesn't show the SDK download itself. With the
gazelle targets moved, builds on macOS that don't involve them no longer
evaluate `go_deps`.
- **Not verified**: running `//:gazelle` on macOS. CI covers the full
build and tests.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

3 participants