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

Added ARMhf target #40

Closed snobu closed 6 years ago

snobu commented 6 years ago

This PR adds ARMhf (think Raspberry Pi) target and compiler.

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

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

$ file target/armv7-unknown-linux-gnueabihf/release/hello-arm

target/armv7-unknown-linux-gnueabihf/release/hello-arm: ELF 32-bit LSB shared object,
ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for
GNU/Linux 3.2.0, BuildID[sha1]=6cc5316eeeccdf66b24decb00515988194be4036,
with debug_info, not stripped

Tested OK on Raspberry Pi 2.

Feel free to reject in case ARM doesn't fit the purpose of this image. No hard feelings. Pun intended :)

snobu commented 6 years ago

Oh wait you're right, let me try to link it statically, hopefully I can do this for ARM with current tool chain.

snobu commented 6 years ago
$ ldd target/armv7-unknown-linux-gnueabihf/release/hello-arm
    not a dynamic executable

$ file target/armv7-unknown-linux-gnueabihf/release/hello-arm
target/armv7-unknown-linux-gnueabihf/release/hello-arm: ELF 32-bit LSB shared object,
ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3,
for GNU/Linux 3.2.0, BuildID[sha1]=6cc5316eeeccdf66b24decb00515988194be4036, not stripped

Well, this is a little strage or i don't understand it enough. Shouldn't ldd say it's dynamic as well? Maybe i should do this on the Pi, not on my Mac, could ldd lie to me given it's not executing on the same target platform as the binary passed to it?

LATER EDIT: Ok, i got it, i had the wrong target, i need the ARM musl target not the GNU one to get static binaries. Will fix and send PR. New result:

target/armv7-unknown-linux-musleabihf/release$ file hello-arm
hello-arm: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, ...