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.16.11-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0506606ab0b8e0da345498ba45846e64997f8df7be3ffeb87bfecdb01cfc24e7 |
|
MD5 | 4ade6aafc1bd915d6dc21135112ad3e5 |
|
BLAKE2b-256 | 7cc28a354a56c8282a8d7fdfc7fe0172489f12efe78bda895fe675c12a6d91e1 |
Hashes for cargo_zigbuild-0.16.11-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73b822cf0d27646bced9ea27c54f3775ba870d2963a6971eb3eb6dd2efef95fc |
|
MD5 | 47959f95787e073b6c5a3d0516e07ab6 |
|
BLAKE2b-256 | 7ae3a6ba386a94761219e665788bdc7f12181a294b424b28993fbef7bb8cbe62 |
Hashes for cargo_zigbuild-0.16.11-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5846c1d045dd19b6bfd76f9fd62e92bf5e20e0e77309e3b2d5431b4db73e78d9 |
|
MD5 | 288306ec05bac92623d715398f63a8d9 |
|
BLAKE2b-256 | a860de9bc8bfeb790e5f25537503ad103005a27fc8d94d8b506296162acbeaef |
Hashes for cargo_zigbuild-0.16.11-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad81d1eaa8faf5da76c2d032ccacdebe96a279124c1b558f38e190b186602d81 |
|
MD5 | 0801b9e6143f6d1e40df9ea83850ac94 |
|
BLAKE2b-256 | ba5b1d61b57a54fb9e14d7c5b016cfb281e3006acd5d3e0596f3a5ca329cf213 |
Hashes for cargo_zigbuild-0.16.11-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd9efffedca92efaeaaf12647da71a645e2ff551130c04a74f59d221f96f7286 |
|
MD5 | eac3ab4e7cb23aa0c76a0e96cbc1729e |
|
BLAKE2b-256 | 3388df819daa6d93f561425026994795f4a14ea7762c954b918a6aa727ace1d9 |
Hashes for cargo_zigbuild-0.16.11-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54e64cadb30186ba00ffc3dff1287561041d193f51e38a4a0beccd74fc5bca57 |
|
MD5 | 6e30358ff88d30d3ef9a0a05240ed359 |
|
BLAKE2b-256 | d40391caaf2c1f894015f45fd73679c35abaa5e0d669f3729e092ad6f2cd5f4f |
Hashes for cargo_zigbuild-0.16.11-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 748442e3e3481e72bb26152a7c1e8dc0e29db3931b9e04bb1af17295354cd9fc |
|
MD5 | b47d57016e15c748e0f7c94d84c06dde |
|
BLAKE2b-256 | 4415c9685e0c1357251a89332abfbf5e5d1df312580bafc6b1538df9db585fe7 |
Hashes for cargo_zigbuild-0.16.11-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43b783c61c1ffb81f29df9f1fa765c311d7316dcae80e388adf379f6b65dbabf |
|
MD5 | 2f1f0b4b9b84db1c6212ce6f9f11a6fb |
|
BLAKE2b-256 | d980afeb3021b51a800a8a87cc912061da4e79cda3d1a1ecfd7d86445a22bc69 |