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-format
option 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
-target
and-mcpu
/-march
/-mtune
flags according to clang: Some Rust targets aren't recognized byzig cc
, for examplearmv7-unknown-linux-gnueabihf
, workaround by using-mcpu=generic
and explicitly passing target features in #58 - 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 - zig misses some
compiler_rt
functions that may lead to undefined symbol error for certain targets. See also: zig compiler-rt status.
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
Hashes for cargo_zigbuild-0.16.7-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccd3952ba8abe23bf84405ff8fe533e8b26cf313305dbd606841aef65502883c |
|
MD5 | dc58898a91643693fa08faef1b711ce6 |
|
BLAKE2b-256 | bafde02954e77a698b50d6cdf7c4910daa97ad7d9f9b7c5c1ad29efe6b0614ac |
Hashes for cargo_zigbuild-0.16.7-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93f8c8f62739cf297d100bf83fc3ce0df61dfdbdbd5dbfbd6cac156b230e65ba |
|
MD5 | 20403f6486dbdca9fa62215dd3e98f57 |
|
BLAKE2b-256 | 86a4333cf8a6bf8cb7524e1eeb2956ede551e0b86547cdb196494a76c3c876b2 |
Hashes for cargo_zigbuild-0.16.7-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1da7ed53f9435c9aa17cb0729a99e2c57cdbf8454a40b2898e9f66ed57d9ce6a |
|
MD5 | ee3acc02042bcfdcc5b348fda69c0200 |
|
BLAKE2b-256 | df042c68655b4de297acbd135b429f8c3d70113d38ffdf6bbb81bf348f053c02 |
Hashes for cargo_zigbuild-0.16.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87016ee7926108f8ac7d3a6499a9711f5a95aa8232cdae4046265a40cf47ea4d |
|
MD5 | 5bd752baa5cfaefc78107bb864596fa4 |
|
BLAKE2b-256 | 88ae1abb2f3e765247e9a4dc9428fe0bd53e7ff9d7b036a894214a14db091a77 |
Hashes for cargo_zigbuild-0.16.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5d6835d7b7b9e20a3c155c776816a46190b547fefb871119a4d5aea0f9c5838 |
|
MD5 | 9ba4af71dbd510fcc1a91661ab638b92 |
|
BLAKE2b-256 | f6aa414d8ddb106d0615d01f23a99e65eadee6c16b6d67a78f15f189e21126ce |
Hashes for cargo_zigbuild-0.16.7-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2c8892f4a15857f640c36069bc9a276dbcf857f868e9ed97dfad2d3a57a3063 |
|
MD5 | bd002634ea547321497e0ae2eb2071b8 |
|
BLAKE2b-256 | c33257b8e447769e1fdbd00f455a9bd77e3ae41442f1ab34da76769a2ed8f8fe |
Hashes for cargo_zigbuild-0.16.7-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bf226e699a8e9685bd04b39dfebc8c74dce205cd28faf86ecb6723b1d6349b6 |
|
MD5 | 3f9e775924df1beca438f08626f00994 |
|
BLAKE2b-256 | 1ae5212ccbf349293ec2039479c095a787eb1f27ec0f97e2d234a92f08de2f7e |
Hashes for cargo_zigbuild-0.16.7-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f105faf9ef2644c2dc0ee5748f1f61e44e5cf1b57a778ef6d701ca12ef09e30c |
|
MD5 | ca1ec6bc19b47be907d7987d6b1fd114 |
|
BLAKE2b-256 | b6d2f187f178e205bb1fbd989bff3db52789f228ad404d02f35576572caf6159 |