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.
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.9-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81925858ead1197ce9e7f28b147a6eb8ae73b002174b6609cac511139bbca152 |
|
MD5 | ea793dc90b7f2c672516b904ea21835d |
|
BLAKE2b-256 | fbf3d320c289fb41d5148ca0e2d2153d5f371bae8a2e4181e5c880840e3396ba |
Hashes for cargo_zigbuild-0.16.9-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6f6da76aa5066e94c0a843a887eab00d1a69e1f0a1a8e7de57901fbc748cadb |
|
MD5 | a7a7cae19db92f9c19014d59006151e8 |
|
BLAKE2b-256 | 606772955aa85afa51878cc2a71709e632482e4f6954d8a87fe6839cb9bba5ed |
Hashes for cargo_zigbuild-0.16.9-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15a617714c1cf3e096f4d1f8950c29b30631a491cca152e69078ed4f006fe50b |
|
MD5 | 924b0897436c9826a7386d73a85940b0 |
|
BLAKE2b-256 | 0353244076f5dc36da9608f7cf2b432ef77c524dfa67708bcf02fa2b56124395 |
Hashes for cargo_zigbuild-0.16.9-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22d40513d85383a9174b0162398380bd581f02394229e9bfb528adaf1fd1da7a |
|
MD5 | 070b0d41218cfb8a71ffc78a4cda0dae |
|
BLAKE2b-256 | 9de2fa9aabb1812301f2d53f548fa8128dbc6e62a2a1d5bfca6c04d5879c1493 |
Hashes for cargo_zigbuild-0.16.9-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba2daae2fad9ae1da741ffad1034aa961851371aa5be46103d2f0da0584a98c9 |
|
MD5 | 533c71586d60d7b28f869e849273684d |
|
BLAKE2b-256 | f62275319af057703bcc0f85f19b8bf6746f2ae3052b6627d3081a89297903ed |
Hashes for cargo_zigbuild-0.16.9-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a0ca765a5d665f180ceee1fb11e7753760ffb3a79810c9086957f77535f291f |
|
MD5 | 804c37cd67d4e7827990dfcef24f6e68 |
|
BLAKE2b-256 | 32879d051a2beeabab2806587c5156ffd4bf070bfc2ce43556d439df62289236 |
Hashes for cargo_zigbuild-0.16.9-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f62a63f7029cc792496e2e2127e8fe39f784fc8aef95e1e0131adf64b2ea2403 |
|
MD5 | 4892d5ef72a7c4f8c142f21e2f9ccb04 |
|
BLAKE2b-256 | dd47bde4856e65802d29f82665f39fccd0d1330eb9894881c6a8423a277848db |
Hashes for cargo_zigbuild-0.16.9-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a615258f116baf59f859c7b03c1a15b455ced27c4f5fa8042811025b0d2f7127 |
|
MD5 | 6fb7e09cfa427c1a0e57951d96cb53c4 |
|
BLAKE2b-256 | 38295d62cfaa6e13d37626204b7c5682ece3ff11376cbee72ff782e14f9b0eb0 |