Skip to content

fix: build static library with PIC - #12

Merged
wemeetagain merged 1 commit into
mainfrom
nflaig/arm64-musl
Jul 10, 2026
Merged

fix: build static library with PIC#12
wemeetagain merged 1 commit into
mainfrom
nflaig/arm64-musl

Conversation

@nflaig

@nflaig nflaig commented Jul 10, 2026

Copy link
Copy Markdown
Member

What changed

Build the hashtree static library with position-independent code enabled.

Why

The static library is linked into native Node.js shared libraries such as @chainsafe/lodestar-z. Cross-compiling that addon for aarch64-linux-musl currently fails with AArch64 relocation errors and asks for the hashtree C objects to be recompiled with -fPIC.

The assembly sources already receive -fpic; setting the Zig module's pic option also covers the C sources and makes the complete shared-library link valid.

Impact

This unblocks ARM64 musl/Alpine native addon builds while preserving the existing static-library interface.

Validation

  • zig fmt --check .
  • zig build test
  • zig build -Dtarget=aarch64-linux-musl
  • complete Lodestar-Z aarch64-unknown-linux-musl ReleaseSafe cross-build

This PR was written with AI assistance.

@nflaig
nflaig marked this pull request as ready for review July 10, 2026 14:27
@wemeetagain
wemeetagain merged commit f5c1b81 into main Jul 10, 2026
3 checks passed
matthewkeil added a commit to ChainSafe/lodestar-z that referenced this pull request Jul 10, 2026
## What changed

- add `aarch64-unknown-linux-musl` to the Lodestar-Z native package
target matrix
- pin hashtree-z to the merged PIC-enabled commit from
[ChainSafe/hashtree-z#12](ChainSafe/hashtree-z#12)
- pin the Zig ZAPI dependency to the ARM64-musl backport on
`zapi-v2.x.0`
- keep the npm dependency on `@chainsafe/zapi` 2.0.0, apply the matching
target-support backport with a pnpm patch, and bundle the patched
dependency for consumers

## Why

Lodestar currently receives an ARM64 musl binary from `@chainsafe/blst`.
Replacing it with Lodestar-Z without an equivalent artifact would
regress Alpine Linux support on ARM64.

The first real cross-build also exposed non-PIC objects in hashtree-z,
which prevented the native Node.js shared library from linking. The
pinned prerequisite commit fixes that linker failure.

## Dependency chain

- [ChainSafe/zapi#47](ChainSafe/zapi#47) is
backported to `zapi-v2.x.0`
-
[ChainSafe/hashtree-z#12](ChainSafe/hashtree-z#12)
is merged; `build.zig.zon` pins its canonical squash commit using `zig
fetch --save=hashtree`

## Validation

- complete `aarch64-unknown-linux-musl` ReleaseSafe build through the
patched ZAPI 2 CLI
- native host ReleaseSafe bindings build
- frozen pnpm install
- `pnpm lint`
- `zig fmt --check build.zig.zon`
- 236 binding tests passed
- npm package dry run confirms the patched ZAPI 2 dependency is bundled

> This PR was written with AI assistance.

---------

Co-authored-by: matthewkeil <me@matthewkeil.com>
Co-authored-by: bing <spiralladder@fastmail.com>
Co-authored-by: Cayman <caymannava@gmail.com>
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.

3 participants