Skip to content
Latchkey

cargo "failed to run custom build command for openssl-sys" in CI

The openssl-sys build script tries to locate the system OpenSSL via pkg-config and fails because the development headers or pkg-config itself are not installed on the runner. The crate cannot link against a library it cannot find.

What this error means

cargo build fails with "error: failed to run custom build command for openssl-sys vX" and a note that pkg-config could not find openssl, or to set OPENSSL_DIR.

cargo
error: failed to run custom build command for `openssl-sys v0.9.102`
  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. ... try installing `pkg-config` and `libssl-dev`.
  --- stderr
  thread 'main' panicked at .../openssl-sys/build/find_normal.rs

Common causes

Missing OpenSSL development files

A slim runner image lacks libssl-dev (Debian/Ubuntu) or openssl-devel (RHEL), so there are no headers or .pc file for the build script to read.

pkg-config is not installed

Without pkg-config, the build script cannot query where OpenSSL lives even when the library is present.

How to fix it

Install pkg-config and the OpenSSL dev package

Add the system packages the build script needs before cargo runs.

Terminal
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev

Use the vendored OpenSSL feature

Build OpenSSL from source via the vendored feature so no system library is required.

Cargo.toml
[dependencies]
openssl = { version = "0.10", features = ["vendored"] }

How to prevent it

  • Install pkg-config and -dev system libraries in a setup step.
  • Prefer the vendored feature when a system OpenSSL is unavailable.
  • Bake required system libraries into a custom runner image.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →