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

Only builds one completely static binary #82

Closed Ploppz closed 5 years ago

Ploppz commented 5 years ago

Some Information

Binaries defined in Cargo.toml:

[[bin]]
name = "api_server"
path = "src/api_server/main.rs"

[[bin]]
name = "scanner"
path = "src/scanner/main.rs"

How I start rust-musl-builder:

alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src \
    -v cargo-git:/home/rust/.cargo/git \
    -v cargo-registry:/home/rust/.cargo/registry \
    -v target:/home/rust/src/target \
    ekidd/rust-musl-builder:nightly-2019-07-08 \
    sudo chown -R rust:rust /home/rust/.cargo/git /home/rust/.cargo/registry /home/rust/src/target; \
    bash ' 

rust-toolchain has nightly-2019-07-08 as well.

Problem

After running cargo build --release, only one binary is to be found in target/x86_64-unknown-linux-musl/release/:

$ ldd target/x86_64-unknown-linux-musl/release/api_server
    not a dynamic executable

scanner is only found in target/release/scanner:

$ ldd target/release/scanner
    linux-vdso.so.1 (0x00007fff90dd7000)
    libssl.so.1.1 => /usr/lib/libssl.so.1.1 (0x00007f9fa1643000)
    libcrypto.so.1.1 => /usr/lib/libcrypto.so.1.1 (0x00007f9fa136f000)
    libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f9fa136a000)
    librt.so.1 => /usr/lib/librt.so.1 (0x00007f9fa135f000)
    libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f9fa133e000)
    libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f9fa1324000)
    libc.so.6 => /usr/lib/libc.so.6 (0x00007f9fa115f000)
    /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f9fa1be4000)
    libm.so.6 => /usr/lib/libm.so.6 (0x00007f9fa1019000)

This is what rust-musl-builder writes to and uses actually:

$ cargo run --bin scanner --release
    Finished release [optimized] target(s) in 0.13s
     Running `target/release/scanner`

I would expect it to build a static binary for scanner as well.

Ploppz commented 5 years ago

It seems that it does not have to do with the number of binaries, but rather is the same problem as #80 .