Skip to main content

Compile Cargo project with zig as linker

Project description

cargo-zigbuild

CI Crates.io docs.rs PyPI Docker Image

🚀 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

Packaging status

Usage

  1. Install zig following the official documentation, on macOS, Windows and Linux you can also install zig from PyPI via pip3 install ziglang
  2. Install Rust target via rustup, for example, rustup target add aarch64-unknown-linux-gnu
  3. 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

  1. 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.
  2. Only current Rust stable and nightly versions are regularly tested on CI, other versions may not work.

Known upstream zig issues:

  1. zig cc: parse -target and -mcpu/-march/-mtune flags according to clang: Some Rust targets aren't recognized by zig cc, for example armv7-unknown-linux-gnueabihf, workaround by using -mcpu=generic and explicitly passing target features in #58
  2. 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
  3. zig misses some compiler_rt functions that may lead to undefined symbol error for certain targets. See also: zig compiler-rt status.
  4. 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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

cargo_zigbuild-0.17.2-py3-none-win_arm64.whl (886.0 kB view details)

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.17.2-py3-none-win_amd64.whl (926.3 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.17.2-py3-none-win32.whl (866.4 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.17.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (928.1 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.17.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (962.1 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.17.2-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.1 MB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.17.2-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.17.2-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (2.0 MB view details)

Uploaded Python 3 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

File details

Details for the file cargo_zigbuild-0.17.2-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.2-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 c6886930a63681496b23f26abc8999cca8e497720c4a512438ae5bb87ad0a484
MD5 e61311093410703a2b54f7818aa18324
BLAKE2b-256 3601ee45f880b78c228a74e4198675deebe614697ebb22c3397724ec555e480c

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.17.2-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 fcf37d5ed48fce10b6bcc3c26992f01c6f1919d2d4d72d6b8ee9309eb234d13d
MD5 759adcc615c6623ae59e1fd5f11b87ea
BLAKE2b-256 90e570780d96dc7dbb1e4f48bd8d636a0817499935528ce76e22b6099764518f

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.17.2-py3-none-win32.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.2-py3-none-win32.whl
Algorithm Hash digest
SHA256 6bd3e33bc59064261e181e57b1f4bb94c8484cb73397af77633bf6437361a01a
MD5 4b8774b6f939088ad7013228610e8e7a
BLAKE2b-256 1f4e782c751a329a934a7d8304963320a6334b35e0482f8c0db1b7b4bf84f58b

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.17.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 91b7dd69b66785e29ea80b65e134da97ce5509345d8c3a5b2099e42d705e4331
MD5 7ac2b11aeba1dd8e1c340ff9b3284155
BLAKE2b-256 882ce539e93393e0003ac798da075d6e24a0001596b8388c8c4936b542085460

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.17.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 92fb59e10e9901e69548b99b1fed34ef6f2baf311a4e1c5d12771a156fcdb40b
MD5 fd462d463474df1d8c2083cc1aab6e36
BLAKE2b-256 5d17bb0def7339f8c63d6e14086a9641dbb9fa993fcef55be13be6351d5e52d2

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.17.2-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.2-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a9e528870f0e8a25d50902595a02e261fb4343a1ca35bb28077acd13e5b79f16
MD5 c0f85056266b2e8999cd327f057db452
BLAKE2b-256 a7bc087e78b7cb2af61ad3bfdc1ea7ce6cdc6775732b06db3e0c2e0f1e3df7d7

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.17.2-py3-none-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.2-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 fb15cd441143636fd06492d49725fb3ab63c0cb7e7181a280f97ff3bf538112b
MD5 039471f1ae7cbf671660a461969544b4
BLAKE2b-256 884679741c2589ba7c7a50b150c985cf50b0e24e0b5c5b0c542b330c09a35352

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.17.2-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.2-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a6bdb8b49ba97e3bd26991eed9f40149b401a0adce09f9306acbbce098872e84
MD5 c145c7065246ca698c77453058ced8e0
BLAKE2b-256 a9eaea392b6d796dd35fe41168f8f61554839da1799c874d2e57709f915a8ed0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page