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 - 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. See also: zig compiler-rt status. - 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.
Release files for cargo-zigbuild 0.17.1
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.17.1-py3-none-win_arm64.whl | Python 3 | none | Windows ARM64 | Details |
| cargo_zigbuild-0.17.1-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
| cargo_zigbuild-0.17.1-py3-none-win32.whl | Python 3 | none | Windows x86-32 | Details |
| cargo_zigbuild-0.17.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl | Python 3 | none | Linux glibc 2.17+ ARMv7l | Details |
| cargo_zigbuild-0.17.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64 | Details |
| cargo_zigbuild-0.17.1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl | Python 3 | none | Linux glibc 2.5+ x86-64 | Details |
| cargo_zigbuild-0.17.1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl | Python 3 | none | Linux glibc 2.5+ x86-32 | Details |
| cargo_zigbuild-0.17.1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl | Python 3 | none | macOS 11.0+ ARM64, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64 | Details |
Total release size: 8.6 MB
Release files / cargo_zigbuild-0.17.1-py3-none-win_arm64.whl
| Download URL | cargo_zigbuild-0.17.1-py3-none-win_arm64.whl |
|---|---|
| Size | 875.8 kB |
| Tags | Python 3 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
a299994ebefdd0c04a86d6658cc73680d2cc95fe3f61a7b255d6554eeca066b4
|
|
BLAKE2b-256 checksum How to use checksums |
e4e21e07c93ffea2db868b3b9b208ef040bf618389f6b937672d1f8df92fd7ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / cargo_zigbuild-0.17.1-py3-none-win_amd64.whl
| Download URL | cargo_zigbuild-0.17.1-py3-none-win_amd64.whl |
|---|---|
| Size | 917.8 kB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
295070b06e754d2040838de7324a795e9367549aae396f2ea577fbcf0555eae2
|
|
BLAKE2b-256 checksum How to use checksums |
53299002ffa13c4e10d3fa5314b6e2644544d729ae1272058a30d2e93da5fd1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / cargo_zigbuild-0.17.1-py3-none-win32.whl
| Download URL | cargo_zigbuild-0.17.1-py3-none-win32.whl |
|---|---|
| Size | 860.1 kB |
| Tags | Python 3 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
28f803b22a56f0189dc7b1bd243116b3e753a746b51004712e3ae3adea851086
|
|
BLAKE2b-256 checksum How to use checksums |
3d16660cd967d3fd38d571abea5d27830e956e266a2b4177ca67cd5f7a15a673
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / cargo_zigbuild-0.17.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | cargo_zigbuild-0.17.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 926.8 kB |
| Tags | Linux glibc 2.17+ ARMv7l Python 3 |
|
SHA-256 checksum How to use checksums |
bd996995cb8d1ac79df4eeaca6433b007827c3e11a3e34169f8a085a71a347b5
|
|
BLAKE2b-256 checksum How to use checksums |
b4acf896aee40b3db79aacc177c8a7f959f3433946affe6633649a6c8e3737e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / cargo_zigbuild-0.17.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | cargo_zigbuild-0.17.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 960.6 kB |
| Tags | Linux glibc 2.17+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
5f60dd4f342f2e0ab7693613af242357fa4194f8664b169bc7886c064038e66f
|
|
BLAKE2b-256 checksum How to use checksums |
246e05281738bb37d06b7e446486b1270358b92972c0d91aeb88090b6a43ac22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / cargo_zigbuild-0.17.1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
| Download URL | cargo_zigbuild-0.17.1-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 |
66cbe50d537cb638a9929a96eac0017b1f411261d8c46ecc445b9956f0966e61
|
|
BLAKE2b-256 checksum How to use checksums |
4fbc5f2422790a1a0aab3fe978920763076c439070a3b767fa828f0489771048
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / cargo_zigbuild-0.17.1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
| Download URL | cargo_zigbuild-0.17.1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl |
|---|---|
| Size | 1.1 MB |
| Tags | Linux glibc 2.5+ x86-32 Python 3 |
|
SHA-256 checksum How to use checksums |
48ecad7155ad720594c54be1135bf4a2511de8f3fa500870780fdff8f89dba4d
|
|
BLAKE2b-256 checksum How to use checksums |
58d83d4383b59c9683a31c22dc8d338fe00d55ced44abf871d7abd9d3a21029a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|
Release files / cargo_zigbuild-0.17.1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
| Download URL | cargo_zigbuild-0.17.1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl |
|---|---|
| Size | 2.0 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 |
4a06f76b70ef6ec5fefb6d7f79e5ecd9f6b1fc0f12bb12b5661c1027c6615786
|
|
BLAKE2b-256 checksum How to use checksums |
1863989c122b472dd86c8bec0b3d40d9b0bed12845c21fbc2ffda35b6ce87bee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.2.3
|