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.3-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04776c1276b6e8657e25e94e3295b09f0270444b00f558e0945fc229965860d9 |
|
MD5 | 9d3d436dd7102a7574d26a1bb6cd2835 |
|
BLAKE2b-256 | 4fbf67763834c9627217ad22de4b6ac4ec3d6b0e525d20a4c6d57f92cf1e9cfe |
Hashes for cargo_zigbuild-0.18.3-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 109b641175436c36d52ebd1163fad0615fda83c1833bb15051a079bae8e34a1e |
|
MD5 | f5337b20cbcd4b252f9a7b91f3a474ee |
|
BLAKE2b-256 | 39cef6a807646919ab4a3134b91ac08b1afbf6aecc90bd2f228eda4a1e33b924 |
Hashes for cargo_zigbuild-0.18.3-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57671d96508a79b90e70056ccfbe12fe6f7faea29dd2a68476e34e77f79eb3e1 |
|
MD5 | fc18e6873fbfba36a1037578109e3b1e |
|
BLAKE2b-256 | 71c9f6cada85b1aa19e4470d34d6a42a34b811ce201b2ae5b802542d27b80c6d |
Hashes for cargo_zigbuild-0.18.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f1cd146ad255ff9f85aa77d86f97e1f9a0101e9fef63f3b8019bd66e41777a0 |
|
MD5 | 489a975560a18087d36d73e8fc6e542b |
|
BLAKE2b-256 | 033c61f7e021b1b29d6cdc3958b3fc12c3c6ccbc9310ae214ebe33aa494b87c0 |
Hashes for cargo_zigbuild-0.18.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb7f4e63f58423a68da138336bc1fc1cadb2a9700a3f0b66e7f01e399bb0cc1b |
|
MD5 | 609afe8d0e255975810d257f1b01f780 |
|
BLAKE2b-256 | 16992c88fd940e2ebd3a783f7a010624002947d121f09986365edb32e81993df |
Hashes for cargo_zigbuild-0.18.3-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b820d049463a5cac4a07e771ee2df252b901f86ee11c6c36b54d34540a15e198 |
|
MD5 | b1225b76a9abc733fcc2b15d57e380c0 |
|
BLAKE2b-256 | 3299cebc25d8d72da2dbe0be409bc20f57171f8791745d4497cd62b2fcb68a88 |
Hashes for cargo_zigbuild-0.18.3-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a11fb4d49e753fe033008d0312ce48a8ed9ab6ecd00986da087c8615d236105b |
|
MD5 | c5392901ed8eadd04e2516dbecb89de4 |
|
BLAKE2b-256 | 9654d2362e92f56e7cb3511e890b206309c6d96edb0a52ccf0cb7e4232a9d11b |
Hashes for cargo_zigbuild-0.18.3-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04992485fd2bb0498f22cb2a3933ad4c604017754b2613f1926bdb604d7c0a8d |
|
MD5 | 6430a6101aa4291d8985bd8a8bfd15e9 |
|
BLAKE2b-256 | 24d850d92026c036e872dd959b93e41d7efe9ea95204dbc62e0978a1900c0e4f |