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. - 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
Built Distributions
Hashes for cargo_zigbuild-0.16.10-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9e1962d041d9f33130ccd9f2861096ccb041aee53cbbf3ffc3da1481b213753 |
|
MD5 | d5ba94ed4fcdbea582e64b4d803a626e |
|
BLAKE2b-256 | 94eaefea3262c6ef00bd5665e360508470e2398de48bc3c41d20769f211b26ce |
Hashes for cargo_zigbuild-0.16.10-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e756a65d9bdf4c022985cdad5c827afe1a0fa7d3eb9ca7bf6985d0f548030887 |
|
MD5 | 93524c945ab3bcdb8ab01ba1546ed301 |
|
BLAKE2b-256 | d6d47eff6b5f94f82d93f9a5fa06f94fe950ee8d46a8c695ed94290ff74527fd |
Hashes for cargo_zigbuild-0.16.10-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad6ed5a8756e4f9d779222824a2a4293c405246187ab863caed9f6a623a07fa6 |
|
MD5 | d9107c487fa1d4efd4133914ceb71d14 |
|
BLAKE2b-256 | 1d2e3090e323b1835c590003d1c94192418f95ff313be2feb1c54ac6445f246b |
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 |
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 |
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 |
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 |
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 |