Skip to content
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

Can't build for musl on Linux #603

Closed
Timmmm opened this issue Mar 21, 2017 · 11 comments
Closed

Can't build for musl on Linux #603

Timmmm opened this issue Mar 21, 2017 · 11 comments

Comments

@Timmmm
Copy link

Timmmm commented Mar 21, 2017

I'm trying to build something that uses rust-openssl on Ubuntu 16.04 using the -musl target.

cargo build --release --target=x86_64-unknown-linux-musl

First when I build it it tells me to export PKG_CONFIG_ALLOW_CROSS=1. Not sure why but whatever; I did it.

Unfortunately then it seems to have trouble finding the OpenSSL headers. I installed them with sudo apt install libssl-dev.

cargo:warning=/home/parallels/myapp/target/x86_64-unknown-linux-musl/release/build/openssl-sys-9bee6f02b4f3e608/out/expando.c:2:33: fatal error: openssl/opensslconf.h: No such file or directory

You can do export OPENSSL_DIR=/usr/include/x86_64-linux-gnu and then it finds the headers, however then you get this error:

thread 'main' panicked at 'OpenSSL library directory does not exist: /usr/include/x86_64-linux-gnu/lib', /home/parallels/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/openssl-sys-0.9.9/build.rs:55
@sfackler
Copy link
Owner

You can use OPENSSL_LIB_DIR and OPENSSL_INCLUDE_DIR when the directories are split like this.

@Timmmm
Copy link
Author

Timmmm commented Mar 21, 2017

Hmmm the problem is it looks for openssl/opensslconf.h and openssl/opensslv.h but those are in different paths in Ubuntu, for some insane reason:

/usr/include/x86_64-linux-gnu/openssl/opensslconf.h
/usr/include/openssl/opensslv.h

It works with the non-musl target though. Maybe I need to link /usr/include/x86_64-linux-musl/openssl to /usr/include/x86_64-linux-gnu/openssl?

@Timmmm
Copy link
Author

Timmmm commented Mar 21, 2017

Yeah that seemed to do the trick. Although now libssh2-sys won't compile because it includes openssl/sha.h and apparently doesn't use OPENSSL_INCLUDE_DIR. Ugh. Can't wait for someone to rewrite OpenSSL in Rust.

@sfackler
Copy link
Owner

I'm confused - if you're cross-compiling to MUSL, you'll probably need an OpenSSL cross-compiled for MUSL as well. If you're not cross-compiling, pkg-config will handle all of this configuration for you when using the normal Ubuntu OpenSSL install.

@Timmmm
Copy link
Author

Timmmm commented Mar 21, 2017

Ah yes good point. I give up!

@Timmmm Timmmm closed this as completed Mar 21, 2017
@fourohfour
Copy link

fourohfour commented Oct 31, 2017

Note to anyone who comes across an error like this in the future - I was able to get this to work by building openssl-1.0.2l from source. Make sure that whatever path you give to ./config --openssldir={path} * when building openssl, you also export as the environment variable OPENSSL_DIR for the rust-openssl ** build. It might be necessary to point OPENSSL_INCLUDE_DIR and OPENSSL_LIB_DIR as well, but normally rust-openssl finds what it needs without issues.

* /usr/local/ssl worked well for me.

** or perhaps a crate that depends it such as cargo

@tobias47n9e
Copy link

Confirming that same error happens on Ubuntu 17.10 with openssl-sys v0.9.27.

@parasyte
Copy link

I just landed on this ticket looking for a way to build native-tls with MUSL. What worked for me was building in clux/muslrust

@sztomi
Copy link

sztomi commented Jun 20, 2020

@parasyte thank you so much for mentioning that here, works like a charm.

@ctopher7
Copy link

@parasyte thanks for saving my life. Been searching to compile my app with the rust official image and keep crashing on openssl. This image works like a charm

@Ujang360
Copy link

I solved this with openssl = { version = "=0.10.33", features = ["vendored"] }

svix-daniel pushed a commit to svix/svix-webhooks that referenced this issue Apr 18, 2023
// only the default-tls
cargo tree

// both since features are additive
cargo tree --features rustls-tls

// only rustls-tls
cargo tree --features rustls-tls --no-default-features

closes #889

## Motivation

Bellow is verbatim copy from issue #889 created by @msdinit

We are building our application against musl, cross-compiling it from
regular libc Ubuntu. However, we are having issues with svix client,
because it depends on system OpenSSL, which in our case would be linked
against libc. There sfackler/rust-openssl#603,
but they are a bit involved.

## Solution

Added cargo features allowing users to choose which ssl version to use
for svix reqwest http client, keeping backwards compatibility.
svix-gabriel pushed a commit to svix/svix-webhooks that referenced this issue Apr 18, 2023
// only the default-tls
cargo tree

// both since features are additive
cargo tree --features rustls-tls

// only rustls-tls
cargo tree --features rustls-tls --no-default-features

closes #889

## Motivation

Bellow is verbatim copy from issue #889 created by @msdinit

We are building our application against musl, cross-compiling it from
regular libc Ubuntu. However, we are having issues with svix client,
because it depends on system OpenSSL, which in our case would be linked
against libc. There sfackler/rust-openssl#603,
but they are a bit involved.

## Solution

Added cargo features allowing users to choose which ssl version to use
for svix reqwest http client, keeping backwards compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants