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.2-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c476cd7c4dae168ac8f2fcd1b8e0d897a30abd81480db69f8d52e5f7d968f8f0 |
|
MD5 | 49543b6e6c15f26b07c12c900428edc9 |
|
BLAKE2b-256 | e6eea8079dc86eebc84e6538164e0fb006f2ca5309e87f200a33fd72318e3a3c |
Hashes for cargo_zigbuild-0.16.2-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dc16766d448396e189e21bf3172830179f0b90a18e6f3a5ca1a236907f9ee9a |
|
MD5 | 470094cb02ae0f166cb3bc379f4f0ea6 |
|
BLAKE2b-256 | f05480e81e7e25d18d8cf66f8c3f48573d9af5bb0634891f6cafc07303284bde |
Hashes for cargo_zigbuild-0.16.2-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbb8c7239d54ee0e9c1997026d885ae436130f4dacae96baa12534ee624298e1 |
|
MD5 | dc8ce163bf5389c981298e53723aac4f |
|
BLAKE2b-256 | 749aba1fdb04ae6538bd6d0f297665b31ed772fee8338917102d5e56a19fa5c0 |
Hashes for cargo_zigbuild-0.16.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54ac95fe37ec552f955dbbaff2e09d875818c22ed95bfa0cf83b1b75f1c0c8fa |
|
MD5 | 17d4b64706f69c8733d00bff1cfbdac1 |
|
BLAKE2b-256 | b86f284da9de1c6d4b867d8ae972dc5f173e0fc42a34028c56bc24f97b827001 |
Hashes for cargo_zigbuild-0.16.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 983b8ef7d657b95d10e9e14a47b310238252587f7ea84373d02e63f142a9be1a |
|
MD5 | 5122ceaec134268ae3fbd8e8c2b4142c |
|
BLAKE2b-256 | 3c1dbadbe67c52538cffe05b83c23e6e78e1b25ed19c1f690af6001419ff23a3 |
Hashes for cargo_zigbuild-0.16.2-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ed41e8b78d00507473d8fe32be5002d025a136e082d37f5b87a9ef8fb449a81 |
|
MD5 | 2a1b6f58427f9ec5e422a627f80c21bf |
|
BLAKE2b-256 | 6cea078bf681b05dae65fcb1dd7fef0797d7fb94a5b5b1c1349a4433523f1599 |
Hashes for cargo_zigbuild-0.16.2-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7637546adcdc8b645f576621e810957cfed8f11537a9a8138eeacf8f1d30de4f |
|
MD5 | ea6f927ccc132c475a1b8ffa0409efc2 |
|
BLAKE2b-256 | f21aa10941b89ec8398c8cf30c98ab9e48843e6e2bc595102d515685a39165e5 |
Hashes for cargo_zigbuild-0.16.2-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f812aea47892b906ba261d6c9ca55b34ce20437d9e568d30518617291655d10 |
|
MD5 | 49b65d5236e122f5927aa8e7703b1b60 |
|
BLAKE2b-256 | ead401a445db671ac0b91c169f7ef02844b0c34febc24ca1a3a34f0315142a20 |