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.18.1-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d137b7771341c69ebe09c7a0ed077cf39f5186976773c9256987dc7efd3e4392 |
|
MD5 | fdabc19b4fb2fe08e47cb0d0b65c1a75 |
|
BLAKE2b-256 | bd239625747c361f2825452a62db65a582a5f8c0e99b651290286ed055e63991 |
Hashes for cargo_zigbuild-0.18.1-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed968fb11599b101f348df2a11b6df016a6f2d7fd8a27d926765b2be76fa91b1 |
|
MD5 | 6fd7270fb07b4f5bde61bfe896dee63e |
|
BLAKE2b-256 | 6626551b9f4ecba5f3ccdb1b70297a0b0b90a71a633a33493ed4484c03dc2cb9 |
Hashes for cargo_zigbuild-0.18.1-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8eb4fbbfb85723315187e23c568ae915a023067008e5e5ac8e42dff98ad0852 |
|
MD5 | a8230df7f12f4b662a8932897d223cff |
|
BLAKE2b-256 | d294460d3942df2014aca3cac9815d06c4af15f7b3403c9acd57ce6755c75e5f |
Hashes for cargo_zigbuild-0.18.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e975ce1bb4b3435b89c7d5bce1a8483b6b0f089053e3ebaa0e82fdaf6bc7414 |
|
MD5 | 863c8f23fc37001f11691525b6d757f8 |
|
BLAKE2b-256 | 17b39a74d9050c417351d046932d35b687dbb92b68ea727c96db9fd10b1436ee |
Hashes for cargo_zigbuild-0.18.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0c54d5a42fd13998717cedc8985a6698effd97c86c49d022ffee2a0dc6e1974 |
|
MD5 | 862a68616fbbe23ef6560556357a1557 |
|
BLAKE2b-256 | 0bd2cd54056c9ee1c04f39539ac53aebaa693b37ebd4f58fe1fa99e78db51c55 |
Hashes for cargo_zigbuild-0.18.1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecc74ca3c951fc316bd0f349b1f54fbdfed11c00ce1c0b86ace54ef76bb12164 |
|
MD5 | 2e6ecd73c2ef0c9da734bf0a287867df |
|
BLAKE2b-256 | d4a23265000b4b05d516052987ee3d9a6fc5418108a4b9ea35ba2e02336d434d |
Hashes for cargo_zigbuild-0.18.1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c450be41b65fde9ba4dc8d5dfcbd0e4c7efe6a086342ee55ee8d41ea751e8d67 |
|
MD5 | 74839be1e6c0c70d8782d14f9e7b3acf |
|
BLAKE2b-256 | 1739482fc9db46d067ec69ab292221e41c541514af9badea725f32335803d4af |
Hashes for cargo_zigbuild-0.18.1-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bda001aca41f9885bcdb1abe6895cc9bb339a65c56c10f1f43c08f526f1e5621 |
|
MD5 | 211a5ff211b2849fe7f5393c7d0d609f |
|
BLAKE2b-256 | 9ccafe209e7de2ce33fb7f92257bef1335d1443da8312d100d0fe5378b9d64e6 |