Open markcatley opened 1 year ago
Hey sorry for the delay, but I was planning on adding cargo-zigbuild support ~next week, and this plan seems pretty reasonable!
No worries. I looked at implementing myself but it was well beyond my skills without a lot of help. More than happy to help with testing though.
Initial Notes From Testing On Windows:
must install ziglang (approximately a million options for that)
must install cargo-zigbuild
pip install cargo-zigbuild
will install ziglang
tooto build a specific target (say arm64 linux)
rustup target add aarch64-unknown-linux-gnu
(that's cool, we already support that for macos stuff)cargo zigbuild --target aarch64-unknown-linux-gnu
cargo zigbuild --target aarch64-unknown-linux-gnu.2.17
to get specific glibcuniversal2-apple-darwin
target supported, which is nice because that's the name I would use too⚠️ problematically, building cargo-dist in this manner hits an underlying linker issue in zig, which will affect any package with many dependencies.
I expect most people who care about this feature care about linux => other, so I'm going to shift to testing on WSL for now.
Initial Notes From Testing On WSL (Ubuntu 20.04):
snap install zig --classic --beta
fails, unclear if it's busted or i did it wrongpip install cargo-zigbuild
, works greatLooks like zigbuild musl support recently broke because zig and rustc can desync on the version of musl they're thinking of https://github.com/rust-cross/cargo-zigbuild/issues/158
I’d like to be able to build my project with zigbuild as part of cargo dist. It’s fairly simple (for me): use the zigbuild docker image, run ‘cargo zigbuild — target foo’. I’m happy to contribute, but don’t know the codebase.
Building portable binaries on Linux is a bit of a nightmare. There's no simple way to select a minimum version of Linux you'd like to support. The reason for this is that the standard linkers will always dynamically link against the latest version of glibc and any other library on the system. glibc is the most common dynamically linked library in rust binaries and is commonly the only dynamically linked library. Supporting old versions of that would go a long way to support portable binaries on linux.
A common approach, taken by cargo-binstall and cargo-lambda is to use the zig linker via cargo-zigbuild to enable linking against older glibc version. I propose we add support for it.
Having a look at how it works support could be added by looking for a specified glibc version in the target tuple (-unknown-linux-gnu., eg. aarch64-unknown-linux-gnu.2.17 or universal2-apple-darwin) and calling cargo zigbuild instead of cargo build and add some information into the documentation. At a later date, once you're happy the support is stable, you could add the steps to install ziglang and cargo-zigbuild to the github actions templates and add support for glibc 2.17 by default (this seems to be the version supported by other rust binaries that have older linux support - it's from Dec 2012, or you could pick 2.26 which supports the AmazonLinux 2, the runtime for AWS lambda and other AWS services).
I've added macos universal binary support as a selling point for this option too. I am not sure that the need for it is as compelling as older glibc versions but some projects may find it useful.
If you're happy with this approach I'm happy to help with adding support.