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

Build failed in Alpine Linux. #1624

Open
jialez0 opened this issue Apr 24, 2022 · 13 comments
Open

Build failed in Alpine Linux. #1624

jialez0 opened this issue Apr 24, 2022 · 13 comments

Comments

@jialez0
Copy link

jialez0 commented Apr 24, 2022

I tried to build a rust program which rely on openssl-sys, but it failed:

error: failed to run custom build command for `openssl-sys v0.9.72`

Caused by:
  process didn't exit successfully: `/root/ccv1/kata-containers/src/agent/target/debug/build/openssl-sys-7562b43250227d6b/build-script-main` (exit status: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=X86_64_ALPINE_LINUX_MUSL_OPENSSL_NO_VENDOR
  X86_64_ALPINE_LINUX_MUSL_OPENSSL_NO_VENDOR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
  OPENSSL_NO_VENDOR unset

  --- stderr
  thread 'main' panicked at 'don't know how to configure OpenSSL for x86_64-alpine-linux-musl', /root/.cargo/registry/src/mirrors.sjtug.sjtu.edu.cn-7a04d2510079875b/openssl-src-111.18.0+1.1.1n/src/lib.rs:283:18
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

I have already install openssl on my system before:

apk add openssl openssl-dev

How can I solve this problem?

@sfackler
Copy link
Owner

You'll want to file this on the openssl-src crate about it not recognizing the x86_64-alpine-linux-musl target.

@defi-degaulle
Copy link

bump

@lapwat
Copy link

lapwat commented Sep 4, 2023

apk add alpine-sdk openssl-dev

@Skepfyr
Copy link
Collaborator

Skepfyr commented Sep 4, 2023

Does this issue still occur? As far as I can tell x86_64-alpine-linux-musl doesn't exist. I vaguely recall a bunch of discussion about static vs dynamic musl linking a while ago so this may have changed with that.

@james-stevens
Copy link

On Alpine v3.18.3, I'm getting pretty much the same error message when trying to build this package as part of a build of vector (https://vector.dev/)

   Compiling openssl-sys v0.9.92 (https://github.com/vectordotdev/rust-openssl?tag=openssl-sys-v0.9.92_3.0.0#109e2419)
   Compiling hyper v0.14.27
error: failed to run custom build command for `openssl-sys v0.9.92 (https://github.com/vectordotdev/rust-openssl?tag=openssl-sys-v0.9.92_3.0.0#109e2419)`

Caused by:
  process didn't exit successfully: `/opt/github/vector/target/release/build/openssl-sys-15277c7e187a4db8/build-script-main` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=X86_64_ALPINE_LINUX_MUSL_OPENSSL_NO_VENDOR
  X86_64_ALPINE_LINUX_MUSL_OPENSSL_NO_VENDOR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
  OPENSSL_NO_VENDOR unset

  --- stderr
  thread 'main' panicked at 'don't know how to configure OpenSSL for x86_64-alpine-linux-musl', /root/.cargo/git/checkouts/openssl-src-rs-063d49162999cd08/98b1172/src/                                                 lib.rs:333:18
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
make: *** [Makefile:189: build] Error 101

@alex
Copy link
Collaborator

alex commented Sep 6, 2023

This appears to be a consequence of https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/main/rust/alpine-target.patch which Alpine applies.

It's not clear how ecosystem packages are expected to deal with this. However, from simply reading the error message I infer that you could try modifying https://github.com/alexcrichton/openssl-src-rs/blob/26dc3c81d8ebee5f7ec40835e29bf9f37e648ab2/src/lib.rs#L241 to add that target and see if it works. I have no opinion on whether such a PR should be accepted upstream.

@james-stevens
Copy link

Thanks for your incredibly fast response, Alex

I noticed the official Vector binary is called vector-0.32.1-x86_64-unknown-linux-musl.tar.gz, so I was investigating how to change the target from alpine to unknown as this seems to be their solution!

export TARGET=x86_64-unknown-linux-musl isn't the answer :)

I've a ton of experience of building open source, but I'm a total newb on Rust!

Alpine is our go-to platform for containers, but we need an additional feature in vector, so I wanted to see if I could add it.

@james-stevens
Copy link

After grep'ing about the src, found that export OPENSSL_NO_VENDOR=Y solved this issue for me

//! * `OPENSSL_NO_VENDOR` - If set, always find OpenSSL in the system, even if the `vendored` feature is enabled.

@aviplayer
Copy link

aviplayer commented Oct 9, 2023

Does anyone have any recipe to build it?
on alpine 3.16 musl target was working
just
RUN apk add pkgconfig
RUN apk add gcc musl-dev openssl-dev
And then
RUN rustup target add x86_64-unknown-linux-musl
But with 3.18 - start getting this openssl error
I tried solutions, mentioned there, but nothing works

@azasypkin
Copy link

Does anyone have any recipe to build it?

If a statically linked OpenSSL would work for you, you can try following the approach I use here: https://github.com/secutils-dev/secutils/blob/main/Dockerfile (ignore arm64 specific pieces). It works well for me.

@aviplayer
Copy link

Does anyone have any recipe to build it?

If a statically linked OpenSSL would work for you, you can try following the approach I use here: https://github.com/secutils-dev/secutils/blob/main/Dockerfile (ignore arm64 specific pieces). It works well for me.

Thank you @azasypkin, works as a sharm

@james-stevens
Copy link

found that export OPENSSL_NO_VENDOR=Y solved this issue for me

then, when you run it, you have to use vector --openssl-legacy-provider=false

but the OEM binary for musl also works fine for me

@polarathene
Copy link

export TARGET=x86_64-unknown-linux-musl isn't the answer :)

You should be able to use CARGO_BUILD_TARGET=x86_64-unknown-linux-musl to force that target for the build via cargo 👍


found that export OPENSSL_NO_VENDOR=Y solved this issue for me

then, when you run it, you have to use vector --openssl-legacy-provider=false

Lacking context on that connection, but Vector defaults to not having a legacy provider (see their docs at website/content/en/docs/reference/configuration/tls.md).

OPENSSL_NO_VENDOR=1 is an ENV setting that this crate supports:

fn find_openssl(target: &str) -> (Vec<PathBuf>, PathBuf) {
#[cfg(feature = "vendored")]
{
// vendor if the feature is present, unless
// OPENSSL_NO_VENDOR exists and isn't `0`
if env("OPENSSL_NO_VENDOR").map_or(true, |s| s == "0") {
return find_vendored::get_openssl(target);
}
}
find_normal::get_openssl(target)
}

  • As Vector has their Cargo.toml add openssl crate with the vendored feature, using that ENV opts out of it which is why it's a fix.
  • You just need to be able to install openssl crate without vendored, otherwise you'll get some other build error that needs to be addressed.

For reference, additional Alpine/musl advice is covered in this issue: #1627 (comment)

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

10 participants