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

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.2

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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.8.2-py3-none-win_amd64.whl (565.1 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.8.2-py3-none-win32.whl (535.4 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.8.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (608.3 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.8.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (614.4 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.8.2-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (669.0 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.8.2-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (701.7 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.8.2-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.2-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.2-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 b1caa0c46048ee4cb2d795333e06970e190a1e8530160438c2b987ce071765b6
MD5 17a6cdcfd7f5ba990ba7a4b02a3216db
BLAKE2b-256 616a859ffe1449676e7219d1bf8d4514118eb433fcd88f7a2e585a95c0378b7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 6d2fb9ee8c872cc14093213ab4c6df3028bc79643b115917e078597f80e81aca
MD5 11cc0381608a46149bb64ba4e96dcd60
BLAKE2b-256 91f56a6fc5702959349f78ce0821759624063fe0c3e87aff3c6c911953df2b22

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.2-py3-none-win32.whl
Algorithm Hash digest
SHA256 d3b73a262c1092c8e130dba666f40a55a20a04ec274d9bb5e6d2d4c24d346d05
MD5 50a00eb83232b100861dc088d470740b
BLAKE2b-256 3c9e4046694d2f400466a56fa9e96a5624a7fed4a0c48c63d94e56cfa2f40516

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 0d7b925b65af0d85250142d3a59f642d0284d936c7cf3fad276abce0b34334a0
MD5 60dca2dfdebb828999396f4cb7c8780b
BLAKE2b-256 58b006ca57ecbe80e9b46d3fff4ee26eab49b725c35075893d65d46e96292347

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cb83ec316218d271badecd3377e2f5b49854ba5a45dd522d48a632a30a30f72b
MD5 aad7cc3ab63ca7e2a19d87bb88f0317d
BLAKE2b-256 ad062cfdcb00257d62d1755488f4818a9013ae2ad35efa71fce8fad2df6751e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.2-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 885c2db58c625401b4e0af533b3d17afe73b16f339f5ce32baa0af64b260431e
MD5 b0981d5fac112811563c0b5d5cff591e
BLAKE2b-256 87749599aebfc038b194a82721ad3ae22275b14db967f094b9e3a37d44f50cdc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.2-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 6165573b8bca68ee785f2ef3bf1a6c96face52c79a5c8299de35684993efee1a
MD5 baeadc3e482eceacc05a110dcb891ee2
BLAKE2b-256 168e1dc82ef6c6f1654b219f9f9f9a3b583cf27f2f933709b4cfaa6f5c82a16f

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.8.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.8.2-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f70b4379a4e5206d9d163bdbddb80fb30d58bbb068e038ca0a51e62e03ef209a
MD5 c0da30055e0aaa83786f4306b9b150d8
BLAKE2b-256 448c75b57453e4cf77125832f95790f09191c54811fb4ebaaee75125bb6917a0

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