axodotdev / axodotdev/cargo-dist

Add support for zigbuild for backward-compatible glibc and macos universal binary support

Open
#264 6 comments 2 reactions 0 assignees View on GitHub
feature request - new integration
Dominant language
Rust
Stars
2.1k
Forks
149
Avg merge
1d 11h
Merged PRs (30d)
32

Description

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](https://github.com/rust-cross/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.

Contributor guide

Open the contributing guide

Research direction

Start by tracing how cargo-dist parses target tuples and chooses between cargo build commands; the issue names the target forms *-unknown-linux-gnu. and universal2-apple-darwin. Confirm how cargo-zigbuild should be invoked, then document the supported setup and verify that the requested glibc and macOS universal binary targets produce the intended artifacts.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, rust, zig
Domain
build-system, ci-cd, release
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.