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

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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.8.5-py3-none-win_amd64.whl (560.9 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.8.5-py3-none-win32.whl (535.5 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.8.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (608.2 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.8.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (612.4 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.8.5-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (663.7 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.8.5-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (700.1 kB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.8.5-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.5-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.5-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 bdf5833ea00d6006b513930e7a4043d003865355f30aa9455955a88aa8a8e7c6
MD5 fb091328364e18158796c7fa14f43ed3
BLAKE2b-256 dbbef4c68f4f6472246bcdf25749b44809c3ae6c477cdf2234de574daae5e346

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.5-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 81c0a75b7f57e8d886daa8b7f2d1750d2c5733f730b947b020c9a5c05b6fd01e
MD5 a9da5dc838232540373fa7702bf445f6
BLAKE2b-256 55de862e7b29bb41b81fdc6061c2755ba3b71fff22c05b58d2786f53a04c4ef8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.5-py3-none-win32.whl
Algorithm Hash digest
SHA256 a9b6f182bde5437ec953f6b949ae9e9ad63b2d9b6d70faeee459eea70ac59784
MD5 374587c2609ea08e981a15ca327858c8
BLAKE2b-256 7e29d8aa39c9eeb0d86f5bd93123299da44f2d6d84586e3a12d16f1838144ea7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 0fd5584ec236f9fcf125f93d97351f0492ef8c8063b35356eb6e68600e1aacee
MD5 e9a2a107f073f6b10948ff7393bab8ee
BLAKE2b-256 853746d4ada4b73927e4afaf6161100d60adb07672cb5f5df70a71adc425f088

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1bbad9230673ce6b0869ada10ceb3b9aae390454eedc7d9c8b0da1f92e13a287
MD5 b6d4d7517a7cf120a889854bd14ebab5
BLAKE2b-256 af6128b445f3d46d67d020b9b8693a4266e17decc22feadaf9dc4692bb29a79e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.5-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a901297f29bd609051f6c0a5a74e9a52474d3e467ff2b1b3150a595b5d2e5eac
MD5 f582c69b550c6aa5a20e4cc044f7a617
BLAKE2b-256 ac7251bd9188fc3d4d62d087b995a4a547f8ac2e347a4086e14fd1f9fb48c2b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.8.5-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 e5daa1e9c2834d7d83820091c8aedcffe45a7302a0f5ec71602fe52ee3f5dc1d
MD5 2a026d468fbcc53367ebdeb87b24924e
BLAKE2b-256 ea79674da705514c9da6fcd93165272128ddc01074c385fef9b7d5b40e2e7700

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.8.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.8.5-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ea1b5dfa664ec40548528c5372fdd2b0ad347076c084dbc8c1c1cefe109e7609
MD5 944d7755b93d76613fd996a408964815
BLAKE2b-256 1b7c311efb372213b5ecea8da807f1fd3c86cc0b134b2a57f6fba8a0131a60b1

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