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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.16.11-py3-none-win_amd64.whl (897.1 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.16.11-py3-none-win32.whl (846.4 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.16.11-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (885.3 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.16.11-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (930.6 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.16.11-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.0 MB view details)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.16.11-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (1.0 MB view details)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.16.11-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.9 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.16.11-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.11-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 0506606ab0b8e0da345498ba45846e64997f8df7be3ffeb87bfecdb01cfc24e7
MD5 4ade6aafc1bd915d6dc21135112ad3e5
BLAKE2b-256 7cc28a354a56c8282a8d7fdfc7fe0172489f12efe78bda895fe675c12a6d91e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.11-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 73b822cf0d27646bced9ea27c54f3775ba870d2963a6971eb3eb6dd2efef95fc
MD5 47959f95787e073b6c5a3d0516e07ab6
BLAKE2b-256 7ae3a6ba386a94761219e665788bdc7f12181a294b424b28993fbef7bb8cbe62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.11-py3-none-win32.whl
Algorithm Hash digest
SHA256 5846c1d045dd19b6bfd76f9fd62e92bf5e20e0e77309e3b2d5431b4db73e78d9
MD5 288306ec05bac92623d715398f63a8d9
BLAKE2b-256 a860de9bc8bfeb790e5f25537503ad103005a27fc8d94d8b506296162acbeaef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.11-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 ad81d1eaa8faf5da76c2d032ccacdebe96a279124c1b558f38e190b186602d81
MD5 0801b9e6143f6d1e40df9ea83850ac94
BLAKE2b-256 ba5b1d61b57a54fb9e14d7c5b016cfb281e3006acd5d3e0596f3a5ca329cf213

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.11-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bd9efffedca92efaeaaf12647da71a645e2ff551130c04a74f59d221f96f7286
MD5 eac3ab4e7cb23aa0c76a0e96cbc1729e
BLAKE2b-256 3388df819daa6d93f561425026994795f4a14ea7762c954b918a6aa727ace1d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.11-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 54e64cadb30186ba00ffc3dff1287561041d193f51e38a4a0beccd74fc5bca57
MD5 6e30358ff88d30d3ef9a0a05240ed359
BLAKE2b-256 d40391caaf2c1f894015f45fd73679c35abaa5e0d669f3729e092ad6f2cd5f4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.11-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 748442e3e3481e72bb26152a7c1e8dc0e29db3931b9e04bb1af17295354cd9fc
MD5 b47d57016e15c748e0f7c94d84c06dde
BLAKE2b-256 4415c9685e0c1357251a89332abfbf5e5d1df312580bafc6b1538df9db585fe7

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.16.11-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.16.11-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 43b783c61c1ffb81f29df9f1fa765c311d7316dcae80e388adf379f6b65dbabf
MD5 2f1f0b4b9b84db1c6212ce6f9f11a6fb
BLAKE2b-256 d980afeb3021b51a800a8a87cc912061da4e79cda3d1a1ecfd7d86445a22bc69

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