rust-cross / rust-musl-cross

Docker images for compiling static Rust binaries using musl-cross
MIT License
620 stars 68 forks source link

Output binary not statically linked? #22

Closed luser closed 3 years ago

luser commented 5 years ago

Hi! I'm trying to use your Docker image to produce a statically-linked mipsel binary (for use on an Ubiquiti EdgeRouter). The output binary seems to wind up dynamically linking against libc and libgcc_s though:

luser@eye7:/build/snippet$ docker run --rm -it -v "$(pwd)":/home/rust/src messense/rust-musl-cross:mipsel-musl cargo build --release
    Updating crates.io index
  Downloaded itoa v0.3.4
   Compiling itoa v0.3.4
   Compiling snippet v0.1.4-alpha.0 (/home/rust/src)
    Finished release [optimized] target(s) in 38.61s
luser@eye7:/build/snippet$ file target/mipsel-unknown-linux-musl/release/snippettarget/mipsel-unknown-linux-musl/release/snippet: ELF 32-bit LSB shared object, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-mipsel.so.1, with debug_info, not stripped
luser@eye7:/build/snippet$ readelf -d target/mipsel-unknown-linux-musl/release/snippet | rg NEEDED
 0x00000001 (NEEDED)                     Shared library: [libgcc_s.so.1]
 0x00000001 (NEEDED)                     Shared library: [libc.so]

The output above is from compiling this simple test project I have laying around for such purposes. Is this intended behavior or did I miss a step in the directions?

Thanks!

messense commented 5 years ago

This post seems related: https://users.rust-lang.org/t/static-cross-compiled-binaries-arent-really-static/6084

messense commented 3 years ago

I think it can be force to output statically linked binary with RUSTFLAGS="-C target-feature=+crt-static".