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 - 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 - zig misses some
compiler_rt
functions 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.
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
Hashes for cargo_zigbuild-0.17.4-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06fd3dadf4ced9c69f15d71a56afe1a9df2797dff7f10a088bdbe70b036404ac |
|
MD5 | 8cabaef101fdca0f9a3fa1c398a40ce7 |
|
BLAKE2b-256 | afea14f029fc9b2d113676b72309e1af9e94e063c04a8b00108dd954feffb80d |
Hashes for cargo_zigbuild-0.17.4-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93ae888d42ab81a462e32bfa53588b228f3865a3a7aa202f40d0236f3ea260a4 |
|
MD5 | 0d66cc1d683a66f2e6afaceb108954b6 |
|
BLAKE2b-256 | a522d9288d1c56dfff3c361822cf81da70a7c2b00cfd8a06fcec8d21f0b091d1 |
Hashes for cargo_zigbuild-0.17.4-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0539f29122ca6731b92ef91888e4e96b98feb32ad88dc23c813dbf77a102ae5 |
|
MD5 | 7569999241c405a380493cb6088dd68a |
|
BLAKE2b-256 | 9c808a3807e164ad21e141e4ffea1d58beec6d193a738a704587cf5954ffbb0a |
Hashes for cargo_zigbuild-0.17.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b25661109f039a399e366df5429b644631e63b72f5b6ed4381db9681282fd6f |
|
MD5 | a055449a1a252551eba835ad450bc3c9 |
|
BLAKE2b-256 | 32d0897ef4832eb512026386c7f964c5dcd67efe02e5c0d0c425da4159906ecc |
Hashes for cargo_zigbuild-0.17.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc36552847cf36afa7818b3607a1d05ed89d477107b01c8f87ac562879d8d6c9 |
|
MD5 | 05669becd9ad0ec85e9ae3aa0f9cfeec |
|
BLAKE2b-256 | 5d041001ff2cde75ed7df3ffac2425ca551f503613f4f471d93cd3aa1cf86c4c |
Hashes for cargo_zigbuild-0.17.4-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56e02bbc839a3c795af64d3fdce73280b37c52b2602f9d472509ec38b959413a |
|
MD5 | 92c408926a81be2eee2d4eb9a7c24401 |
|
BLAKE2b-256 | 05535d8ed42f727b633feb7e48d206351782a410c3c800c0636151e6b54dc530 |
Hashes for cargo_zigbuild-0.17.4-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8e39a00cf49ca2820fb8481e270adfb0e4915045619962f2b9a59ccba8911d6 |
|
MD5 | 1f3051c4a404bd67f243162781391db2 |
|
BLAKE2b-256 | 2a87e9fa714dae510386f2fec9ca5102a10afc551d5b60bd33160929edccb0a2 |
Hashes for cargo_zigbuild-0.17.4-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ed937d75e92a31a363e64f05ef3c1739bb71c5de238492da96b4e865c045ac7 |
|
MD5 | 0ab2441531817080fd9c9b19faf6472d |
|
BLAKE2b-256 | 61d0e7845d9e556baa2dfa8e74238ae29786b1ff9823042bdbe059f920931626 |