Upgrade Zig toolchain to 0.15.2 - #259
Conversation
Bumps the pinned Zig SDK from 0.14.0 to 0.15.2 and adapts to the layout
changes in the 0.15 release:
- zig_sdk.bzl: VERSION + all six host SHA256s. Zig >=0.14.1 renamed its
release tarballs to zig-{arch}-{os}-{version} (arch first), so the
download URL and archive strip-prefix now use a {zig_platform} (arch-os)
format var. The SHA256/ext dicts stay keyed by {os}-{arch} to preserve
the public host_platform_sha256 / host_platform_ext override API.
- defs.bzl: build the arch-os slug for the URL/stripPrefix; stage the
renamed lib/tsan -> lib/libtsan tree, and the new lib/c/** tree that
lib/c.zig (the libzigc shim built while linking) imports.
- private/defs.bzl: Zig 0.15 folded the x86_64-linux-gnu libc-include dir
into the shared x86-linux-gnu dir; update the glibc target's include
list to match (verified against `zig cc -v`).
zig-wrapper.zig needs no source changes for 0.15.2.
Verified on darwin-arm64: `bazel test //...`, the macOS-native zig
toolchain config, `zig fmt --check`/`zig test` on the wrapper, buildifier,
and the bzlmod example built against this module all pass.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Request for maintainers: it would be great to cut a tagged release (and BCR entry) after merging this PR, before the Zig 0.16.0 upgrade (#260) lands — so there's a released hermetic_cc_toolchain version pinned to Zig 0.15.x that consumers can adopt without jumping straight from 0.14.0 to 0.16.0. |
Addresses the two workaround-able issues reported when testing the Zig 0.15.2 upgrade at Uber (see uber#247 discussion): 1. Zig 0.15 compiles C/C++ with UBSan instrumentation by default, which surfaces as `ld.lld: error: undefined symbol: __ubsan_handle_*` at link time. The wrapper now passes -fno-sanitize=undefined in cc mode, placed before the caller's args so an explicit -fsanitize=undefined still takes precedence. The dbg/fastbuild features repeat the flag so the intent is visible in the toolchain config. 2. Zig 0.15's linker cannot read thin archives (ziglang/zig#25694): error: unexpected token in LD script: literal: '!<thin>' Build systems like Meson create thin archives for internal static libraries via ar's `T` modifier. Since archives produced by this toolchain are also consumed by it, the wrapper's ar mode now strips the `T` modifier from the operation string and drops `--thin`, so regular archives are created instead. Both are verified against the real 0.15.2 toolchain: default compiles reference __ubsan_* symbols and -fno-sanitize=undefined removes them; `zig ar rcsT` produces a `!<thin>` archive that fails to link with exactly the error above, while the stripped `rcs` archive links fine. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Pushed 610cbf9, addressing points (1) and (2) from @linzhp's report on the earlier 0.15.2 attempt (#247 (comment)): 1. UBSan-by-default — Zig 0.15 compiles C/C++ with UBSan instrumentation by default (
Verified against the real 0.15.2 toolchain: a default compile of a file using 2. Thin archives (ziglang/zig#25694) — reproduced exactly: Point (3) (#203 / #249) is not addressed here. 🤖 Generated with Claude Code |
Two sh_tests around the ar wrapper's thin-archive handling: - ar_thin_request_test: asking the toolchain's ar wrapper for a thin archive (`rcsT`) must produce a regular `!<arch>` archive that links. - thin_archive_canary_test: a genuinely thin archive created by raw `zig ar` (bypassing the wrapper) must still FAIL to link with the ziglang/zig#25694 error. This is a canary: when a Zig upgrade fixes the upstream bug, this test starts failing, signalling that the expectation should be flipped and stripThinArchiveFlags removed from the wrapper. The @zig_config repo (which holds the SDK filegroups the tests need as runfiles) is now use_repo'd in MODULE.bazel; the toolchains extension is a dev_dependency there, so consumers are unaffected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Added
The point of the canary: when a future Zig upgrade fixes #25694, this test starts failing — deliberately. That failure is the signal to flip the expectation (thin archives should now link) and delete Plumbing note: the tests need the SDK filegroups as runfiles, so 🤖 Generated with Claude Code |
|
See also: #247 |
the problem is Meson doesn't call the wrapper. It calls Given that the issue is fixed in 0.16 and Can you remove |
|
Thanks for the update wrt the uber-meson situation. |
The wrapper's ar mode stripped thin-archive flags so that regular archives were produced, but the build systems that create thin archives (e.g. Meson) invoke `zig ar` directly and never go through the wrapper, so the workaround never fired for the real use case. The underlying issue (ziglang/zig#25694) is fixed in Zig 0.16, so carry it to the 0.16 upgrade rather than keeping a hack that does not help. Removes stripThinArchiveFlags (plus its parseArgs test case) and the test/ar sh_tests, and reverts the MODULE.bazel zig_config use_repo that those tests required. The -fno-sanitize=undefined UBSan default is kept. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts: # toolchain/zig-wrapper.zig
linzhp
left a comment
There was a problem hiding this comment.
Thanks for the contribution
Bumps the pinned Zig SDK from 0.14.0 → 0.15.2 and adapts to the layout changes in the 0.15 release. Three
.bzlfiles change (~32 lines);zig-wrapper.zigneeds no source changes for 0.15.2.Changes
toolchain/private/zig_sdk.bzl—VERSION+ all six hostSHA256s. Zig ≥0.14.1 renamed its release tarballs tozig-{arch}-{os}-{version}(arch first), so the download URL and archive strip-prefix now use a{zig_platform}(arch-os) format var. The SHA256/ext dicts stay keyed by{os}-{arch}to preserve the publichost_platform_sha256/host_platform_extoverride API.toolchain/defs.bzl— build the arch-os slug for the URL/stripPrefix; stage the renamedlib/tsan→lib/libtsantree, plus the newlib/c/**tree thatlib/c.zig(thelibzigcshim built while linking) imports.toolchain/private/defs.bzl— Zig 0.15 folded thex86_64-linux-gnulibc-include dir into the sharedx86-linux-gnudir; the glibc target's include list is updated to match (verified againstzig cc -v). aarch64 and all musl targets were unchanged.Verification (darwin-arm64)
tools/bazel test //...— passes; same 4-pass/7-platform-skipped result as the 0.14.0 baseline (the wasm and windows cross-links that surfaced thelib/libtsanandlib/cchanges now build).tools/bazel test --config=macos_toolchains --@rules_go//go/config:static --@rules_go//go/config:pure //test/c/...— passes (native Darwin zig toolchain).zig fmt --checkandzig testonzig-wrapper.zigwith the real 0.15.2 compiler — pass.examples/bzlmodbuilt against this module via--override_module—cgo_testpasses.🤖 Generated with Claude Code