Skip to main content

Compile Cargo project with zig as linker

Project description

cargo-zigbuild

CI Crates.io docs.rs PyPI Docker Image

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

  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

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. If the --target argument is the same as the host target, for example when compiling from Linux x86_64 to Linux x86_64, Cargo by default also uses zig as linker for build dependencies like build scripts and proc-macros which might not work (See #4). You need to use the nightly Rust compiler then cargo-zigbuild will enable the unstable target-applies-to-host option automatically to make it work out of the box.
  3. 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
  2. glibc 2.27 or older: fcntl64 not found, but zig's glibc headers refer it

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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.8.4-py3-none-win_amd64.whl (567.0 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.8.4-py3-none-win32.whl (538.0 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.8.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (610.2 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.8.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (615.6 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.8.4-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (670.4 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.8.4-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (703.3 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.8.4-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.2 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.8.4-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.4-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 08381c8fd164c91533333fb97ad7db4b54f111ef1434d23441dd18c8c81ba20f
MD5 8e6bd6a3c2b35b6f868334a03deff5f0
BLAKE2b-256 55d2fe50c50bad643264ec67f5d9e21f71c8114def10802890e4e541ea12ec34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.4-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 b2d57c36a5ef5aa5e83fb4a48ffb902887e13ab0d752cc7acb1b49203a8f66c1
MD5 947fccd03fd4bd790f47f520a919fe24
BLAKE2b-256 ffa347593e9911f2a69e8402898cd72f41178897151127d888beedb8a0387ea6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.4-py3-none-win32.whl
Algorithm Hash digest
SHA256 fb4c53b0b27db0e37d6b9879cbaf8b9ab11922e784b267c423562926872d3645
MD5 a7b15ca9795233982bf0391de63e1dc9
BLAKE2b-256 4f8068c9df95890955b04fe0b9c2fc5ba9d48dd05ab41169ec6b23868136e348

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 a19651166f409a6bba4b3227586f3678dae258d28d9c41f3c8ff4a847e633a4c
MD5 1856a51da6023acc2680a762d5f4ea74
BLAKE2b-256 1947df92e788fa5f8d96f604a9a9075e9783709b68bc5bc0361d105df8a2dcf0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 96b122aa01452b4586da016cb6a47b88404519199afd06d0bfcd512ca39e1651
MD5 546299d4432bb8d14c1fce763a74d2ef
BLAKE2b-256 35f099c61310b1037636012c3afdcacf20561075ab49fe368d2caa57ff055f7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.4-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 18cce5240d3010eb99e1eaa29f0b4512bfc9398ca3f2aec70262765b1f6949df
MD5 acd638cf8355d3e01f6fa5b6c8f8f668
BLAKE2b-256 6b196613ee164649050211aae6b74864eb7cc00be9fc8ac362f07e18cc290ffc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.4-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 529b71ee91466ddd89ead8d675209ba5bb41d23d5f6b70f0d7f745209f2ff198
MD5 0b61f858ca9d0371c3bee3b20d2dc8c2
BLAKE2b-256 118cc5348b78cd4bfcb3f15da00406f30bd0a104eb9fe66ebed240af7aebd3ed

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.8.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.8.4-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4c6ed17769a8b0dbe541aee0781319391c18e5342fdb96515b5766c1d3100399
MD5 ae533c2751daf57c4a8b61e7e2690847
BLAKE2b-256 80c3477f2d8fd7b0645938e39fa6f5c23a3b72e1bc2b9c3a5a999b328218b4f3

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