Assumed audience: Rust developers who might want or need to know about more approaches to getting the right libc version one way or another.
-
Use musl. By default, just by configuring it in your Rust toolchain. As a bonus, you might want to use a custom allocator to avoid the performance hit from using musl’s built-in allocator, which is well-known to be rather slow — because musl’s goal is not first of all speed but being small and portable and statically linkable.
-
Match the build OS to the target OS so. Variants of this:
-
Get a build machine set up with whatever OS you are using. On GitHub Actions, this might mean specifying (e.g.)
ubuntu-20.04if that’s what your project actually runs on (usingubuntu-latestis a recipe for breaking), or at least a version of Linux at least as old as the version on your target machine. -
Use cross to cross-compile to a given target. This uses Docker under the hood, which makes it relatively straightforward to use… but also requires installing Docker, so it’s not small by any means.
-
Build and deploy a dedicated Docker image with the required bits. This is sort of a variant on the previous item. It involves getting thoroughly into the weeds with Docker, but also means you have total control.
-
-
Use cargo-zigbuild to use Zig as the linker for the project and then specify the exact glibc version you want.1
-
Manually pick your glibc at runtime, if you control how it is loaded. (Whoa!)
For the little project that motivated the question, I’m debating between actually going full Docker (more yak shaving! But also, more familiarity with a useful tool that I have barely ever touched directly, and that over half a decade ago) and “just” picking a matching version of the OS and moving on.
Notes
I hypothesize that all the good stuff Zig is doing around linking and libc may end up being its most significant contribution long-term! ↩︎