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
Hashes for cargo_zigbuild-0.16.1-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c79ad69455af9e33a54aae7c622542306c66a911998b95c31b39f0f4a331117 |
|
MD5 | aa0cee9f7d7ecfe85dcd7a85ae09b204 |
|
BLAKE2b-256 | dfef962a0b7754c712a5d4750e591cdca94149a1b71d93ed787b5649c73f2436 |
Hashes for cargo_zigbuild-0.16.1-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5f77b429dcee8d8def6e428fcdf24bd073e7bdb05e085c331b1675d7befe580 |
|
MD5 | 3b9e4ca8e0d2867c48b221b431c0e8d9 |
|
BLAKE2b-256 | 8b5decb5eccaef3b07113b33621e0cd285065ba3a477e0d06daaaade03c27092 |
Hashes for cargo_zigbuild-0.16.1-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6727ac699e1d6e3bbdb7f8348c77da90c23d1816a0c07b7d2171569a7c59cb9 |
|
MD5 | 77408b467258a87eeab54d8160adde30 |
|
BLAKE2b-256 | e89996f080f224119a1053dba1c4681eba0651162f0996ee3b38c8bf8887ca20 |
Hashes for cargo_zigbuild-0.16.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b48380f79623f41efb019edc332aab0705dd4056ee5b17935e92421a02ac5375 |
|
MD5 | 3df5d0e735f33643c96cde7b20fdd4f9 |
|
BLAKE2b-256 | 6135cbffd50e6dce9b8529649a3b428ef8fc800b08b9f854689b460a669961af |
Hashes for cargo_zigbuild-0.16.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf7852b921f0d689b749561112c976d88088a82770c5ead9b196e75f8ea7e593 |
|
MD5 | 4b4b83544d101cc309c9e9a395918a84 |
|
BLAKE2b-256 | 6525062d5e5b1108abe3b7c8182d5ea3cf256e6a1dff0926277a3d0eb2347d1b |
Hashes for cargo_zigbuild-0.16.1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43ef5b698328b5b898d77e3faef8c10bb0125572b1f1864fccedb9c8e3f25d1f |
|
MD5 | 32aafadc37df45de03e33e2824a3adb7 |
|
BLAKE2b-256 | ef8feb41e72f7e47d426a7fefed1e7a41fef0b3707c10bb81b4b3c338d8e15e9 |
Hashes for cargo_zigbuild-0.16.1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d7cb888370104480d61bdf2645bb9003514eba8ef5203b74de27b05d845cb10 |
|
MD5 | 53b3dcb769501b281cee4cd1e073d591 |
|
BLAKE2b-256 | cebe3f09e35fdb7f2a86a9e349872ae9c3640b0e1eed63134f209a09dfd5d847 |
Hashes for cargo_zigbuild-0.16.1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43ec0165f22eb0e8262ab6b26f32fbc56d39e4a30cdc24a32ec9d05c80c2c08a |
|
MD5 | 2fa720f2b991c2dffe784020dd1482bd |
|
BLAKE2b-256 | 77999a618ac455115d3d3676ada597c97c6d6d2e5248ec9878f841ec942fa007 |