Rul1an/zig-cross-compile-action
Zig based cross compilation for C, C++, Rust and Go. No Docker.
A secure, performance-focused GitHub Action to setup the Zig toolchain and cross-compile C, C++, Rust, Go, and Zig projects.
~/.cache/zig support to speed up builds.linux-x86_64-musl, macos-arm64).Just install Zig and set up the environment.
- uses: Rul1an/zig-cross-compile-action@v3
with:
version: "0.13.0"
target_preset: "linux-x86_64-musl"
setup_only: "true"
- run: zig build -Dtarget=$ZIG_TARGET
Run tests, benchmark, and build with caching enabled.
- uses: Rul1an/zig-cross-compile-action@v3
with:
version: "0.13.0"
target_preset: "linux-x86_64-musl"
use_cache: "true"
# Run tests before building. Fails job if tests fail.
run_tests: "true"
test_script: |
zig build test
zig build test-parity
perf_command: "zig build bench"
# Build command
project-type: "zig"
cmd: "-Doptimize=ReleaseSafe"
Generate accurate SBOMs and sign artifacts (Linux runners only).
IMPORTANT Keyless signing requires
permissions: id-token: writein your workflow.
- uses: Rul1an/zig-cross-compile-action@v3
with:
version: "0.13.0"
target_preset: "linux-x86_64-musl"
setup_only: "true"
# Supply Chain
sbom: "true"
sbom_target: "zig-out/bin/my-app"
sign: "true"
sign_artifact: "zig-out/bin/my-app"
| Input | Description | Default |
|---|---|---|
version |
Zig version (e.g. 0.13.0). Use strict_version: true (default) for exact matches. |
0.13.0 |
target_preset |
Alias for common targets (linux-x86_64, linux-arm64, macos-arm64, windows-x86_64). |
|
target |
Explicit Zig target triple (e.g. x86_64-linux-gnu). Supersedes target_preset. |
|
project-type |
zig, custom, c, go, rust. Sets up environment variables. |
custom |
setup_only |
If true, installs toolchain and env but skips build command. |
false |
use_cache |
Enable ~/.cache/zig persistence. |
false |
sbom |
Generate SBOM with Syft (Linux only). | false |
sign |
Sign artifact with Cosign Keyless (Linux only). | false |
Setting project-type to go, rust, or c calculates the correct cross-compilation environment variables (e.g., CC, CGO_ENABLED, CARGO_TARGET_..._LINKER) but relies on you to provide the build command via cmd or a subsequent run step. The action acts as a "toolchain bootstrapper" for these languages.
When use_cache: true, we cache ~/.cache/zig and include build.zig / go.mod / Cargo.lock in the cache key.
Tip: Zig caches can grow large. GitHub limits caches to 10GB. You may need to clear caches occasionally if testing many targets.
v3 is backwards compatible with v2 inputs (version, target, cmd, project-type).
verify-level is deprecated (no-op).project-type now strictly means "setup environment"; for non-Zig projects, it functions identically to custom but with smarter env vars.This action is used to build and release Rul1an/llm-cost (a cross-platform Zig tool for LLM token estimation). Check that repository for a production-grade workflow example.