Skip to main content

Build provenance: This package is built and distributed by Astral as part of astral-dev-toolchain. It packages cargo-zigbuild from tag v0.24.0 at commit 2ffd80658c96b5ff971085dd509e58e5b441f1c8.


cargo-zigbuild

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.

Installation

cargo install --locked cargo-zigbuild

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

pip install cargo-zigbuild

We also provide Docker images 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 ghcr.io/rust-cross/cargo-zigbuild \
  cargo zigbuild --release --target x86_64-apple-darwin

Packaging status

Usage

  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

Environment Variables

Variable Description
CARGO_ZIGBUILD_PYTHON_PATH Python executable path when using Python ziglang package (default: python3)
CARGO_ZIGBUILD_ZIG_PATH Zig executable path (default: zig)
CARGO_ZIGBUILD_CACHE_DIR Cache directory for zig tools and wrappers
CARGO_ZIGBUILD_RUSTC_VERSION Override detected rustc version
CARGO_ZIGBUILD_TARGET Resolved zig target triple exported to build scripts, for example x86_64-linux-gnu.2.36 (also CARGO_ZIGBUILD_TARGET_<target>, which is always set; the unsuffixed name only when a single --target is given)
SDKROOT Path to macOS SDK (auto-detected on macOS)
CMAKE_TOOLCHAIN_FILE Path to CMake toolchain file (also CMAKE_TOOLCHAIN_FILE_<target>, TARGET_CMAKE_TOOLCHAIN_FILE)
BINDGEN_EXTRA_CLANG_ARGS Extra clang arguments for bindgen (also BINDGEN_EXTRA_CLANG_ARGS_<target>)
PKG_CONFIG_SYSROOT_DIR System root for pkg-config (auto-set to SDKROOT for Apple targets)
OHOS_NDK_HOME Path to OpenHarmony NDK (required for ohos targets)
CFLAGS Additional C compiler flags
RUSTFLAGS Additional Rust compiler flags

Specify glibc version

By default --target for *-gnu will have Zig implicitly build for a default version of glibc that varies based on the release of Zig (v12 to v14 releases default to glibc 2.28).

To build for a specific minimum glibc version, add that version as a suffix to the --target value. For example, to compile with --target aarch64-unknown-linux-gnu for glibc 2.17:

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

Tip - cargo zigbuild cannot find headers (*.h files) or libraries that exist

You may need to prepend the following ENV to your cargo zigbuild command with the following system paths or similar:

  • CFLAGS='-isystem /usr/include'
  • RUSTFLAGS='-L /usr/lib64'

cargo zigbuild always uses the zig cc option -nostdinc which excludes standard header locations like /usr/include. This is also a default behaviour for Zig whenever it is configured with a --target, which additionally opts out of standard system search paths.

This can lead to a common difference between cargo build being successful, while cargo zigbuild fails without extra configuration:

# Cannot find a header file to build:
fatal error: 'libelf.h' file not found

# Cannot find a shared library to link:
error: unable to find dynamic system library 'elf' using strategy 'no_fallback'. searched paths

There is a variety of ways to resolve this, but for system paths like /usr/include you must be careful to avoid getting the system glibc headers mixed with the glibc headers Zig provides itself, otherwise this will produce errors like from CPATH=/usr/include:

In file included from /usr/local/lib64/python3.13/site-packages/ziglang/lib/libunwind/src/gcc_personality_v0.c:21:
In file included from /usr/local/lib64/python3.13/site-packages/ziglang/lib/libunwind/include/unwind.h:18:
In file included from /usr/include/stdint.h:26:
In file included from /usr/include/bits/libc-header-start.h:33:
/usr/include/features.h:516:9: warning: '__GLIBC_MINOR__' macro redefined [-Wmacro-redefined]
  516 | #define __GLIBC_MINOR__ 41
      |         ^
<command line>:2:9: note: previous definition is here
    2 | #define __GLIBC_MINOR__ 37
      |

When you have installed system packages that added headers to /usr/include that your project needs to build, you will want Zig to fallback to /usr/include just for those headers while using it's own for glibc. This can be done with zig cc -isystem /usr/include, which for cargo zigbuild can be configured through the common ENV CFLAGS='-isystem /usr/include'.

For the similar issue with shared libraries, if your packages are installing system libraries at /usr/lib64 you would normally use LDFLAGS='-L /usr/lib64', but rustc and cargo do not read this ENV but they must be configured with the search path for crates with a build.rs that searches for a library to link dynamically/statically. Instead you will need to use RUSTFLAGS='-L /usr/lib64'.

Tip - Verify minimum GLIBC version required

Provided you have no stripped the symbols from your binary built, on Linux you can run the following script to scan for glibc versioned symbols and find the highest version (the minimum required to run)

  1. Create a file /usr/local/bin/get-min-glibc:

    #!/bin/bash
    
    FILE_NAME=$1
    LANG=C readelf -W --version-info --dyn-syms ${FILE_NAME} \
      | grep 'Name: GLIBC' \
      | sed -re 's/.*GLIBC_(.+) Flags.*/\1/g' \
      | sort -t . -k1,1n -k2,2n \
      | tail -n 1
    
  2. Make the script command executable:

    chmod +x /usr/local/bin/get-min-glibc
    
  3. Run the command with the path to your executable / library to check:

    $ get-min-glibc target/x86_64-unknown-linux-gnu/release/hello-world
    2.28
    

Specify macOS version

To build for a specific minimum macOS version, set the MACOSX_DEPLOYMENT_TARGET environment variable:

MACOSX_DEPLOYMENT_TARGET=13.0 cargo zigbuild --target aarch64-apple-darwin

rustc and C/C++ build scripts read this variable directly, and cargo-zigbuild also passes the version to zig cc.

Specify target CPU

When cross-compiling for a CPU newer than the target's baseline — for example AWS Graviton (ARM Neoverse) instances — specify the target CPU via RUSTFLAGS, or you may hit hard-to-diagnose Illegal instruction (SIGILL, exit code 132) errors at runtime, or leave performance on the table:

RUSTFLAGS='-C target-cpu=neoverse-n1' cargo zigbuild --release --target aarch64-unknown-linux-gnu.2.34

cargo zigbuild picks up -C target-cpu and passes a matching -mcpu to zig cc so that C/C++ dependencies are built for the same CPU.

Since environment variables can't be set in cargo aliases, you can also pass the rustflags via cargo's --config option — cargo zigbuild honors it the same way:

cargo zigbuild --release --target x86_64-unknown-linux-gnu \
    --config "target.x86_64-unknown-linux-gnu.rustflags=['-C', 'target-cpu=x86-64-v4']"

This makes it possible to scope a target-cpu to a specific alias in .cargo/config.toml instead of applying it to every build for that target:

[alias]
build-prod = "zigbuild --release --target x86_64-unknown-linux-gnu --config target.x86_64-unknown-linux-gnu.rustflags=['-C','target-cpu=x86-64-v4']"

Conversely, if a binary built for x86_64-unknown-linux-gnu dies with Illegal instruction on older hardware, check whether your RUSTFLAGS/.cargo/config.toml sets a target-cpu newer than the machines you deploy to.

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

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

Caveats

  1. Currently only Linux and macOS 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.
  3. When using zig 0.15+ with crates that use bindgen, you may need clang 18+ installed for bindgen to work correctly. This is because zig 0.15+ bundles libc++ 19 headers which require a compatible libclang version.

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

License

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

Metadata

Release files for astral-dev-toolchain-cargo-zigbuild 0.24.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for astral-dev-toolchain-cargo-zigbuild 0.24.0
File Actions
astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details for astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-win_arm64.whl
astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-win_amd64.whl
astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-macosx_11_0_arm64.whl
astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-macosx_10_12_x86_64.whl

Total release size: 9.4 MB

Release files / astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-win_arm64.whl

Download URL astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-win_arm64.whl
Size 1.4 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
f859b9cfbc96fc5adfe775ba412f5c22adc085d31a28d188b8ac368e8cca1167
BLAKE2b-256 checksum
How to use checksums
ba91f028ba382ce316309871b916c4bc996c6256735d93641979d1aad6be6fe1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Release files / astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-win_amd64.whl

Download URL astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-win_amd64.whl
Size 1.5 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
422af1eadac8d6f6a860db74e5f6787f90326ea6fb9b9dcb881bc778ebcdaf68
BLAKE2b-256 checksum
How to use checksums
4c7335eff81bee5c840672b6f1733d7d8a660622b74fbfb37473b964b1395568
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Release files / astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.6 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
3e9dcfc32b38c2815a12e3f508880f41b8a2142566257c1a611f448966332e65
BLAKE2b-256 checksum
How to use checksums
dba3ab8ba5aadd157959deb256f5ab7c74021fd716111696e770be8475720e39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Release files / astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.5 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
f3835678fcc3f79a901430793ba693c3d2a800d088b8820f30b161c56ed4cf34
BLAKE2b-256 checksum
How to use checksums
2c620153980c3ecf448b29ea154e401a6e454e6f0c0f78e1f24d5fdee7629e4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Release files / astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-macosx_11_0_arm64.whl

Download URL astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-macosx_11_0_arm64.whl
Size 1.6 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
dd9f193f04eee3891fa576ddd06628f8ba5742eba3dcff35afe7b6f1dea7e0cf
BLAKE2b-256 checksum
How to use checksums
181ece15c58d46f076e12e033920df8b03bc750e8c6d76a46618e1d1f9ff3b3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Release files / astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-macosx_10_12_x86_64.whl

Download URL astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-macosx_10_12_x86_64.whl
Size 1.7 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0c9e8747939a203bcde7eb3f35cc929108965169ad72fe2696865f561c96358c
BLAKE2b-256 checksum
How to use checksums
ba8d5e4c3ae4c11efcc9a4c95568ffb4c5f62b9af34c9ceecb64af56b6cd2ab5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

Security for astral-dev-toolchain-cargo-zigbuild 0.24.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for astral_dev_toolchain_cargo_zigbuild-0.24.0-py3-none-win_arm64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page