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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.18.2-py3-none-win_amd64.whl (884.8 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.18.2-py3-none-win32.whl (832.1 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.18.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (919.1 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.18.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (956.3 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.2-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 8ab20ae149138f139c341906a7498f93087bfb0cd15e60015fa0c32938c27f91
MD5 cbb0ad43fdff15b93bbf03efd1495c43
BLAKE2b-256 0a215e11a3ae82a3344e6ed5dd62edb11fe0b0a6d268a0684b17ce98c25191f4

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 f7125b0d85cf748b8c8277a9284a7bb4a2a651972afdb6abecc2c73e4dfcfe83
MD5 339efecd4e48c0c2ba3bac75c2d51af7
BLAKE2b-256 6593a83128f80d3758e96f4d6c25d02918f8161883f20e5479ab94433013ef88

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.2-py3-none-win32.whl
Algorithm Hash digest
SHA256 8a7a423b535615c97b0cc3b8735a2063b61ae4376bf070b2171e8233829ed986
MD5 613cf238116bcac1869c91f859ffa1ca
BLAKE2b-256 3fcd6299fc18687cf4f22c828e3e4af6b30beecf47155effb61bd7d815ed3b04

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 5b77d2854dfbf207acb7d1e59a892c37f8b6f55b00cd5f70beb27971010f94ed
MD5 d8d674bb23da6569bd105ee20cbdda1e
BLAKE2b-256 14832f10024988288daca31d050f9d58d0ea2dabcaaf94561199d1708e3d2a06

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f9c081c0cb9b68493bae5c3c6514744aaeb419496e29da6508d1e1efb6816672
MD5 2c9f864a54bba4c2279446a8b800d3f0
BLAKE2b-256 a7767eaedaf983de6e0c8284aac6d4f1819c55da4c8e77b8bfdbd3e8099ef1d2

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.2-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c10df0793525f827a1ba49984738e31f900d84c2550253aaa83c5cf25ba36efa
MD5 2e870ef150acab50a04b56e1fe62b779
BLAKE2b-256 ddf51006a240604dc4a28e8cd2c1b7a75fcf7ea10dd4c73925fe7d0b59b051d8

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.18.2-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 d3a50b9effcf92f06191a6f1fa83ec2e1ee8ad888b98fdf99778aafd82e8c6eb
MD5 ea2c03dd2992759f536771feccceb96a
BLAKE2b-256 6ba5b5bf1027da46b454fae69365abd5e63fce0a7c2d6b6396e135da0740a5af

See more details on using hashes here.

Provenance

File details

Details for the file cargo_zigbuild-0.18.2-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.2-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 1369cb1f5e7da00b1436b1202b6db4ac398e3c673105e82e596638e8be4b0800
MD5 69121b5eef3cf3e3bda1f18a21c79452
BLAKE2b-256 d95a1a703c985bbd8672b99aa62b4f87a1c50a1e579421ad2ff956a0ed6d99ee

See more details on using hashes here.

Provenance

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