https://github.com/rust-cross/cargo-zigbuild Github Repo Stars: rust-cross/cargo-zigbuild

Compile Cargo project with zig as linker for easier cross compiling.


Install zig

https://ziglang.org/download/


Install cargo-zigbuild

cargo install cargo-zigbuild


Cross build

cargo zigbuild --target x86_64-unknown-linux-musl
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 --target universal2-apple-darwin


OpenSSL

If the vendored Cargo feature is enabled, the openssl-src crate will be used to compile and statically link to a copy of OpenSSL. The build process requires a C compiler, perl (and perl-core), and make. The OpenSSL version will generally track the newest OpenSSL release, and changes to the version are not considered breaking changes.

opensl

openssl = { version = "0.10", features = ["vendored"] }

reqwest

reqwest = { version = "0.11.10", features = ["native-tls-vendored"] }


justfile

justfile

_:
  @just --list

build-linux-x64-musl:
  cargo zigbuild --release --target x86_64-unknown-linux-musl