This topic is about supporting the creation of binaries that do the following:
$ ldd binary
not a dynamic executable
I managed to do this after reading this post, but it requires:
- compiling all crate deps with
cargo build -p
- using
-Z print-link-args
and--emit-obj
argument with the newcargo rustc
comand to a) get a .o file and b) get a linker command - hand editing the linker command line to (among other things) add
-static
, change-lgcc_s
to-lgcc_eh
and remove-pie
This resulted in a binary (with glibc statically linked) that I can run anywhere, even without libc installed. Static linking is one of the selling points of go and I think making this easier is worth pursuing with rust. Compiling on old distros for maximum compatibility isn’t fun.
In terms of previous movements on this, an issue was raised referencing this comment on linking glibc. Another issue was raised with the possibility of supporting alternative C libraries.
So it seems I may not understand the blocker. Given I do have a working statically linked binary, why is glibc not suitable for static linking? There are some issues (see the performance issue outlined in my first link and this comment chain) but it does result in functional output.