Compile Cargo project with zig as linker
Project description
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-format
option 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
-target
and-mcpu
/-march
/-mtune
flags according to clang: Some Rust targets aren't recognized byzig cc
, for examplearmv7-unknown-linux-gnueabihf
, workaround by using-mcpu=generic
and 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
SDKROOT
environment variable to a macOS SDK path to workaround it
License
This work is released under the MIT license. A copy of the license is provided in the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file cargo_zigbuild-0.16.0-py3-none-win_arm64.whl
.
File metadata
- Download URL: cargo_zigbuild-0.16.0-py3-none-win_arm64.whl
- Upload date:
- Size: 848.7 kB
- Tags: Python 3, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebb95198cd8991a8cc9032876011500196b2d8cf2bba0d2c6b603daa46825e25 |
|
MD5 | f3f3e56a04905232ff13b14ba39452a0 |
|
BLAKE2b-256 | b8bec3544bdf557a13e73c8292bcaea69d736df46ba504081cd0c4be463456a5 |
Provenance
File details
Details for the file cargo_zigbuild-0.16.0-py3-none-win_amd64.whl
.
File metadata
- Download URL: cargo_zigbuild-0.16.0-py3-none-win_amd64.whl
- Upload date:
- Size: 899.2 kB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 167834a0cb5456b30f5b1f7882f4471357f4777ad0f25012bc36c2375e2a09ca |
|
MD5 | f4ae2064855fa47fc3191ab2698ca9ca |
|
BLAKE2b-256 | 555d635a82ee2140f3fa1e4c5a0a5a5d39b58543b32443065efcce31590ecd37 |
Provenance
File details
Details for the file cargo_zigbuild-0.16.0-py3-none-win32.whl
.
File metadata
- Download URL: cargo_zigbuild-0.16.0-py3-none-win32.whl
- Upload date:
- Size: 839.0 kB
- Tags: Python 3, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7052baf870432f9362500ad0412d42afc9869d3d588f057c5b18d500c0727be5 |
|
MD5 | 430176cad3362f51809988f8872fe15b |
|
BLAKE2b-256 | d15f60b2d1bc19979e79bfc0438ad78987b909234229df9ccc3716f543d7a388 |
Provenance
File details
Details for the file cargo_zigbuild-0.16.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
.
File metadata
- Download URL: cargo_zigbuild-0.16.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 882.5 kB
- Tags: Python 3, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f123be93e5d27d64b90dd64f38be7e844926de3ccf4be373a9314db1a394d4ec |
|
MD5 | cdcaf4e245f8a7ca658ce8873e06d2bf |
|
BLAKE2b-256 | 860b75760134d5fae8feed0b2c9fbfb820e43f6098a6352c0e7acfdc709366e6 |
Provenance
File details
Details for the file cargo_zigbuild-0.16.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: cargo_zigbuild-0.16.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 929.6 kB
- Tags: Python 3, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 081c76c6abcd0ce7fa22fc1e11387a8a12d9ce8687cc9a81df9a701033619880 |
|
MD5 | 3975a3dc506ade94b25809604887dfec |
|
BLAKE2b-256 | 0599f09666edace7754a756df2acf0d777e6b0cbc90ddd92ab5a8ac98682ee74 |
Provenance
File details
Details for the file cargo_zigbuild-0.16.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
.
File metadata
- Download URL: cargo_zigbuild-0.16.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: Python 3, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb1493e033f9822d466c30a73e82c7f5d4fd62d44acfef312b60e1794a753059 |
|
MD5 | 4f70b2f91a038da02a6dbb436e7d798a |
|
BLAKE2b-256 | 2e522c465105d3f2c8f2d317feeff1cb9841cba6f757b1e447354dc2b29df510 |
Provenance
File details
Details for the file cargo_zigbuild-0.16.0-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
.
File metadata
- Download URL: cargo_zigbuild-0.16.0-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 1.0 MB
- Tags: Python 3, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3136df37e0ebc38b80790faeec052685f141ac12a57114a43d3d047f309b69da |
|
MD5 | 02c47c9b2fbcaf06eca5aa039ce1470c |
|
BLAKE2b-256 | e3213a9f052a5ef822ae68c8a185613986aec5b81d554f0d80a953784b6fcb67 |
Provenance
File details
Details for the file cargo_zigbuild-0.16.0-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
.
File metadata
- Download URL: cargo_zigbuild-0.16.0-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 1.9 MB
- Tags: Python 3, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2469848ae8747cab7656762a4ef430d3002c7dd6031b5a32937e7b281b6ca18c |
|
MD5 | 4f6a8283fe97252277b23db2c0b70c26 |
|
BLAKE2b-256 | fda4b8c010511a24ffd5c32a0d0e1918fcc997cc65a0ece2cd7ff2caacf6c542 |