Compile Cargo project with zig as linker
Project description
cargo-zigbuild
🚀 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
Usage
- Install zig following the official documentation,
on macOS, Windows and Linux you can also install zig from PyPI via
pip3 install ziglang - Install Rust target via rustup, for example,
rustup target add aarch64-unknown-linux-gnu - 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-formatoption doesn't work with universal2 target currently.
Caveats
- 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.
- Only current Rust stable and nightly versions are regularly tested on CI, other versions may not work.
Known upstream zig issues:
- zig cc: parse
-targetand-mcpu/-march/-mtuneflags according to clang: Some Rust targets aren't recognized byzig cc, for examplearmv7-unknown-linux-gnueabihf, workaround by using-mcpu=genericand explicitly passing target features in #58 - glibc 2.27 or older: fcntl64 not found, but zig's glibc headers refer it: workaround by using linker script in #14
- ability to link against darwin frameworks (such as CoreFoundation) when cross compiling:
Set the
SDKROOTenvironment variable to a macOS SDK path to workaround 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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cargo_zigbuild-0.16.1-py3-none-win_arm64.whl.
File metadata
- Download URL: cargo_zigbuild-0.16.1-py3-none-win_arm64.whl
- Upload date:
- Size: 849.4 kB
- Tags: Python 3, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c79ad69455af9e33a54aae7c622542306c66a911998b95c31b39f0f4a331117
|
|
| MD5 |
aa0cee9f7d7ecfe85dcd7a85ae09b204
|
|
| BLAKE2b-256 |
dfef962a0b7754c712a5d4750e591cdca94149a1b71d93ed787b5649c73f2436
|
File details
Details for the file cargo_zigbuild-0.16.1-py3-none-win_amd64.whl.
File metadata
- Download URL: cargo_zigbuild-0.16.1-py3-none-win_amd64.whl
- Upload date:
- Size: 900.4 kB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5f77b429dcee8d8def6e428fcdf24bd073e7bdb05e085c331b1675d7befe580
|
|
| MD5 |
3b9e4ca8e0d2867c48b221b431c0e8d9
|
|
| BLAKE2b-256 |
8b5decb5eccaef3b07113b33621e0cd285065ba3a477e0d06daaaade03c27092
|
File details
Details for the file cargo_zigbuild-0.16.1-py3-none-win32.whl.
File metadata
- Download URL: cargo_zigbuild-0.16.1-py3-none-win32.whl
- Upload date:
- Size: 839.6 kB
- Tags: Python 3, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6727ac699e1d6e3bbdb7f8348c77da90c23d1816a0c07b7d2171569a7c59cb9
|
|
| MD5 |
77408b467258a87eeab54d8160adde30
|
|
| BLAKE2b-256 |
e89996f080f224119a1053dba1c4681eba0651162f0996ee3b38c8bf8887ca20
|
File details
Details for the file cargo_zigbuild-0.16.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.
File metadata
- Download URL: cargo_zigbuild-0.16.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 883.3 kB
- Tags: Python 3, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b48380f79623f41efb019edc332aab0705dd4056ee5b17935e92421a02ac5375
|
|
| MD5 |
3df5d0e735f33643c96cde7b20fdd4f9
|
|
| BLAKE2b-256 |
6135cbffd50e6dce9b8529649a3b428ef8fc800b08b9f854689b460a669961af
|
File details
Details for the file cargo_zigbuild-0.16.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: cargo_zigbuild-0.16.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 930.5 kB
- Tags: Python 3, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf7852b921f0d689b749561112c976d88088a82770c5ead9b196e75f8ea7e593
|
|
| MD5 |
4b4b83544d101cc309c9e9a395918a84
|
|
| BLAKE2b-256 |
6525062d5e5b1108abe3b7c8182d5ea3cf256e6a1dff0926277a3d0eb2347d1b
|
File details
Details for the file cargo_zigbuild-0.16.1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl.
File metadata
- Download URL: cargo_zigbuild-0.16.1-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: Python 3, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43ef5b698328b5b898d77e3faef8c10bb0125572b1f1864fccedb9c8e3f25d1f
|
|
| MD5 |
32aafadc37df45de03e33e2824a3adb7
|
|
| BLAKE2b-256 |
ef8feb41e72f7e47d426a7fefed1e7a41fef0b3707c10bb81b4b3c338d8e15e9
|
File details
Details for the file cargo_zigbuild-0.16.1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl.
File metadata
- Download URL: cargo_zigbuild-0.16.1-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
- Upload date:
- Size: 1.0 MB
- Tags: Python 3, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d7cb888370104480d61bdf2645bb9003514eba8ef5203b74de27b05d845cb10
|
|
| MD5 |
53b3dcb769501b281cee4cd1e073d591
|
|
| BLAKE2b-256 |
cebe3f09e35fdb7f2a86a9e349872ae9c3640b0e1eed63134f209a09dfd5d847
|
File details
Details for the file cargo_zigbuild-0.16.1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.
File metadata
- Download URL: cargo_zigbuild-0.16.1-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
- Upload date:
- Size: 1.9 MB
- Tags: Python 3, macOS 10.9+ universal2 (ARM64, x86-64), macOS 10.9+ x86-64, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/0.14.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43ec0165f22eb0e8262ab6b26f32fbc56d39e4a30cdc24a32ec9d05c80c2c08a
|
|
| MD5 |
2fa720f2b991c2dffe784020dd1482bd
|
|
| BLAKE2b-256 |
77999a618ac455115d3d3676ada597c97c6d6d2e5248ec9878f841ec942fa007
|