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. glibc 2.27 or older: fcntl64 not found, but zig's glibc headers refer it: workaround by using linker script in #14
  3. 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
  4. zig misses some compiler_rt functions that may lead to undefined symbol error for certain targets.

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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.16.3-py3-none-win_amd64.whl (892.7 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.16.3-py3-none-win32.whl (837.5 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.16.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (882.4 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.16.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (928.0 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.16.3-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.3-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.3-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.3-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.3-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 95bf3f26d2ce527f079cb3ba0571aae9c3f2aefc91e8f869dbb78cd191ba2762
MD5 c32ab14f97583171d939a4b8a710532e
BLAKE2b-256 a345d81d027f546a5d02055861742d0404f890b8cb12bb92e22e9d68c4cec400

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 4784f5654a115246b59a6770c2be6311bfb073bb7003e3dfdc9a8cdf18496923
MD5 1059074231f06f82a29ef166a2829942
BLAKE2b-256 8bd9fb4e1490b9c21c2c0160367a1680631d4886aeec60cb9b2453f91832cea9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.3-py3-none-win32.whl
Algorithm Hash digest
SHA256 b3a944c9bdd54c3cb31143d19394fa36174bf1d760b4b4fb0cb17e39dd00e726
MD5 d545ecf58210ed0c0e8de04ff7aa5225
BLAKE2b-256 7870eb585b9b33460596d2e02d68360c8a7bcdb6c350af0eb31fbaeb8f7d160f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 6e88e413641460cc15fdcda3998e5d91f2dfc0874293874be6148258cc650456
MD5 796e32cb4c945074c819b2056e01725a
BLAKE2b-256 554d62ccf0bcfae129fe9d03594cce8ef42b82146e8654839cfc6fa512cf7c17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a228d19225cb7af39706da3c44cc0c422db9c106a7ba5a6b7bae653e0e8b79da
MD5 2228c483cd463e5213f91a8e829b5e49
BLAKE2b-256 d45eb3b832f9174d94f4c9cf5e5773cc49236d2508271ec538aaff2f3ea67248

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.3-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4840696d1aa653a2fee5d34b893cbaca57e7cdbb63ef7cfd7b00f04c84d7729d
MD5 09625cbe017e97a7a2e7ccd9aef88e55
BLAKE2b-256 b32644508b1ae1efcc4b9fd7dca6103dd7bfc2b04e0c5d6e0b533f9c23350d1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.3-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 955ce8f9cadb6d4710a7f9d0399e58c56faeb67ae830882bb7fe1989c2a89870
MD5 6e85e7f37d8c1864b18842b5edcad61d
BLAKE2b-256 36d033c34a167efd977a3cf606fb08b06d04a84948e4c2f6d95d9dcf42076441

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.16.3-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.3-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 677e8980c2f1239c56802bb5d4069bf1d124f62489ec7b58f6af5a05cf08b6ba
MD5 381742915ba608b061b9914bd6d5cabc
BLAKE2b-256 db18386c8bf335ad831ef4b9db565abe0eb2a1078cc5a253b190e7a4cf46f55e

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