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.

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.16.8-py3-none-win_arm64.whl (840.3 kB view details)

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.16.8-py3-none-win_amd64.whl (882.2 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.16.8-py3-none-win32.whl (829.1 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.16.8-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (874.2 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.16.8-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (917.1 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.16.8-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (993.6 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.16.8-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (1.0 MB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.16.8-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.9 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.16.8-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.8-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 e34f7a6397e8b47cd52ab510dcefa32cdec369f60887a39ebf600d5ffba2c380
MD5 bea71b98d4c2fb32485f8d896d06be1e
BLAKE2b-256 d85c949797317e98f6fe186d68b316dd15c715502b09ca32090fbd14334e740a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.8-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 a909f08ce9895b9407b9991427621e521444880591dc69f735cca9b4f1127ee7
MD5 487c38c8571d4ef7297be830af98329d
BLAKE2b-256 dc3843b890a3f985dd77d425dab5c2741b355618506ef980a924d22d00b9fe4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.8-py3-none-win32.whl
Algorithm Hash digest
SHA256 8736d5135549c43a891a7d096f590f59a47055b99e40308220c8e4e315baf1e1
MD5 00a13fc36c8ef7491f3f8c0dd4b20444
BLAKE2b-256 85cb4db41349d238f966e2414cafd20c56b46fd3c8cf05c5e08ffc628d14edfc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.8-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 6c938ea5ac605997cf3bf531e0dbf86ef143604bf1a09762fcef2ca6e34d9d81
MD5 8ed5213f14fb095687bdc33050850249
BLAKE2b-256 bf2163663769576e0ff2b3f20f696930eb62445a93e19cc55701985c7271b22d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.8-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 401a2540c9b08438fae87e105b0f9a035be7b5a29e8243db09b1f3a7dec05b96
MD5 d3b2fb11e474465bfda6d821d9faec86
BLAKE2b-256 94b886059e9bafa519c2a1cfc781d85c5cb4381040558284f166f1239d748531

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.8-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8873c9971e990169814380d270cca19742670cd2f2fceab50b924e20077f6458
MD5 7e6e4ea972b34f691f629228fcf8dd89
BLAKE2b-256 606e08b69c028a32d436525c1401002513c0db3009a7a90f4c98ed20fd27d598

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.8-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 52f1bd1d68099ed6a9c8f7126dd998c642f8806b5188183fa7fbdfface6a64b1
MD5 0b0c95777f9ecec47fb6cd49951bbc72
BLAKE2b-256 65ab656702c2760c4dd3948fa7c4ddf75c40923bd54500fc6ab7d5b0948ec561

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.16.8-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.16.8-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3de00a385937950cebce7e10a6e966096f8668c516796a8f638c16cd29de012a
MD5 d88b00fd859797d3b6096e59b4141407
BLAKE2b-256 24cef57eeebc7266d7d205ebb2d05b9b2e1069d507ad9d3b020ab9425e2f4f8a

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