Statically compile (musl) a dynamic library (cdylib)


#1

Hi all,

is a week I am trying to compile a dynamic rust library (cdylib) without dynamically linking any glibc pieces.

This seems an almost impossible beast to tackle, but I am wondering if any of you have ever succeeded.

What I tried so far is something like:

$ cargo build --target=x86_64-unknown-linux-musl               
error: cannot compile `rediSQL v0.5.0 (file:///home/simo/rediSQL)` package, because target `x86_64-unknown-linux-musl` does not support the `cdylib` crate type
# Nope :(
$ RUSTFLAGS="-C target-feature=+crt-static" cargo build --target=x86_64-unknown-linux-musl                                                       
error: cannot compile `rediSQL v0.5.0 (file:///home/simo/rediSQL)` package, because target `x86_64-unknown-linux-musl` does not support the `cdylib` crate type
# Nope :(
$ RUSTFLAGS="-C target-feature=-crt-static" cargo build --target=x86_64-unknown-linux-musl      
    Finished dev [unoptimized + debuginfo] target(s) in 173.60 secs
# Almost
$ ldd target/x86_64-unknown-linux-musl/debug/libredis_sql.so 
        linux-vdso.so.1 =>  (0x00007fff795a5000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff61d54d000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff61d183000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff61dc3e000)
# Nope :(

Do you guys have any alternative to this?

It is a quite complex build and I would prefer to keep it on my own machine (it requires bindgen that needs libclang).