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

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.16.10-py3-none-win_amd64.whl (890.7 kB view details)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.16.10-py3-none-win32.whl (833.8 kB view details)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.16.10-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (886.3 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.16.10-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (926.2 kB view details)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.16.10-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.10-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.10-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.10-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.10-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 b9e1962d041d9f33130ccd9f2861096ccb041aee53cbbf3ffc3da1481b213753
MD5 d5ba94ed4fcdbea582e64b4d803a626e
BLAKE2b-256 94eaefea3262c6ef00bd5665e360508470e2398de48bc3c41d20769f211b26ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.10-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 e756a65d9bdf4c022985cdad5c827afe1a0fa7d3eb9ca7bf6985d0f548030887
MD5 93524c945ab3bcdb8ab01ba1546ed301
BLAKE2b-256 d6d47eff6b5f94f82d93f9a5fa06f94fe950ee8d46a8c695ed94290ff74527fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.10-py3-none-win32.whl
Algorithm Hash digest
SHA256 ad6ed5a8756e4f9d779222824a2a4293c405246187ab863caed9f6a623a07fa6
MD5 d9107c487fa1d4efd4133914ceb71d14
BLAKE2b-256 1d2e3090e323b1835c590003d1c94192418f95ff313be2feb1c54ac6445f246b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.10-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 ddf572dc168de0da6d76e9201940d3992a04854aaf5658c38dec8b33acad4d81
MD5 46f17301a6d6783a0e4a9ccd0734a628
BLAKE2b-256 4a04749a19978d2c202b06023a6254952c3a1b6b08ec1244039562a5971500b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.10-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 88ed8effb4e69d06b72aa9007d173589d4a32bab7cb5a3493480c0b687f4bd72
MD5 393ce663daa4ab80d0799a317a028df2
BLAKE2b-256 7c4f982f82d50c5f05fad23a7e8d688299826cc73073041112d5f73fa4d6417b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.10-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 da599f0982629ce4811675935f371d1d94fc90f8b0b109afb8bd222b3d3c8514
MD5 1a46fbb7f937c9956cc79cd24d2d8fdc
BLAKE2b-256 be809815b68f0ceb0058b597b88d3f18b3540851cc1e98854c10ab1d92754579

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cargo_zigbuild-0.16.10-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 f24539ef46dea57b25a59757e0ff9735eff804f3dcb81d6ce595487999d417de
MD5 05b4b0453dc87ae5be97f1972cb676c1
BLAKE2b-256 49f412ddce6d407c90a0943d98f61e9df9a5420a887b6af804d93dd6dc28844e

See more details on using hashes here.

File details

Details for the file cargo_zigbuild-0.16.10-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.10-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e257152f6ffdd8057437629b21a23796b2b07070d5d4ddc797d8192aa05f8291
MD5 1ae844b770464e66e7a84b45bc3c6145
BLAKE2b-256 8d28e2dfaed24812fab326765c594a16608e132fb5a8fa03c24b820cb1222458

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