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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.17.4-py3-none-win_amd64.whl (906.6 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.17.4-py3-none-win32.whl (847.4 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.17.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (935.5 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.17.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (980.0 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.17.4-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.4-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.4-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.4-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.4-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 06fd3dadf4ced9c69f15d71a56afe1a9df2797dff7f10a088bdbe70b036404ac
MD5 8cabaef101fdca0f9a3fa1c398a40ce7
BLAKE2b-256 afea14f029fc9b2d113676b72309e1af9e94e063c04a8b00108dd954feffb80d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.4-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 93ae888d42ab81a462e32bfa53588b228f3865a3a7aa202f40d0236f3ea260a4
MD5 0d66cc1d683a66f2e6afaceb108954b6
BLAKE2b-256 a522d9288d1c56dfff3c361822cf81da70a7c2b00cfd8a06fcec8d21f0b091d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.4-py3-none-win32.whl
Algorithm Hash digest
SHA256 e0539f29122ca6731b92ef91888e4e96b98feb32ad88dc23c813dbf77a102ae5
MD5 7569999241c405a380493cb6088dd68a
BLAKE2b-256 9c808a3807e164ad21e141e4ffea1d58beec6d193a738a704587cf5954ffbb0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 2b25661109f039a399e366df5429b644631e63b72f5b6ed4381db9681282fd6f
MD5 a055449a1a252551eba835ad450bc3c9
BLAKE2b-256 32d0897ef4832eb512026386c7f964c5dcd67efe02e5c0d0c425da4159906ecc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fc36552847cf36afa7818b3607a1d05ed89d477107b01c8f87ac562879d8d6c9
MD5 05669becd9ad0ec85e9ae3aa0f9cfeec
BLAKE2b-256 5d041001ff2cde75ed7df3ffac2425ca551f503613f4f471d93cd3aa1cf86c4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.4-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 56e02bbc839a3c795af64d3fdce73280b37c52b2602f9d472509ec38b959413a
MD5 92c408926a81be2eee2d4eb9a7c24401
BLAKE2b-256 05535d8ed42f727b633feb7e48d206351782a410c3c800c0636151e6b54dc530

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.17.4-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 c8e39a00cf49ca2820fb8481e270adfb0e4915045619962f2b9a59ccba8911d6
MD5 1f3051c4a404bd67f243162781391db2
BLAKE2b-256 2a87e9fa714dae510386f2fec9ca5102a10afc551d5b60bd33160929edccb0a2

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.17.4-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.4-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 7ed937d75e92a31a363e64f05ef3c1739bb71c5de238492da96b4e865c045ac7
MD5 0ab2441531817080fd9c9b19faf6472d
BLAKE2b-256 61d0e7845d9e556baa2dfa8e74238ae29786b1ff9823042bdbe059f920931626

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