|
| 1 | +# ADR 0002: Build the native library with `zig cc` |
| 2 | + |
| 3 | +- **Status:** Completed |
| 4 | +- **Date:** 2026-06-27 |
| 5 | +- **Deciders:** project maintainer |
| 6 | + |
| 7 | +## Context |
| 8 | + |
| 9 | +The project bundles `libzstd` for six classifiers (`{osx,linux,windows}` × |
| 10 | +`{x86_64,aarch64}`). zstd is pure C with no build-system dependency. The build |
| 11 | +must produce all six from CI without per-platform runners or system toolchains. |
| 12 | + |
| 13 | +## Decision |
| 14 | + |
| 15 | +Compile the zstd library sources directly with `zig cc` |
| 16 | +(`scripts/build-zstd.sh`). Zig bundles clang + libc + headers for every target, |
| 17 | +so any host cross-compiles any classifier hermetically. No zstd Makefile, no |
| 18 | +CMake, no sysroot. The Maven `exec` plugin runs it in `generate-resources`; |
| 19 | +it is idempotent (skips if the library exists). |
| 20 | + |
| 21 | +## Consequences |
| 22 | + |
| 23 | +### Positive |
| 24 | +- One CI host (`ubuntu-latest`) builds all six classifiers — including the ones |
| 25 | + with no free CI runner (windows-aarch64, linux-aarch64). |
| 26 | +- Hermetic and reproducible: no dependence on the host's installed toolchain. |
| 27 | +- Compiles `.c` directly, bypassing zstd's own build entirely. |
| 28 | + |
| 29 | +### Negative |
| 30 | +- Adds a Zig toolchain dependency to the build. |
| 31 | +- `zig cc` is a clang wrapper, not the zstd-blessed build path. |
| 32 | + |
| 33 | +### Risks to manage |
| 34 | +- Zig is pre-1.0; `zig cc` flag behaviour can shift between versions. The Zig |
| 35 | + version is **pinned** (0.16.0) in CI; upgrades require a re-test. |
| 36 | + |
| 37 | +## Alternatives considered |
| 38 | + |
| 39 | +- **GitHub matrix runners:** no free windows-aarch64 / fragmented, slow. |
| 40 | +- **CMake/Make + cross sysroots:** per-target toolchain setup, the misery this |
| 41 | + decision exists to avoid. |
| 42 | + |
| 43 | +## References |
| 44 | + |
| 45 | +- [scripts/build-zstd.sh](../../scripts/build-zstd.sh) |
| 46 | +- [ADR 0006 — native compile flags](0006-native-compile-flags.md) |
| 47 | +- [ADR 0014 — single-threaded native build](0014-single-threaded-native-build.md) |
0 commit comments