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

Packaging status

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

macOS universal2 target

cargo zigbuild supports a special universal2-apple-darwin target for building macOS universal2 binaries/libraries on Rust 1.64.0 and later.

rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
cargo zigbuild --target universal2-apple-darwin

Note

Note that Cargo --message-format option doesn't work with universal2 target currently.

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, workaround by using -mcpu=generic and explicitly passing target features in #58
  2. ability to link against darwin frameworks (such as CoreFoundation) when cross compiling: Set the SDKROOT environment variable to a macOS SDK path to workaround it
  3. zig misses some compiler_rt functions that may lead to undefined symbol error for certain targets. See also: zig compiler-rt status.
  4. CPU features are not passed to clang

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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.18.0-py3-none-win_amd64.whl (903.3 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.18.0-py3-none-win32.whl (849.7 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.18.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (932.5 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.18.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (977.4 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.18.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.1 MB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.18.0-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (1.1 MB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.18.0-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (1.9 MB view details)

Uploaded Python 3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64

File details

Details for the file cargo_zigbuild-0.18.0-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 457a7baed04e2f7fc58e415e89cc517b9b41eee5ae556366c2898f6b1e7dd6f4
MD5 101d1c5b5c12d19032f9baf2da46706b
BLAKE2b-256 582c86a3f3f529027b7f8f9ac7e701742695994e7104644755c7ed952312f601

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 c00ef7595cb6b8276801eb4df05a184f9ba7b608cdc1d0abc22c3a9348e565fe
MD5 ca7f4738475589ffba2cc493d5d035d1
BLAKE2b-256 c1e8f5ca6343af2dee7b1996832f9c9e98fc0145961086ba9b24a076753cd788

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 eae5b9affebc27c54e5f8d0eb3e1b30aab39272ba3eeef6a7b6fe020e2ce7176
MD5 eee2f7114a76d196bd78fa72113da45c
BLAKE2b-256 51d12707282ef06b60686fcfa813f392a85b7c8fe6bd5bbda6e8bed0549df7b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 228411248544042f4fb96c1b3405489220eddeaa15fee09cda966b15aac4900c
MD5 2b346966950ac2d1a3ec42a8e47bb093
BLAKE2b-256 2812437355444ecd22337a20c0e880cc882576fada2e061cef1f81096f92f6e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9e4d2c942b4260beaa5df2051420b136935c3319964afebc4c09ea4084a03e46
MD5 cd9ff2159eb7771c2e04d70e6a160f18
BLAKE2b-256 c2181c61a1d3c12e132d8ee645c9e19f9c6e0bc61dfc60ae9387874feb3c1b0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3a98189034cdbcf5dad25eb66e296244c9194dd9af2a2b592e48fbceb36de102
MD5 6a3582fcc57e17e628296c63594afb0a
BLAKE2b-256 a2f690da8a8d06a660903bf1695cda75d18fdf5ab282a103ef3226d47eb4e7d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.0-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 85dc1e2bf1ae52ce238c41f9eb6347ad30a6ab08dfb63c1bd661bfc140a77dc3
MD5 3794721826c843507fe87d9164bded60
BLAKE2b-256 92b72982d783fedf1899102782d738c00c608cc2e0a5468ff283e27ac0454959

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.18.0-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.0-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 ca9893f7b51be023fa126d12d5339e496e859d474a83915eb991984bd44d9798
MD5 dc3c4b8ce623e68f6aed997fa164d838
BLAKE2b-256 adcd91ec5360165906d2e97632ecb7d00537437ae1faa40de449f9e56e1a895b

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