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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.6.5-py3-none-win_amd64.whl (541.3 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.6.5-py3-none-win32.whl (515.7 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.6.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (580.7 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.6.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (580.9 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.6.5-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (640.3 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.6.5-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (667.4 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.6.5-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.1 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.6.5-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.6.5-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 3804eeb2e51a1949c7c4f485a09583892576cb362ec2169d4b99211bb6b5c405
MD5 8dd6c0a83df58a78dfdd6e31a1ede2cf
BLAKE2b-256 b06798096a5bbb93e95874b58b126e4e6b3af8ade40d3d934afc87d822b1c633

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.6.5-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 2194d4df1e6f5f06fbe2175a6df54855bec7f699a6db8d664e35256839fec58b
MD5 e815c09971ae76337c07607dd3ecc7ea
BLAKE2b-256 8d4ec8d36031d9b15cde64b4fc44b68d63930da4e2c06469864b834c29f4cfae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.6.5-py3-none-win32.whl
Algorithm Hash digest
SHA256 3a273be596bbfa458d7cbff22a9caa5b2302bee9f6324d156ab464426315f242
MD5 5a932bc93fe1590e13a4c98fd54168d4
BLAKE2b-256 71500de0feeba4cc8370505d667a6c50290058e58062d265abc60068ed6c58e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.6.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 97c9dc52c5378e74a6b0a783acc90cb388c6f6158605f446492926d16d99dff6
MD5 5d7cdc127e28a702dc842ffb3cf7d820
BLAKE2b-256 f13fecfed64183804cae644dec3e94654ce5d04b51a3cfb8a988f0ab8f1ffbd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.6.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f60d2b7b9858adaf8153e43682211ac221da65cc06b6bb8d6863fc65980b1e98
MD5 7b52bc43058f175e7b666c9f92b2d0a2
BLAKE2b-256 b291b817f23cb575714026c12f37708cb7a970b6fd8f3fc173122fb6c8255b53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.6.5-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 17c98f85355b7cafad332822044b8f8153be4009102a73e0c2dccf03d7617def
MD5 9382708d8a4a23d04f2c9b168f42789a
BLAKE2b-256 ca869dcdc2dc2a02f474c8893e6cf4f7f5a3f8ae4a69038355f3cb9a1839998f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.6.5-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 f262481c3b49e695fad8defca1dff19091a3aab8e6fa9c0c3a305e000a6331e2
MD5 5888ce2c04cae2e5df3b25409e1ecb7f
BLAKE2b-256 77ef9c76cb5eda68033266c9f4c3ce70166e3378e7cf46a4cdaf0d97c183a387

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.6.5-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.6.5-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 695d9fe4a9ccb2341749f500212b737e27d82c58a9c0da518097bd460e41b99d
MD5 5fe309dafe5c37b1eb6e10d5c95bf34c
BLAKE2b-256 3d820d84c9dd698d13254a1c0c44b7038027d63cd648386a5b60cb083a5a3569

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