Compile Cargo project with zig as linker for easier cross compiling.
bash
cargo install cargo-zigbuild
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 libc version in --target
option, for example,
to compile for glibc 2.17 with the aarch64-unknown-linux-gnu
target:
bash
cargo zigbuild --target aarch64-unknown-linux-gnu.2.17
--target
argument is the same as the host target,
for example when compiling from Linux x86_64 to Linux x86_64,
Cargo by default also uses zig as linker for build dependencies like build scripts and proc-macros
which might not work (See #4).
You need to use the nightly Rust compiler and enable the unstable target-applies-to-host
option
and set target-applies-to-host = false
in cargo configuration file, for example .cargo/config.toml
, to make it work.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
This work is released under the MIT license. A copy of the license is provided in the LICENSE file.