Skip to content

tayne3/zig-toolchain.cmake

Repository files navigation

zig-toolchain.cmake

zig-toolchain.cmake

Release Tag Tests CMake

A lightweight CMake toolchain file that enables cross-compilation of C/C++ projects using Zig, eliminating the need to install platform-specific GCC toolchains.

Usage

Requirements:

  • CMake 3.14+
  • Zig 0.15+

Integration:

Download zig-toolchain.cmake to your project root or a cmake/ subdirectory.

curl -o zig-toolchain.cmake https://github.com/tayne3/zig-toolchain.cmake/releases/download/v0.3.0/zig-toolchain.cmake

Cross-Compilation:

Use standard CMake variables for common targets, or specify ZIG_TARGET directly when you need precise ABI control (e.g., musl vs gnu).

Compile for Linux ARM64:

cmake -S . -B build -G Ninja \
  -DCMAKE_TOOLCHAIN_FILE=zig-toolchain.cmake \
  -DCMAKE_SYSTEM_NAME=Linux \
  -DCMAKE_SYSTEM_PROCESSOR=aarch64

cmake --build build

Compile for Windows x64:

cmake -S . -B build -G Ninja \
  -DCMAKE_TOOLCHAIN_FILE=zig-toolchain.cmake \
  -DCMAKE_SYSTEM_NAME=Windows \
  -DCMAKE_SYSTEM_PROCESSOR=x86_64

Compile for Linux x86_64 (Musl/Static):

cmake -S . -B build -G Ninja \
  -DCMAKE_TOOLCHAIN_FILE=zig-toolchain.cmake \
  -DZIG_TARGET=x86_64-linux-musl

About

⚡ Use Zig compiler in CMake projects. Simplify cross-compilation.

Topics

Resources

License

Stars

Watchers

Forks

Contributors