5

I am compiling my Rust code to be used as a CLI.

I want it installable on the widest possible range of x86_64-unknown-linux-gnu based systems, particularly Ubuntu's.

I am using a docker base image FROM rust:latest for builds, but this compile-host has glibc v2.29.

When I try to run the binary on another Debian system with (Debian GLIBC 2.28-10) 2.28 it exits with an error:

clix: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by clix)

So does this mean I need to compile on an old Ubuntu (ubuntu:16.04) to support Ubuntu 16 and newer?

Is there a an alternative where I can compile on rust:latest and have my binary work on old Ubuntu OS's?

Related:

zino
  • 1,222
  • 2
  • 17
  • 47
  • if you want to compile your image to run on ubuntu 16 base yes you should take an ubuntu 16 base, just do a rustup install in the image. In docker host is not important so I don't follow you – Stargateur Sep 23 '21 at 05:40
  • 1
    @Stargateur My understanding is that Docker is only used for the build, possibly in CI. The resulting binary is supposed to run on the host system directly. – Sven Marnach Sep 23 '21 at 08:41
  • @stargateur The docker container is just for compiling. The compiled binary is to distribute as a release download (which is why I want it to work for many systems). I was under the impression Rust compiled static binaries that just work in most Linux distributions, but actually you have to be careful about the release date of the OS you compile on. – zino Sep 23 '21 at 08:52
  • ecen if rust is by default static there always by the loader that need to be load i don t know one elf program that can be share like that. since every distribution have its own path and specificity it s not possible – Stargateur Sep 23 '21 at 08:58
  • @Stargateur Rust by default produces dynamically linked binaries. Completely statically linked binaries are usually portable across Linux distributions. Tools written in Go are commonly distributed like this. – Sven Marnach Sep 23 '21 at 14:02
  • @SvenMarnach allow me to disagree plus rust is static by default https://stackoverflow.com/questions/29008127/why-are-rust-executables-so-huge – Stargateur Sep 23 '21 at 14:09
  • 2
    @Stargateur Rust binaries are _mostly_ statically linked by default, but the *-linux-gnu targets link against glibc dynamically (and other external libs, e.g. OpenSSL), so you end up with a dynamically linked ELF binary, not a statically linked one. – Sven Marnach Sep 23 '21 at 14:35

1 Answers1

0

So does this mean I need to compile on an old Ubuntu (ubuntu:16.04) to support Ubuntu 16 and newer?

This is the simplest solution.

Is there a an alternative where I can compile on rust:latest and have my binary work on old Ubuntu OS's?

Yes: you can build yourself a Linux-to-older-Linux cross-compiler, and use it to build your binary on rust:latest. This isn't entirely trivial thing to do, and usually "build on older" is the more straightforward solution.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362