#zig #cargo

bin+lib cargo-zigbuild

Compile Cargo project with zig as linker

85 releases

new 0.18.1 Dec 3, 2023
0.18.0 Nov 22, 2023
0.17.5 Nov 13, 2023
0.17.0 Jul 29, 2023
0.7.1 Mar 31, 2022

#30 in Cargo plugins

Download history 5139/week @ 2023-08-18 5516/week @ 2023-08-25 6075/week @ 2023-09-01 8237/week @ 2023-09-08 7563/week @ 2023-09-15 8785/week @ 2023-09-22 9553/week @ 2023-09-29 9146/week @ 2023-10-06 9497/week @ 2023-10-13 8443/week @ 2023-10-20 9243/week @ 2023-10-27 7564/week @ 2023-11-03 9407/week @ 2023-11-10 8205/week @ 2023-11-17 9136/week @ 2023-11-24 8607/week @ 2023-12-01

36,661 downloads per month
Used in 4 crates (2 directly)

MIT license



CI Crates.io docs.rs PyPI Docker Image

🚀 Help me to become a full-time open-source developer by sponsoring me on GitHub

Compile Cargo project with zig as linker for easier cross compiling.


cargo install cargo-zigbuild

You can also install it using pip which will also install ziglang automatically:

pip install cargo-zigbuild

We also provide a Docker image which has macOS SDK pre-installed in addition to cargo-zigbuild and Rust, for example to build for x86_64 macOS:

docker run --rm -it -v $(pwd):/io -w /io messense/cargo-zigbuild \
  cargo zigbuild --release --target x86_64-apple-darwin

Packaging status


  1. Install zig following the official documentation, on macOS, Windows and Linux you can also install zig from PyPI via pip3 install ziglang
  2. Install Rust target via rustup, for example, rustup target add aarch64-unknown-linux-gnu
  3. Run cargo zigbuild, for example, cargo zigbuild --target aarch64-unknown-linux-gnu

Specify glibc version

cargo zigbuild supports passing glibc version in --target option, for example, to compile for glibc 2.17 with the aarch64-unknown-linux-gnu target:

cargo zigbuild --target aarch64-unknown-linux-gnu.2.17

macOS universal2 target

cargo zigbuild supports a special universal2-apple-darwin target for building macOS universal2 binaries/libraries on Rust 1.64.0 and later.

rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
cargo zigbuild --target universal2-apple-darwin


Note that Cargo --message-format option doesn't work with universal2 target currently.


  1. Currently only Linux, macOS and Windows gnu targets are supported, other target platforms can be added if you can make it work, pull requests are welcome.
  2. Only current Rust stable and nightly versions are regularly tested on CI, other versions may not work.

Known upstream zig issues:

  1. zig cc: parse -target and -mcpu/-march/-mtune flags according to clang: Some Rust targets aren't recognized by zig cc, for example armv7-unknown-linux-gnueabihf, workaround by using -mcpu=generic and explicitly passing target features in #58
  2. ability to link against darwin frameworks (such as CoreFoundation) when cross compiling: Set the SDKROOT environment variable to a macOS SDK path to workaround it
  3. zig misses some compiler_rt functions that may lead to undefined symbol error for certain targets. See also: zig compiler-rt status.
  4. CPU features are not passed to clang


This work is released under the MIT license. A copy of the license is provided in the LICENSE file.


~172K SLoC