Making a rust all-in-one package program


#1

What are the steps of packaging a all-sufficient rust binary? I mean, I want to make a release where users may just download already compiled rust executable with all the libraries with it. For example:

$ ls release-0.6.2/
rust-executable
libssl.so.1.0.0
libcrypto.so.1.0.0

So the end-user needs to download the archive only, unpack it and he is able to use it without installing openssl into his system. So, the rust-executable loads these listed libssl.so.1.0.0 and libcrypto.so.1.0.0 at runtime instead of LD_LIBRARY_PATH ones… I thought of providing a shell script which does LD_PRELOAD and some other stuff. But I think I want to invent a bycycle here because it is common thing to do and there are best practices already I think.


#2

It may be more straightforward to statically link to libssl and libcrypto so you don’t have to worry about tracking down dynamic libraries.


#3

How can I do that with cargo ?


#4

Make sure you have static libraries available (they end in .a), and set the environment variable OPENSSL_STATIC to 1 when building.


#5

Probably that will solve this for openssl libraries but what about everything else?


#6

Check out this post about rustup: https://blog.rust-lang.org/2016/05/13/rustup.html#example-building-static-binaries-on-linux

[…] it’s possible to distribute ELF binaries with no dynamic library dependencies that will run on any version of Linux.

If my understanding is correct, this is what you are looking for and rustup provides a very convenient way to achieve it.