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

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. 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.12.0_beta.2-py3-none-win_arm64.whl (607.6 kB view details)

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.12.0_beta.2-py3-none-win_amd64.whl (634.5 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.12.0_beta.2-py3-none-win32.whl (598.5 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (675.5 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (701.9 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (753.0 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (788.8 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.12.0_beta.2-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.4 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.12.0_beta.2-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.2-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 1e02ceaeaba570749c6034251af23ec8807f369f3554a72ef4534857367d05a2
MD5 f383d4634129ac7ef959bffce77b83c4
BLAKE2b-256 430f7821319c040e3d020753430123ac84d9d9fd58f4bd10b4d5842e156c403c

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.12.0_beta.2-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 fd197c92936cfaf269ea8d5c1f9ed331d5cfa991c907de112e32e1b466fc1bec
MD5 8accd86fc7f10bd59066f6e1555435bc
BLAKE2b-256 e107f8071bd8285f6675169b81ca7f346d9a2dc1b25ff10d7d41745039b8bcdc

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.12.0_beta.2-py3-none-win32.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.2-py3-none-win32.whl
Algorithm Hash digest
SHA256 0e38930d057b4052cd55104132d875ec1adc91018e9043187a5a351b003cb8b6
MD5 57a87235836a5f727f4f0a383ccc1971
BLAKE2b-256 271604b200d5183438aedfe407dc659dcfe1e83df6ce0b7e08adc53ee9f0b28e

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 7e37f09ee1ca7d8c222484bda32cb938834f468399adae3183e9cfde000f751a
MD5 6c975a02444e71b701d5b3946a56a2e8
BLAKE2b-256 492384eef74d99b88f017c603d8d7be3a86ad730dd2fb1293c745ddcdcc8591b

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 55102aca95621db06eb2d629b4cff45b8b31c3465a4b13a731f30814193361ca
MD5 dd95a3512c0d66ee3e8e08faceb13e16
BLAKE2b-256 866eb85f837d5a90585edd5346b7b80c2466dd2694dc3ba64d3f1598368b0c99

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b4c251b6781121e24b51b7b671f314dfb05cdaad95cbb07c0aaa1a6366af499b
MD5 c9e2b7fa4022ffb5cc2b81c98ad8a0fc
BLAKE2b-256 c94ec39c28451c0d1b4c7cd0824f7c8904b0f777951a508c4df1e91a1e846c5f

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.2-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 57dc4fc0429f77006c0155e12049d8b008df6dd97ab9d690a6dbe9bf9451cec1
MD5 f159294ed0d7138bac2f1a76d6b926de
BLAKE2b-256 7dd7aa4caff7b9688321a818b897acca3c2c8ea14e9a84cc8855ae9f62cba269

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.12.0_beta.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.12.0_beta.2-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0c55cbd0fca0a4aa55425bfe54d44a9cc634c152d53415f06e70a14c568edf35
MD5 9a1fc04250a68f82594361b1e12c29cf
BLAKE2b-256 1b9884a2a40906a81dda9eef56b62f8e510c37fbc7569e6790e5d5115d18a256

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