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 - zig misses some
compiler_rt
functions that may lead to undefined symbol error for certain targets. See also: zig compiler-rt status.
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.6-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b4ea31ab3c9fa1839f92c0730850fbce64d58f74632e7a524cfb55c52f9a939 |
|
MD5 | 74681fb3d9e145c7469e133482579f22 |
|
BLAKE2b-256 | 2d184d8d3c414dbec85c84d424c0eb08e0183ad01ee11f5f50bbe6613b7b34c6 |
Hashes for cargo_zigbuild-0.16.6-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b12a15ecc4665a9940ec6d8aa6665263c8d877cca38db5e66b233c3f7a63efe |
|
MD5 | 1857b8cd8fc9851c3de91562b6a3b239 |
|
BLAKE2b-256 | fd4e2146b49380f0ef10436f222997cb4c1f3c035eaea720e776dab4226d72d6 |
Hashes for cargo_zigbuild-0.16.6-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b771deac211e6a329c1c902cf39f36f82f7fa554d33e67a8323d4b205cf8e637 |
|
MD5 | ad044b956e1533e400a011fae3f84573 |
|
BLAKE2b-256 | 60261955b354d12c7e3579a2c929d4eef2cb3af54dac06d940bc9b112243976d |
Hashes for cargo_zigbuild-0.16.6-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffbe6443ad6ea3b0e890696940a9eeb64ac91b4c223943f75c5d2a9e387097f5 |
|
MD5 | 567bf6026accafd5ce336b5fb4681a6f |
|
BLAKE2b-256 | 104b0fdce14a1d2c669767035d38a3908683ff68b8e7b30ffa8a569ee50b0ebd |
Hashes for cargo_zigbuild-0.16.6-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3808b4bd9967630d466862d12a5d26e9a7733b8027636311c465accb8ce65be1 |
|
MD5 | 253932b1eb84688d36c05326c1daadcc |
|
BLAKE2b-256 | 09e266762721b0ba2abe5de7984eaaec12ace94ac66f2080e38ea50f3b26f645 |
Hashes for cargo_zigbuild-0.16.6-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2be236eb31f3ed4a94750c6ae876c01061967069ca3a30f2c4743dcc59e039d1 |
|
MD5 | 4baced51fdcba79f948c72d3adba6e92 |
|
BLAKE2b-256 | cfa8fd59d6938d789ee0eb8e0eefc1b4e98982033b91a84b7c373b5ec258d00a |
Hashes for cargo_zigbuild-0.16.6-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13b290562d71c8d2182897e78865a1529a36c5f199b42b1b89e353f0c624fb2b |
|
MD5 | c46fdcb4633ddf1557405a96f68ef382 |
|
BLAKE2b-256 | 60964bca06a5e274f4d35c9a03b390624aece5a28090aca061a6e7f0a6560a2e |
Hashes for cargo_zigbuild-0.16.6-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a117798bbbf9715b7e773c7b4299c6cd6c898c5cbc455fc90ae1c4b8fd66d1f0 |
|
MD5 | 68c2eb610f2a06e4260ffe2e2a13fe30 |
|
BLAKE2b-256 | 4f7c52b70ed5968751545b5371dfe0ac9420d487a5c7296053088eab297b354b |