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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.12.0_beta.3-py3-none-win_amd64.whl (635.1 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.12.0_beta.3-py3-none-win32.whl (598.1 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.12.0_beta.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (672.6 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.12.0_beta.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (700.9 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.12.0_beta.3-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (751.7 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.12.0_beta.3-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (786.8 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.3-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 f938b142b532ea97a21a205de2eea53c651ed8bdd9d3295fc405cc37ad7bb7dc
MD5 823cc20addaeb90f7ec14b25df26e9dc
BLAKE2b-256 6e9fc0a59a39e02d9f35d4201e94d446cb280fb4781c1e6ebff0407a187cca7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 f724e8a86794b422ab0ecec1e49950b42df06f9268b2a57f3488c73f67a5c354
MD5 cb807e58e2a3db75b86a90dc922d2cea
BLAKE2b-256 ce39ddb024e36282445fe428d8280feb741e0f9d725e8ee2df0c48a92ec29c21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.3-py3-none-win32.whl
Algorithm Hash digest
SHA256 f3d88439dc6005c958f27686957dda1706d1a598021dd019dfc3a8d5d06a17a8
MD5 13050d0aaa068b2f772af20fcfb018bd
BLAKE2b-256 fee22f8221fbf3f361599b217d5e20b646fb7ed9d08df047ea6cd901c2bc1792

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 d97389f91b3e83847b4672986f64bef39e82c642d5307216092c76798a00177d
MD5 ea2ada94713f5a7f4df1db383b487928
BLAKE2b-256 d47d6801489f8a0004f0ea1f542a8e669ae91a157cc6cbb4cc15a400231c1fcc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2d1ac6b8e5e01e0df1bd2a446f1accf6c1a537a91b21cb5241e8e3ba7069332b
MD5 633a140dde47ae49d187ffce0e1942e7
BLAKE2b-256 c98189d4995b6eb6723e5da6673d63a9982628d42731226bff65e5979ed244d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.3-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 27bcf8b436a3d440621c5c19bb3e6fd88d016c95122709fc151b59c1a2dec110
MD5 f800b76715bc5312dfb72353b6fb3644
BLAKE2b-256 31253991382226a7ddcd29237b05427f7a42ba735d085e6b9bfb5cd5b6d76b43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.12.0_beta.3-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 6272b42b018cf38d25181f9b4157391f1baa7f9444d2b562cd735a66c2134172
MD5 5d5c2ae88396c43193209bcca9b47ff0
BLAKE2b-256 640ef9f9dcd2b189a26e2531b638d88870f0392b3d3b358ffb164b6e401b078d

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.12.0_beta.3-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.3-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 8cac53f34927b5f81dbf66d685669b159ca3b80ed35def447b0fdee606706645
MD5 09e5c3d218747840d2efcae326f42814
BLAKE2b-256 de129f89b608c12c4403109533617dc29ed43573b1fabc238172f1e57d18c70d

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