Skip to main content

Compile Cargo project with zig as linker

Project description

cargo-zigbuild

CI Crates.io docs.rs PyPI Docker Image

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

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

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
  2. glibc 2.27 or older: fcntl64 not found, but zig's glibc headers refer it

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.9.0-py3-none-win_arm64.whl (545.2 kB view hashes)

Uploaded Python 3 Windows ARM64

cargo_zigbuild-0.9.0-py3-none-win_amd64.whl (571.3 kB view hashes)

Uploaded Python 3 Windows x86-64

cargo_zigbuild-0.9.0-py3-none-win32.whl (544.1 kB view hashes)

Uploaded Python 3 Windows x86

cargo_zigbuild-0.9.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (627.5 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

cargo_zigbuild-0.9.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (649.5 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

cargo_zigbuild-0.9.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (701.1 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.5+ x86-64

cargo_zigbuild-0.9.0-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (736.4 kB view hashes)

Uploaded Python 3 manylinux: glibc 2.5+ i686

cargo_zigbuild-0.9.0-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.2 MB view hashes)

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

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