-
-
Notifications
You must be signed in to change notification settings - Fork 750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to cross compile for musl #1627
Comments
The system's copy of OpenSSL is built against glibc, not musl. If you want a fully static binary, you need to build OpenSSL against musl as well. You could do this yourself or by enabling the |
You are right of course, but for this project openssl is a transitive dependency. I don't want to add it as a primary dependency just to enable this feature, especially since it builds fine in CI (what I am trying to do is document development processes as well). The solution I have grudgingly settled on is a convoluted process involving docker to do the cross-compile. |
@detly mind sharing some of the details? |
@defi-degaulle I haven't tried to reproduce this recently, so you might need to work on this a bit, but basically:
Presto, the properly linked binary should appear in |
for anyone stumbling across issues like this: If you just want to compile with musl, but openssl is getting in the way, another tip is that most Rust libraries have features that allow you to select rustls over openssl (also called "native-tls" frequently), which can be another easy solution to the openssl/musl compilation problem. (Sometimes you need to set |
For reference i was able to link against openssl in Alpine both statically and dynamically using this Dockerfile To link statically against openssl from alpine
To link dynamically from openssl from alpine (NOTE: you need the "libgcc" package installed in runtime container)
|
Your requirement for it might be due to something else going on? I could not reproduce with EDIT: For reference:
Static vs Dynamic link reproductionMinimal example with # Rust alpine container with extra deps added:
$ docker run --rm -it rust:alpine ash
$ apk add musl-dev openssl-dev openssl-libs-static
# Minimal project example:
$ cargo init /example && cd /example
$ cargo add openssl
# All one command (can paste into terminal without needing `\`)
$ cat > src/main.rs <<EOF
fn main() {
println!("Version: {}", openssl::version::version());
}
EOF
# Check builds successfully:
$ cargo run --release
Version: OpenSSL 3.1.4 24 Oct 2023
# Check built binary is static linked:
$ apk add file
$ file target/release/example
target/release/example: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), static-pie linked, BuildID[sha1]=7f5e22856b30e8134301eb470397c1894d90890a, with debug_info, not stripped
# Nothing is linked (musl ldd outputs ld-musl regardless, can ignore):
$ ldd target/release/example
/lib/ld-musl-x86_64.so.1 (0x7fdcc5a0e000) # vs dynamic link:
$ RUSTFLAGS='-C target-feature=-crt-static' cargo run --release
Version: OpenSSL 3.1.4 24 Oct 2023
$ file target/release/example
target/release/example: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, BuildID[sha1]=d35b6310ac85417c2dbb64ee599e1c7eb745e152, with debug_info, not stripped
$ ldd target/release/example
/lib/ld-musl-x86_64.so.1 (0x7f3f14586000)
libssl.so.3 => /lib/libssl.so.3 (0x7f3f144a9000)
libcrypto.so.3 => /lib/libcrypto.so.3 (0x7f3f1408c000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f3f14068000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f3f14586000)
|
This happens the same way under
cross
with a custom docker image, or barecargo
on an Ubuntu env. To simplify things, I'll just give the local command (for Ubuntu 21.10). This is a GNU host, but what I want is a statically-linked-with-musl-libc binary.Assume I've done
sudo apt install pkg-config libssl-dev musl-tools
.Fundamentally the problem seems to be:
opensslconf.h
is at/usr/include/x86_64-linux-gnu/openssl/opensslconf.h
/usr/include/openssl
So there is no way to set
OPENSSL_INCLUDE_DIR
to a value that satisfies this, andpkg-config
doesn't seem to help.This seems similar to #603, but (a) I would be happy with a statically linked OpenSSL, and I don't think they're doing that and (b) I can't even do this via
cross
with a custom image containing OpenSSL, I get the same error.The text was updated successfully, but these errors were encountered: