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.3-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3e38c4f787de005e8df52408e8b0608f62e3b49d2258bdf94ad17bd068a9ea5 |
|
MD5 | 746131bb7fe19fff5c43f9f5410d8be0 |
|
BLAKE2b-256 | bb9c919683850c5717cc33a1fdfb1e998497bbeaba60d94229d6fecfb1b8945d |
Hashes for cargo_zigbuild-0.17.3-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 170785e8d024c8eeedaab8d4c2aed0f22a8bc122b55c659ed1c9216f272c838b |
|
MD5 | c829263a1ee7fef82be5df60e1ce2f88 |
|
BLAKE2b-256 | 1ca352a2529eb1491ccc990a8af5fe8432e893fd1353119668f7b162e60b0e52 |
Hashes for cargo_zigbuild-0.17.3-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 426db8add47ff8eb882451df29d3d9c157cd2175e12706121d0d79eadf37d10c |
|
MD5 | faffedf684bd219a6ea598574fca5095 |
|
BLAKE2b-256 | 822288aa0e9016572322216ad7500e6cfbc95ad84a5dbb3859ee5f3c689b8189 |
Hashes for cargo_zigbuild-0.17.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9759a85265f06e9dc313e32df2f4ebf19c0c2a6bf89b2ac99c2ceb4e2bf5cfa3 |
|
MD5 | 66ee22a4cb713eae31c33000c9b16f56 |
|
BLAKE2b-256 | 83e560fe129283abb2adbde4fbf1c2638954a1e2a9aebec6e9ca699ec3ec4c8d |
Hashes for cargo_zigbuild-0.17.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 159c51622801a9572dfe9ed7658c47667ac66f04a5ff3c8af03210d034f32250 |
|
MD5 | 13e96b9f07b6e9631c2a629d985179cc |
|
BLAKE2b-256 | f06f73dac0cb2be974e6cb1bff7e4953e6b0147cf6074b153b0c01b8ca7defea |
Hashes for cargo_zigbuild-0.17.3-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8af4fa7f5626d21760caa7fe4123d7d34180a79f80b4a3d4c6a7c686dec0d19a |
|
MD5 | f794bca6ebea3f936d6f9ab3848540bf |
|
BLAKE2b-256 | 45d7449b9dc175a0682faadf355fb0acf23987b373157dc547129673f706173a |
Hashes for cargo_zigbuild-0.17.3-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50ee504d83c8521db6d54beb62eee714e2dc9d5d72450bcff3640c5d76d5557f |
|
MD5 | 59e4b8869bd3c5c99bf3abe795325703 |
|
BLAKE2b-256 | 50d091a213d2800c460badcced036e88d784726df09aece610b3f3e6afb44381 |
Hashes for cargo_zigbuild-0.17.3-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70e9bc44f663053cbe6e8395f5662712dbedcf48cf78d233258268a38d4803d3 |
|
MD5 | b99741db1f8e4d3fe5d64e1ead41cfbb |
|
BLAKE2b-256 | dd6466decda01c4b327e84647e1c9d9954a05d0971fea3568a9168298d4c2b83 |