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 to find shared openssl with pkg-config even though pkg-config can find it #1865

Closed
timabell opened this issue Mar 30, 2023 · 1 comment

Comments

@timabell
Copy link

Context

I'm opening this because the build output said to open an issue here if it should work and doesn't. I think this falls in that category but correct me if I'm wrong here.

Observed issue

Adding libgit to my project introduced openssl, which seems to be the cause of my broken release build.

Here's the output from a failed build:

 cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  run pkg_config fail: `PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" "pkg-config" "--libs" "--cflags" "openssl"` did not exit successfully: exit status: 1
  error: could not find system library 'openssl' required by the 'openssl-sys' crate

  --- stderr
  Package openssl was not found in the pkg-config search path.
  Perhaps you should add the directory containing `openssl.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'openssl' found


  --- stderr
  thread 'main' panicked at '

  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = x86_64-unknown-linux-gnu
  $TARGET = x86_64-unknown-linux-gnu
  openssl-sys = 0.9.82

If I understand that correctly it's telling me that pkg-config couldn't find libssl.

Troubleshooting attempts

Apt

I tried adding libssl-dev to the build workflow, but it tells me libssl-dev is already installed so it's not that.

Run sudo apt-get install -y pkg-config libssl-dev
  sudo apt-get install -y pkg-config libssl-dev
  shell: /usr/bin/bash -e {0}
  env:
    CARGO_TERM_COLOR: always
Reading package lists...
Building dependency tree...
Reading state information...
pkg-config is already the newest version (0.29.2-1ubuntu3).
libssl-dev is already the newest version (3.0.2-0ubuntu1.8).
0 upgraded, 0 newly installed, 0 to remove and 13 not upgraded.

https://github.com/timabell/gitopolis/actions/runs/4548572206/jobs/8019736711#step:3:1

Test pkg-config

I added a step to run the same pkg-config command directly in the build and to my surprise that command succeed with output and a zero exit code.

Run PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" pkg-config --libs --cflags openssl
  PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" pkg-config --libs --cflags openssl
  echo $?
  echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
  shell: /usr/bin/bash -e {0}
  env:
    CARGO_TERM_COLOR: always
-I/usr/include -lssl -lcrypto
0
PKG_CONFIG_PATH=

https://github.com/timabell/gitopolis/actions/runs/4548572206/jobs/8019736711#step:4:1

I don't understand why running pkg-config in the build would work, but when run as part of the cargo build it doesn't. This is the reason for submitting this issue.

Workarounds

Possible workaround: Specifying paths

I didn't get as far as trying to supply the paths directly via environment variables to bypass the need for pkg-config but I guess in theory that could be a valid workaround. I don't know what the paths would be for this particular image.

Workaround: "Feature=Vendored"

I got it working for my project by enabling the "vendored" feature as suggested on stackoverflow, but I still think this should have worked, and given it's a public repo & github action you'll be able to see everything and see what you think. It's not ideal to enable the vendored flag as it means more build-time dependencies (perl etc).

What should have happened

I think this build should have "just worked", because pkg-config and libssl-dev were both available, and pkg-config is working when run as an independent step.

timabell added a commit to rustworkshop/gitopolis that referenced this issue Mar 30, 2023
https://stackoverflow.com/questions/65553557/why-rust-is-failing-to-build-command-for-openssl-sys-v0-9-60-even-after-local-in#comment118424959_65554916

This causes the openssl crate to build the C openssl library from source and statically link it, avoiding the currently failing need to find the system library. See https://docs.rs/openssl/latest/openssl/#vendored

Failure message in CI was:

```
	...
	  run pkg_config fail: `PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" "pkg-config"
	"--libs" "--cflags" "openssl"` did not exit successfully: exit status: 1
	  error: could not find system library 'openssl' required by the
	'openssl-sys' crate

	  --- stderr
	  Package openssl was not found in the pkg-config search path.
	  Perhaps you should add the directory containing `openssl.pc'
	  to the PKG_CONFIG_PATH environment variable
	  No package 'openssl' found

	  --- stderr
	  thread 'main' panicked at '

	  Could not find directory of OpenSSL installation, and this `-sys`
	crate cannot
	  proceed without this knowledge. If OpenSSL is installed and this crate
	had
	  trouble finding it,  you can set the `OPENSSL_DIR` environment
	variable for the
	  compilation process.

	  Make sure you also have the development packages of openssl installed.
	  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

	  If you're in a situation where you think the directory *should* be
	found
	  automatically, please open a bug at
	https://github.com/sfackler/rust-openssl
	  and include information about your system as well as this message.
```
https://github.com/timabell/gitopolis/actions/runs/4495064891/jobs/7908291289#step:5:144

Likely broken since libgit was added in fec939c

Issue written up in sfackler/rust-openssl#1865
@sfackler
Copy link
Owner

You are building with the cross tool, which runs the build in a Docker image. Installing OpenSSL on the host will not affect its availability in the container.

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

2 participants