cargo-zigbuild
🚀 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 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
Usage
- Install zig following the official documentation,
on macOS, Windows and Linux you can also install zig from PyPI via
pip3 install ziglang - Install Rust target via rustup, for example,
rustup target add aarch64-unknown-linux-gnu - 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
Note that Cargo
--message-formatoption doesn't work with universal2 target currently.
Caveats
- 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.
- Only current Rust stable and nightly versions are regularly tested on CI, other versions may not work.
Known upstream zig issues:
- zig cc: parse
-targetand-mcpu/-march/-mtuneflags according to clang: Some Rust targets aren't recognized byzig cc, for examplearmv7-unknown-linux-gnueabihf, workaround by using-mcpu=genericand explicitly passing target features in #58 - glibc 2.27 or older: fcntl64 not found, but zig's glibc headers refer it: workaround by using linker script in #14
- ability to link against darwin frameworks (such as CoreFoundation) when cross compiling:
Set the
SDKROOTenvironment variable to a macOS SDK path to workaround it - zig misses some
compiler_rtfunctions that may lead to undefined symbol error for certain targets.
License
This work is released under the MIT license. A copy of the license is provided in the LICENSE file.
Metadata
Release files for cargo-zigbuild 0.16.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| cargo_zigbuild-0.16.4-py3-none-win_arm64.whl | Python 3 | none | Windows ARM64 | Details |
| cargo_zigbuild-0.16.4-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
| cargo_zigbuild-0.16.4-py3-none-win32.whl | Python 3 | none | Windows x86-32 | Details |
| cargo_zigbuild-0.16.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl | Python 3 | none | Linux glibc 2.17+ ARMv7l | Details |
| cargo_zigbuild-0.16.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64 | Details |
| cargo_zigbuild-0.16.4-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl | Python 3 | none | Linux glibc 2.5+ x86-64 | Details |
| cargo_zigbuild-0.16.4-py3-none-manylinux_2_5_i686.manylinux1_i686.whl | Python 3 | none | Linux glibc 2.5+ x86-32 | Details |
| cargo_zigbuild-0.16.4-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl | Python 3 | none | macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64 | Details |
Total release size: 8.3 MB
Release files / cargo_zigbuild-0.16.4-py3-none-win_arm64.whl
| Download URL | cargo_zigbuild-0.16.4-py3-none-win_arm64.whl |
|---|---|
| Size | 850.6 kB |
| Tags | Python 3 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
ac46a36aefd7dd34c45bc56dba57904cc71c629ff5f481841efd1dba3dd41981
|
|
BLAKE2b-256 checksum How to use checksums |
24240f0b3ed950b35bded478ab75d1f624852d35b29e05d4d7859031f0e57824
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.15
|
Release files / cargo_zigbuild-0.16.4-py3-none-win_amd64.whl
| Download URL | cargo_zigbuild-0.16.4-py3-none-win_amd64.whl |
|---|---|
| Size | 896.2 kB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d825e5a9f029e7942ef4e416bcbc26e429afdc39dcb5f24b0950e4d5ab12e1c1
|
|
BLAKE2b-256 checksum How to use checksums |
51872559cfb91ad14ecdba6c6a783e578ee1e4e592d2d97f7192b63178751252
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.15
|
Release files / cargo_zigbuild-0.16.4-py3-none-win32.whl
| Download URL | cargo_zigbuild-0.16.4-py3-none-win32.whl |
|---|---|
| Size | 839.2 kB |
| Tags | Python 3 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
9bcea56c24363e403f5e78c01e9487e8f1b67e15b4f6cc9bf748d141d7547a34
|
|
BLAKE2b-256 checksum How to use checksums |
246d205f332e8365ab1d637223811d6b84fbba0452440104483c1047db02c6ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.15
|
Release files / cargo_zigbuild-0.16.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | cargo_zigbuild-0.16.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 882.6 kB |
| Tags | Linux glibc 2.17+ ARMv7l Python 3 |
|
SHA-256 checksum How to use checksums |
090f1c0078045e20e602fe8b7dd9cc626616adf7067a0522b289605695d2548a
|
|
BLAKE2b-256 checksum How to use checksums |
904289b5e1b21fea2f71baf240fc36ca8902f034f773d8ac187da4ae26555bda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.15
|
Release files / cargo_zigbuild-0.16.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | cargo_zigbuild-0.16.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 928.9 kB |
| Tags | Linux glibc 2.17+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
999b4fd46fcd03a1da8d201c1955f40c6ee52f03d507932c5d7e5d0a927ad238
|
|
BLAKE2b-256 checksum How to use checksums |
ee7b71c6b4258800971541a05323490c2e90e9f57c76c7b56aa6490decf03c16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.15
|
Release files / cargo_zigbuild-0.16.4-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
| Download URL | cargo_zigbuild-0.16.4-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | Linux glibc 2.5+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
5ce88fffb6624cb9f21f552fbeb63e5827d41cad344d3f71ae8592be4dbfc8ca
|
|
BLAKE2b-256 checksum How to use checksums |
bb9d65b7b10acfce859aad5781bba5edc815157bb1183fe19d33cec4f11179f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.15
|
Release files / cargo_zigbuild-0.16.4-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
| Download URL | cargo_zigbuild-0.16.4-py3-none-manylinux_2_5_i686.manylinux1_i686.whl |
|---|---|
| Size | 1.0 MB |
| Tags | Linux glibc 2.5+ x86-32 Python 3 |
|
SHA-256 checksum How to use checksums |
1fdb648043b2fb0a83157d6ed206ffcbe45ed77b1b341e303dead43bba734743
|
|
BLAKE2b-256 checksum How to use checksums |
5738a00bfd798169e547409651e58c09535a92b987b9aae62d32c0d8bc445063
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.15
|
Release files / cargo_zigbuild-0.16.4-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
| Download URL | cargo_zigbuild-0.16.4-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl |
|---|---|
| Size | 1.9 MB |
| Tags | Python 3 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f7e11005a403ba0fa7c7f585e88f9aa8ba31f17ca0b3280c56643e1b6736a621
|
|
BLAKE2b-256 checksum How to use checksums |
4dd94ddc1d302936324d08d52d80a946f9c09f2d71248142c351a751ec7c67f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.14.15
|