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

Fix switch to musl target for ARM static binaries #43

Closed snobu closed 6 years ago

snobu commented 6 years ago

Fixes https://github.com/emk/rust-musl-builder/pull/40 and produces statically linked ARM binaries.

# On a Mac

$ $DOCKER_RUN_ALIAS cargo build --target=armv7-unknown-linux-musleabihf --release

   Compiling hello-arm-static v0.1.0 (file:///home/rust/src)
   Finished release [optimized] target(s) in 5.87 secs

Binary copied to a Raspberry Pi 2:

# This is a Raspberry Pi 2

$ uname -a
Linux Pi2 4.9.80-v7+ #1098 SMP Fri Mar 9 19:11:42 GMT 2018 armv7l GNU/Linux

$ ldd hello-arm-static
    not a dynamic executable

$ file hello-arm-static
hello-arm-static: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV),
statically linked, BuildID[sha1]=e45cafee899493b39610565d68e0a4f7e65dab88,
not stripped

$ ./hello-arm-static
Hello, world!
emk commented 6 years ago

This is great!

Would you be interested in adding an example in examples/ and updating ./test-image.sh to check that the new example is always statically linked? This would prevent me from breaking it accidentally, which is a thing that can happen. :-/

snobu commented 6 years ago

Yes, sure thing, i'll take a look tomorrow.