chore: upgrade to Zig 0.16.0#4
Conversation
- std.ArrayList: .init(alloc) → .empty + explicit allocator on each method - addCSourceFiles moved from Compile to Module (lib.root_module) 🤖 Generated with AI assistance
Zig's bundled clang does not automatically define __APPLE__ when compiling .S assembly files, even on a macOS target. blst's build/assembly.S uses #ifdef __APPLE__ to select the mach-o ARM64 symbol variants; without this define, the #elif __ELF__ branch is taken instead and the mach-o symbols (_mulx_mont_384, _fromx_mont_256, etc.) are never assembled, causing undefined-symbol linker errors on Apple Silicon with Zig 0.16+. 🤖 Generated with AI assistance
addCMacro only passes -D flags to the Zig compiler, not to clang when compiling C/assembly sources via addCSourceFiles. The fix for macOS ARM64 blst assembly must be in c_flags so clang receives the -D__APPLE__=1 flag. 🤖 Generated with AI assistance
std.Target.x86.featureSetHas() called on a non-x86 CpuFeatureSet is undefined behavior — feature enum indices are arch-specific, so x86's .adx (index 13) may map to an unrelated ARM64 feature (balance_fp_ops) that is enabled on Apple Silicon. This incorrectly sets __ADX__, causing server.c to reference ctx_*-prefixed symbols via vect.h macros, while the ARM64 mach-o assembly only defines ct_*-prefixed symbols → undefined symbol linker errors on Apple Silicon. Also remove the spurious -D__APPLE__ c_flag: clang already defines __APPLE__ natively when building for macOS. 🤖 Generated with AI assistance
There was a problem hiding this comment.
Pull request overview
Upgrades the build script and repo ignore patterns to align with Zig 0.16.0-dev build/stdlib API changes as part of the Zig master upgrade effort.
Changes:
- Migrates
std.ArrayListusage to the new.empty/append(allocator, ...)/deinit(allocator)APIs. - Updates C source inclusion to use
lib.root_module.addCSourceFilesand adds a safe arch guard around the__ADX__macro definition. - Ignores
zig-pkg/in.gitignore.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| build.zig | Updates build logic and flags handling for Zig 0.16 API changes; adds an x86_64-only guard for ADX feature probing. |
| .gitignore | Adds zig-pkg/ to ignored build/package artifacts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .fingerprint = 0x97ffb139ce317072, // Changing this has security and trust implications. | ||
|
|
||
| .minimum_zig_version = "0.14.1", | ||
| .minimum_zig_version = "0.16.0", |
There was a problem hiding this comment.
PR description says upgrade to Zig 0.16.0-dev (master), but the package minimum Zig version is set to the stable-looking "0.16.0". If this repo is intended to track master/nightly, align this to a dev identifier (or update the PR description if the intent is the 0.16.0 release) to avoid consumers/CI trying to use a different toolchain than expected.
| env: | ||
| ZIG_VERSION: 0.14.1 | ||
| ZIG_VERSION: 0.16.0 | ||
|
|
There was a problem hiding this comment.
PR description mentions Zig 0.16.0-dev (master), but CI pins ZIG_VERSION to "0.16.0". Please align CI with the intended toolchain (e.g., master/nightly vs a released 0.16.0) so CI reliably matches the minimum/toolchain expected by the package.
Four of the five Zig-0.16-upgrade PRs on our dependency forks have merged into ChainSafe upstream main: * ChainSafe/blst.zig#4 → 6ad139a * ChainSafe/hashtree-z#10 → 56e406f * ChainSafe/snappy.zig#5 → 7139424 * ChainSafe/zig-yaml#1 → b74f4e8 Switch from `lodekeeper-z/<repo>?ref=chore/zig-master` to the merged commit on `ChainSafe/<repo>` main for each. Content is identical so the existing `hash` fields stay valid. `zapi` (ChainSafe/zapi#9) is still open upstream — bump the `lodekeeper-z/zapi` commit pointer to the current PR head (fefb88ebf5c9) which includes the latest port/refactor work; TODO note to switch to ChainSafe/zapi once ChainSafe#9 merges.
## Motivation Get the codebase cleanly compatible with **Zig 0.16.0** release, following the new "explicit `io` everywhere, no hidden global state" design — without changing runtime behavior. ## Description - **`std.Io`** — File/Dir operations, `Mutex`/`Condition`/`Event` (cancelable vs uncancelable split), entropy via `io.random`/`io.randomSecure`, timestamps via `std.Io.Timestamp` - **ArrayList unmanaged** — allocator threaded through `deinit`/`append`/`resize`/`ensureCapacity`/`clone`; replace `items.len = N` hacks with `resize` / `expandToCapacity` / `appendNTimesAssumeCapacity` (preserves semantics, matches `initCapacity`'s Precise allocation) - **Struct builder** — `@Type(.@"struct" = ...)` → `@Struct(names, types, attrs)` builtin in `ssz/type/container.zig` - **Copy-elision workaround** — `std.Io` 0.16 result-location semantics pre-write the union tag of the assignment target, so reads from `self.state.init_group.*` during RHS evaluation would observe the new variant. Snapshot pre-upgrade fields to locals in `state_transition.zig` fork-upgrade chain and `era/Writer.zig` - **ThreadPool** — `io` is a parameter on `init`/`deinit`/`verifyMultipleAggregateSignatures`/`aggregateVerify` (not a stored field); normal paths use cancelable `lock`; shutdown + `submitAndWait.done.wait` stay uncancelable with comments explaining the invariant - **Shared `src/time.zig`** — `timestampNow` / `since (Duration)` / `durationSeconds`, replacing four duplicated helper pairs across `state_transition` and `bench` - **IO signature convention** — `(allocator?, io, file, ...)` applied consistently to `e2s.*` and `era.*` - **Reader API polish** — `takeArray` (zero-copy) + `readSliceAll` where appropriate; drop single-buffer `readVecAll` and `catch |err| return err` - **Other**: `RefCount` comptime-reflect on wrapped T's deinit arity (1-arg vs 2-arg) so 0.16 unmanaged `ArrayList` and project types with stored allocators both work; `sanitize_c = .trap` on blst artifact so Debug fuzz builds link without `libubsan`; untrack 426 stale `test/fuzz/zig-pkg/` entries from the git index - **CI**: `ZIG_VERSION` bumped `0.14.1 → 0.16.0`; `zbuild` sync-check + `build-examples` jobs temporarily commented out pending upstream Zig 0.16 support ## Dependency PRs Each Zig 0.16 upgrade landed as a dedicated PR on the upstream repo. `build.zig.zon` points at `lodekeeper-z` forks on the `chore/zig-master` branch until these merge and cut releases: | Dependency | Upstream PR | |---|---| | `blst` | [ChainSafe/blst.zig#4](ChainSafe/blst.zig#4) | | `hashtree` | [ChainSafe/hashtree-z#10](ChainSafe/hashtree-z#10) | | `snappy` | [ChainSafe/snappy.zig#5](ChainSafe/snappy.zig#5) | | `yaml` | [ChainSafe/zig-yaml#1](ChainSafe/zig-yaml#1) | | `zapi` | [ChainSafe/zapi#9](ChainSafe/zapi#9) | | `httpz` (disabled) | [karlseguin/http.zig#191](karlseguin/http.zig#191) |
Upgrade to Zig 0.16.0-dev (master) — part of the lodestar-z Zig master upgrade effort.
Key changes:
std.io→std.Iomigrationstd.Io.Dirmethods now require explicitioparameter🤖 Generated with AI assistance