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.12-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c2c19bc370d18d4355b6307ec898c09d8d5e86f6435a95bd68bcc7d060e862b |
|
MD5 | 822c7c7ea08e82dfcd1ea4627b4404c5 |
|
BLAKE2b-256 | 415d482c8fbfebe60c9ae87edac0040caa9e57183c352cedc7c9d25bbb1bb0f4 |
Hashes for cargo_zigbuild-0.16.12-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f7cc790f1af37797d430592f89fd9811995ff58200f247cf0a899ac9b8b2cfc |
|
MD5 | 44eeee0cb922d0f075937b0109957df2 |
|
BLAKE2b-256 | a995b1c02e148bd942367a6d3f8b3a0943c987c49decfbeab97c98a3976b7e44 |
Hashes for cargo_zigbuild-0.16.12-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 217af24737510acf61994c1143c1fe5bfe3e5834dea21ff75683facae1f4025e |
|
MD5 | ca2e277fb45eca13a630c5aba9f4a2a8 |
|
BLAKE2b-256 | 082f8c82a0bc17ad957811ec419ea764762ad7e3b4891db8df6392cea1a743fb |
Hashes for cargo_zigbuild-0.16.12-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1df89ebf5a21d1d80211278d4a1ec199001ff9d85dce328bf6013cfe4f46b55b |
|
MD5 | 7f3f7f5fb7dbfa9b6f81b5b79a718869 |
|
BLAKE2b-256 | 8da2995fafa36f7d46b1d98dfecf760f836a897549d18f0f347387db4098d027 |
Hashes for cargo_zigbuild-0.16.12-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 142ba3d3e0fe5f5987db6e70b4a8dca538854ae1b05820fb3f57772dee4a854f |
|
MD5 | 43d0f904bcd03e7be64de9d2263f874f |
|
BLAKE2b-256 | 66d539e6c5c4de793768e9f8ebb2d1470cff3f2d30281c78b2ee8705f31f81ec |
Hashes for cargo_zigbuild-0.16.12-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a3d1a91a98fdf53c71211a43eee31194a9adee4ee5ab600d227d3561c5cad8c |
|
MD5 | 22cff92c5c580043d640e77a21baacff |
|
BLAKE2b-256 | c87eb695d8c22d8d0b442f61c3a19eae50729976959028ee9142747aaf0ece42 |
Hashes for cargo_zigbuild-0.16.12-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 646de1449424c6ef9908d89c5981ed4583b1ce8d90637c27f150ccac6e83af6b |
|
MD5 | 0e23140dd2c285cb630382153fe52ac9 |
|
BLAKE2b-256 | 4ac5f8c04a3be77354f6f91e73757eafc6d66de67bc1f71124e7777dc7215dec |
Hashes for cargo_zigbuild-0.16.12-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 395bb9f496f3114ba8442e2d0ad19313a3b98868bb0c9b0aed85134634870b7a |
|
MD5 | 50f1143f69a506cf026bfe444706b37b |
|
BLAKE2b-256 | ed3e94f6818a22b6d4bea0117efa77dc736a7672efc4d0e24d7cb458a229da76 |