emk / rust-musl-builder

Docker images for compiling static Rust binaries using musl-libc and musl-gcc, with static versions of useful C libraries. Supports openssl and diesel crates.
Apache License 2.0
1.54k stars 193 forks source link

upx support #109

Closed GopherJ closed 3 years ago

GopherJ commented 3 years ago

How could this project be improved?

musl can generate big binary but makes the program more portable, upx can minimize a binary, is it possible to have it inside the container?

If you're interested in implementing this feature yourself, how could I help you?

A workaround will look like

# Install upx
RUN wget https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz \
    && tar -xJf upx-3.94-amd64_linux.tar.xz \
    && chmod u+x upx-3.94-amd64_linux/upx \
    && sudo mv upx-3.94-amd64_linux/upx /usr/local/bin
GopherJ commented 3 years ago

Also the size of upx is quite small, like 360K on my pc.

emk commented 3 years ago

Apparently UPX has licensing issues that make it difficult for us to redistribute and it breaks page sharing resulting in more RAM usage in many common scenarioes. Instead, I would recommend zipping your executables when you distribute them but storing them uncompressed on disk.

But if you want to use upx, you should be able to install it normally as part of the Dockerfile that you use to compile your Rust code. Thank you for the suggestion and good luck!