Skip to main content

Compile Cargo project with zig as linker

Project description

cargo-zigbuild

CI Crates.io docs.rs PyPI

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

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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.7.1-py3-none-win_amd64.whl (560.7 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.7.1-py3-none-win32.whl (532.4 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.7.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (599.7 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.7.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (598.3 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.7.1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (656.7 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.7.1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (686.1 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.7.1-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.7.1-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.7.1-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 889c6bf328a6690e27036b6bf0f58ab9aeb94b15c3d1047201dbd5226c26a51c
MD5 42ddfdea9204ca9591a40d795f209781
BLAKE2b-256 a0c1699b0f4601fef1e40516dde904397da77182885e6a1126abb2244bd9f3ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.7.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 ae0249dc908556460215e1519539573bccf44f4bb27e2ba859fa394c90651a7c
MD5 5c43b1af58b8646ba87173bce12da6cd
BLAKE2b-256 b4c7e2f15cd31adbc097c9e7616aa767fc176dd12973a9ffe7dff58d40b90752

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.7.1-py3-none-win32.whl
Algorithm Hash digest
SHA256 c95a952d3d8e1affce2122df9a4422a73a83409a9c4605f1603c2d98fcec4c3c
MD5 c492903395ad2de79f951f3349d887ac
BLAKE2b-256 a0a98fd05690ebb02cc879f21931f6d20656042064b041b5941ec0685710cda2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.7.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 79505ad0fe5807eca3c4baae7570995db04d4499bb431440ef08f8c02260fc43
MD5 d238185c9020cdf26f3466aef6e6891c
BLAKE2b-256 136a5918f19881830c8c86ba89b4a5e1ac0b92ce1ff0a9981115bf081af0e171

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.7.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8cc926b73990672eec09c3eaf8ccbf3cd82c469ce24c43cd6ab0a1d4348f44f0
MD5 dd64a13b8a77a92f075867d4ff1ff094
BLAKE2b-256 8aef4ca062622531dd426fc3da8dbb6af39c24c87f776a2fa380cec4e107f84a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.7.1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c7477318a36ac5fcd8afdece31ece5367fc4a52c11182267fc071af85e182b38
MD5 b577a7cb3fca651cf8bb618fdbba0176
BLAKE2b-256 8e6bb6ae7cd40031926c0b6fb0c15fd149b2adf1b6798de4651f9440de4d3e1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.7.1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 f99036c939f1e5317d1b8b1f0bf4584d895da77a14193cffae3faa11fd636dbc
MD5 36bfb91c5fc570e19ba0c12872765391
BLAKE2b-256 e8150a40ec50b69530b3e67ef52d7e9d9fec3b197ce503de0306325b6292372c

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.7.1-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.7.1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 41491fd1735770ca317d9b93898d572b8bb0c8536a69be14c3817d301ab99015
MD5 e371ee9c2041bc0c0ea25dc2332031ba
BLAKE2b-256 d12ae184caf1a3c35cb32e29ef7b1f53e601f0e835827bd0c9a55368328fc7af

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