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.17.0-py3-none-win_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb0a52e602cbd6628bbacd72de68bc1a94735b2843d0494cd22d463d230b5df5 |
|
MD5 | ee161b8f962fca7595c0b465f04a6507 |
|
BLAKE2b-256 | ebf47b41d171794b74637b96a93f99b4f1e9e8f1fab7cbee6b08103c08de5f3f |
Hashes for cargo_zigbuild-0.17.0-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 842f6502241617e085acc4279516d865cc89c6e2df57bd36b40e638eac0e021b |
|
MD5 | c266c277e8bda96e742051571c17761b |
|
BLAKE2b-256 | de7fe1a3586bd496a4382f658bfe622c2cf298f4909aed006fb9b86bb641f533 |
Hashes for cargo_zigbuild-0.17.0-py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2e8bffc1b462729e94b97f2a9d084682afeb32293bc1b5812f480aed29c7417 |
|
MD5 | 59da43f3c0a22e94324f07122150aae5 |
|
BLAKE2b-256 | 5f81b11aa20978c07a934264b48c94d6fc56964d8e0d809b577b9384551cfb7a |
Hashes for cargo_zigbuild-0.17.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a02553c87ef512b8566517e928a8f04284b9cdd6a98262a3b4aa4c9f4db44d7 |
|
MD5 | 8e5a26330f70c82c21c4901b3da033f1 |
|
BLAKE2b-256 | 232d23bd9b7473118b158ff7e216af8b2a9cde4112668f00836402f42ccf5076 |
Hashes for cargo_zigbuild-0.17.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6ee2c67bdfcfebb891709ec94be69639236c09c6a2d92f303f1a7ad74eed1d5 |
|
MD5 | de858a621567a7ed5c8907f5eda0b732 |
|
BLAKE2b-256 | 2ac8ae2cb16f0c9e19446c55c8d59410fa779ba565abe06fe5a0c3dfdae024a5 |
Hashes for cargo_zigbuild-0.17.0-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | faf165db1c26ec8860b396a66ff0eacf19d1d0b2bebfbbe9a59dcaa47e7151f3 |
|
MD5 | c36585e619cede6ca69ac8e047d1ba93 |
|
BLAKE2b-256 | a2397d58239d0c054ff0403a221fd1789a6f10438a7f029ce710473dcd1216ec |
Hashes for cargo_zigbuild-0.17.0-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 983cf744ab5a09086994249bd9737d99e5b6cd6f3c88e5cecd78beb23a38d6b5 |
|
MD5 | 006ef48c21a0af6d3314efcd0a8e267b |
|
BLAKE2b-256 | 9a7e79cecb55af3e81b871c3ec0fb40c35b7037d0c6b9f9bb3ad444e571a6979 |
Hashes for cargo_zigbuild-0.17.0-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 276a0135fa08d77843184d414fd73c6b214eb73273e544b6c3f2d326af299ce4 |
|
MD5 | c1a7f9d176105f8b792a5b76f72a5741 |
|
BLAKE2b-256 | f493388296f50602cd5a74f9f06f8cf2cc5809482ef8f2057531e6f884ad2110 |