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 - zig misses some
compiler_rt
functions that may lead to undefined symbol error for certain targets.
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.5-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3b68ed8b7ec1fc87975a3e6cb8787316cc50188069be53b90b623d306a59020 |
|
MD5 | 8f6626307c602255e65e48215276b634 |
|
BLAKE2b-256 | 1abbc8eac304075862719b829bc91b7412e799b3d9a66dc6f7508eff59f844a7 |
Hashes for cargo_zigbuild-0.16.5-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8671080e4bcf1336db2777ce5c6136f9123b98ef5e0b73e555cf4d678a072645 |
|
MD5 | 9b04f40891a0bd6a87d75674bb43cecf |
|
BLAKE2b-256 | 3b91a1bd1719f6dc37a3e0636cf1b67bc86923eeb97f3c65acda91edb075199d |
Hashes for cargo_zigbuild-0.16.5-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | beef1e76995d5201dcff2a0ebb5bc878168d03f5dd3dc640588248e6742b43f5 |
|
MD5 | 161859d5e6d7d1b07c63682da53ca7ef |
|
BLAKE2b-256 | ffedb672d23dd9b7f864a2fb5b8644d4d825fd987803fea6cf5624c81f44b888 |
Hashes for cargo_zigbuild-0.16.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5ee9445c7f067e17472418e836cd42bd943b29ec9558133fba953e5aa9fa04a |
|
MD5 | d30fc75e040164478539a87b3bf8789f |
|
BLAKE2b-256 | 6bf78e6bcef9d92343f4e771c2042da7e15131225de53550b61c817edd15f034 |
Hashes for cargo_zigbuild-0.16.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e061b082b4965581c791f0eff73a5e7d91b5453992869a731356c4b1f8b022e8 |
|
MD5 | 7b3a2cfe36750e78b199dfb3ca8b0434 |
|
BLAKE2b-256 | 795fe6f2d2814e7ec70df694b172cbd7afcabfee1e1ef59e44fd2079e98fa16b |
Hashes for cargo_zigbuild-0.16.5-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 490e5bab4f027e84763b78aa989698c5c3effc2a9be78a14c8f02043c174f73c |
|
MD5 | eb5e0f8f25f1452f944381d887e701cc |
|
BLAKE2b-256 | 7ee4cf986f344a98a4c7f638ba05ed9ab1e5280e6d7f0d880e196f120969bf24 |
Hashes for cargo_zigbuild-0.16.5-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 674816d8c11a194c4381f452f0dd81e6c24f63c388775cd52f6dd6bd5b0fa967 |
|
MD5 | 889c0f69ac41c83fe655be07e461fa51 |
|
BLAKE2b-256 | a2e18b1aead7087b75319ed36cb7ca19cc74eb8f384b82a22ce14f9b1e3d7054 |
Hashes for cargo_zigbuild-0.16.5-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7250049dd83d3b34707a2a5162c74421529e30d0e944a783a24c3570dc15d51c |
|
MD5 | 354129fe510473611a63eba456587118 |
|
BLAKE2b-256 | d4097456e7d054cdf592839cb9da40a28a9794ebc59a6667b2b6859b2514eaa6 |