Crates.io | cargo-zigbuild |
lib.rs | cargo-zigbuild |
version | |
source | src |
created_at | 2022-02-16 07:31:45.039668 |
updated_at | 2024-11-30 02:46:31.989436 |
description | Compile Cargo project with zig as linker |
homepage | |
repository | https://github.com/rust-cross/cargo-zigbuild |
max_upload_size | |
id | 533136 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
🚀 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.
cargo install --locked cargo-zigbuild
You can also install it using pip which will also install ziglang
automatically:
pip install cargo-zigbuild
We also provide Docker images 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
docker run --rm -it -v ${pwd}:c:\io -w c:\io messense/cargo-zigbuild.windows `
cargo zigbuild --target x86_64-apple-darwin
[!NOTE]
Windows docker image can compile debug builds, but does NOT supportcargo build --release
for *-apple-darwin targets. You will geterror: unable to run `strip`: program not found
. If you know a solution to this, please open an issue and/or PR.
pip3 install ziglang
rustup target add aarch64-unknown-linux-gnu
cargo zigbuild
, for example, cargo zigbuild --target aarch64-unknown-linux-gnu
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
[!NOTE] There are various caveats with the glibc version targeting feature:
- If you do not provide a
--target
, Zig is not used and the command effectively runs a regularcargo build
.- If you specify an invalid glibc version,
cargo zigbuild
will not relay the warning emitted fromzig cc
about the fallback version selected.- This feature does not necessarily match the behaviour of dynamically linking to a specific version of glibc on the build host.
- Version 2.32 can be specified, but runs on a host with only 2.31 available when it should instead abort with an error.
- Meanwhile specifying 2.33 will correctly be detected as incompatible when run on a host with glibc 2.31.
- Certain
RUSTFLAGS
like-C linker
opt-out of using Zig, while-L path/to/files
will have Zig ignore-C target-feature=+crt-static
.-C target-feature=+crt-static
for statically linking to a glibc version is not supported (upstreamzig cc
lacks support)
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.
Known upstream zig issues:
-target
and -mcpu
/-march
/-mtune
flags according to clang:
Some Rust targets aren't recognized by zig cc
, for example armv7-unknown-linux-gnueabihf
, workaround by using -mcpu=generic
and
explicitly passing target features in #58SDKROOT
environment variable to a macOS SDK path to workaround itcompiler_rt
functions that may lead to undefined symbol error for certain
targets. See also: zig compiler-rt status.This work is released under the MIT license. A copy of the license is provided in the LICENSE file.