rust-openssl: Could not find directory of OpenSSL installation

Viewed 2807

I am attempting to compile a rust binary in docker but the compilation fails saying openssl is not found despite it being installed. Other answers suggest that having pkg-config and libssl-dev installed resolves the issue, but they already are installed. I believe this issue is related to cross compilation as I have been able to get this image built when the host and target are the same.

Dockerfile:

FROM rust:1.57.0 AS build
WORKDIR /usr/src

RUN rustup target add x86_64-unknown-linux-musl

RUN USER=root cargo new project
WORKDIR /usr/src/project
COPY Cargo.toml Cargo.lock ./
RUN apt-get update \
&& apt-get upgrade \
&& apt-get install -y cmake pkg-config libssl-dev
RUN cargo build --release

Error:

#18 14.01    Compiling openssl-sys v0.9.72
#18 14.17 error: failed to run custom build command for `openssl-sys v0.9.72`
#18 14.18 
#18 14.18 Caused by:
#18 14.18   process didn't exit successfully: `/usr/src/project/target/release/build/openssl-sys-64e55e6c4223d7aa/build-script-main` (exit status: 101)
#18 14.18   --- stdout
#18 14.18   cargo:rustc-cfg=const_fn
#18 14.18   cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR
#18 14.18   X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR unset
#18 14.18   cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
#18 14.18   OPENSSL_LIB_DIR unset
#18 14.18   cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_INCLUDE_DIR
#18 14.18   X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_INCLUDE_DIR unset
#18 14.18   cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
#18 14.18   OPENSSL_INCLUDE_DIR unset
#18 14.18   cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR
#18 14.18   X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR unset
#18 14.18   cargo:rerun-if-env-changed=OPENSSL_DIR
#18 14.18   OPENSSL_DIR unset
#18 14.18   cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
#18 14.18   cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64-unknown-linux-musl
#18 14.18   cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64_unknown_linux_musl
#18 14.18   cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
#18 14.18   cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
#18 14.18   cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-musl
#18 14.18   cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_musl
#18 14.18   cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
#18 14.18   cargo:rerun-if-env-changed=PKG_CONFIG
#18 14.18   cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-musl
#18 14.18   cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_musl
#18 14.18   cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
#18 14.18   cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
#18 14.18   run pkg_config fail: "pkg-config has not been configured to support cross-compilation.\n\nInstall a sysroot for the target platform and configure it via\nPKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a\ncross-compiling wrapper for pkg-config and set it via\nPKG_CONFIG environment variable."
#18 14.18 
#18 14.18   --- stderr
#18 14.18   thread 'main' panicked at '
#18 14.18 
#18 14.18   Could not find directory of OpenSSL installation, and this `-sys` crate cannot
#18 14.18   proceed without this knowledge. If OpenSSL is installed and this crate had
#18 14.18   trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
#18 14.18   compilation process.
#18 14.18 
#18 14.18   Make sure you also have the development packages of openssl installed.
#18 14.18   For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.
#18 14.18 
#18 14.18   If you're in a situation where you think the directory *should* be found
#18 14.18   automatically, please open a bug at https://github.com/sfackler/rust-openssl
#18 14.18   and include information about your system as well as this message.
#18 14.18 
#18 14.18   $HOST = aarch64-unknown-linux-gnu
#18 14.18   $TARGET = x86_64-unknown-linux-musl
#18 14.18   openssl-sys = 0.9.72
#18 14.18 
#18 14.18   ', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.72/build/find_normal.rs:180:5
0 Answers
Related