How to compile a static project mull binar with native dependencies?

I have a project with dependencies on Hyper and Diesel, and because of this, on the native OpenSSL and libpq libraries. The project is based on nightly Rust, because it uses compiler plugins.

My current attempt is to build a Docker container. I have MUSL libc and make'd libraries installed with a prefix /usr/local/musl. I run with the cargofollowing command: (Not sure if some options are redundant, I'm not too good at the compiler chain and not even sure if they end with the linker, but I have to try, right.)

LDFLAGS="-static -L/usr/local/musl/lib" \
LD_LIBRARY_PATH=/usr/local/musl/lib:$LD_LIBRARY_PATH \
CFLAGS="-I/usr/local/musl/include" \
PKG_CONFIG_PATH=/usr/local/musl/lib/pkgconfig \
cargo build --release --target=x86_64-unknown-linux-musl

When I lddreceived the file, it shows this:

$ ldd server
linux-vdso.so.1 (0x00007fffb878e000)
libpq.so.5 => /usr/local/musl/lib/libpq.so.5 (0x00007f4d730e7000)
libssl.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f4d72e82000)
libcrypto.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f4d72a85000)
libc.so => /usr/local/musl/lib/libc.so (0x00007f4d727f6000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4d725f2000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4d72246000)
/lib/ld64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x000055e2124a2000)

, "x86_64-linux-gnu"! ?

, Rust. ldd , , , .

--verbose Cargo, rustc rustc : http://pastebin.com/ywv0zNBK (, outdir -Z print-link-args, ) print-link-args, : http://pastebin.com/Aw43qd7h

cargo rustc , ?

+6
2

, , - , OpenSSL - build.rs build.rs Cargo rustc. (: - cargo:rustc-link-lib=static=ssl Cargo .)

, "" GCC - . build.rs , , . OpenSSL env, , OPENSSL_DIR, OPENSSL_STATIC ..

, , ( , docker_codegen). , . , , libc.so , MUSL libc.so (LD_LIBRARY_PATH ..).

Dockerfile, . .

https://github.com/golddranks/rust_musl_docker/blob/master/Dockerfile.template

+9

Rust , :

$ rustup target add x86_64-unknown-linux-musl
$ cargo build --release --target=x86_64-unknown-linux-musl
-1

Source: https://habr.com/ru/post/1661294/


All Articles