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

This version

0.8.0

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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.8.0-py3-none-win_amd64.whl (558.5 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.8.0-py3-none-win32.whl (531.3 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.8.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (600.2 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.8.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (599.7 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.8.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (659.0 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.8.0-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (687.5 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.8.0-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.0-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 136ea56660ca042e510e135fab8b85138e83d0941d8192966fd2771ff15c297d
MD5 659ee51ca3ed19525a2131159e32353c
BLAKE2b-256 17818b684967227b6b9b876ac3b6564aa1ba920d22b5acd1f3810df2c5f49f20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 ea760ec2e80d3ea10597fbde0ad5ed17977bc39b8f1b1212e432dd4c2323e371
MD5 a0f4faf2612f23328be8a38b1846638a
BLAKE2b-256 9d9c2b755f4b2cfebe14ce720db9c4be471d1b78c5e5a2a34da010cb216d0eed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 edf957bbdd81cbef284a96f636d21f0049a9d90a97eb36b66c63b00fc3af7b30
MD5 283563ad6c6054ef27392f3bfac76652
BLAKE2b-256 d5f265918ec4d45ca4b2e1229ac6c50333c97e1d4e9e8e85e66cc549ed035f8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 23972f42ba8661751773ac740de1ff5b2c0f56b1c26a47adf1f2ae4406d6e5c6
MD5 16285d2f194e63fbcee6f1d81c55be45
BLAKE2b-256 1342b38d969bf2d8dde4f5730c7ec3080735eccb373e483baaf1047cd439a54b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 df29d8247924e5b745c77146f46228b6836bc38fa65d1a6fa6d72eaea2213cad
MD5 c661c4fdf9bdb64b3f7fd6f6c529e08d
BLAKE2b-256 be320de23fc43bcbd608b50a589790cd36c23ad0088be5c9508c230707b4e445

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8ad15ca33b25c358f0453c41eaee4c84a0dc5d54e5e7394e0e8a86152fc88787
MD5 e905a431d535c187241425a21eee2afa
BLAKE2b-256 64f4fce61421e81faeb75b6c0918a0ff035354ac69487d0a4e82dd7141d2805c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.0-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 2238a26353a52aa48bc10423ec007832dc36e3c8a8acdeba55630f4319decadc
MD5 e8422850c150463b6b76c74919627803
BLAKE2b-256 6340da2aef9b6e8cd10cfe470d305a2d91402b832de85b93064a063f59032f32

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.8.0-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.0-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 25329d172386b655e4bf4f1becc7f9e93c89fc66aabec49005aefa3069d7ee1b
MD5 fadd2d3a8b544a7a85b5d4e3500e12f0
BLAKE2b-256 676585aeaf4ad81daf1526335270ff8b3eac67c7b05b1618d3555cd35bbf3548

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