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

OpenSSL error #510

Closed
rustbomber opened this issue Jan 11, 2021 · 26 comments
Closed

OpenSSL error #510

rustbomber opened this issue Jan 11, 2021 · 26 comments
Labels

Comments

@rustbomber
Copy link

I use x86_64-unknown-linux-musl to cross build for linux, It worked well before, and suddenly reported this error one day

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

Caused by:
  process didn't exit successfully: `/target/debug/build/openssl-sys-db18d493257de4f7/build-script-main` (exit code: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR
  X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_INCLUDE_DIR
  X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR
  X86_64_UNKNOWN_LINUX_MUSL_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=OPENSSL_STATIC
  cargo:rerun-if-env-changed=OPENSSL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_PATH
##
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  run pkg_config fail: "`\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\"` did not exit successfully: exit code: 1\n--- stderr\nPackage openssl was not found in the pkg-config search path.\nPerhaps you should add the directory containing `openssl.pc\'\nto the PKG_CONFIG_PATH environment variable\nNo package \'openssl\' found\n"

  --- 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-musl
  openssl-sys = 0.9.60

  ', /cargo/registry/src/mirrors.ustc.edu.cn-12df342d903acd47/openssl-sys-0.9.60/build/find_normal.rs:173:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
@kangalio
Copy link

@akaylh Did you find a fix to this issue?

@rustbomber
Copy link
Author

@akaylh Did you find a fix to this issue?

no, I can not find reason.

@kangalio
Copy link

You could reopen this issue then, since the problem still persists.

@353fc443
Copy link

I'm also facing the same issue

@rustbomber rustbomber reopened this Jun 21, 2021
@andrewbanchich
Copy link

andrewbanchich commented Aug 5, 2021

This is happening because OpenSSL was removed from the Docker container.

There are a couple ways to fix this. The easiest, and my preferred, is to use Rustls instead of OpenSSL. It's common for dependencies which use OpenSSL by default to provide a way for you to tell them to use Rustls instead via feature flags.

Example: reqwest = { version = "0.10.8", default-features = false, features = ["rustls-tls"] }

You can look through your Cargo.lock to find which dependencies are using OpenSSL, then configure them to use Rustls instead. Once that's done, everything should build again.

The alternative is more complicated: configure a custom Docker image based on the one used by cross, but also install OpenSSL.

doetlingerlukas added a commit to doetlingerlukas/edge-connector-rs that referenced this issue Sep 24, 2021
@banjiaojuhao
Copy link

Install musl toolchains:
sudo apt install musl-dev musl-tools
And add this to your Cargo.toml dependencies:
openssl-sys = { version = "0.9", features = ['vendored'] }

@Mohsen7s
Copy link

I have the same issue, any update ?

@andrewbanchich
Copy link

@Mohsen7s see my above comment

@andrewbanchich
Copy link

andrewbanchich commented Jan 31, 2022

@adamgreig I think this issue can be closed.

@Mohsen7s
Copy link

@andrewbanchich I'm not looking for tricky hacks. This has to be fixed internally not forcing developers to change code

@andrewbanchich
Copy link

andrewbanchich commented Jan 31, 2022

It isn't a trick or a hack. Cross doesn't allow us to use OpenSSL anymore due to the issue I referenced. This issue is about why this error happens.

If you don't want to just use Rustls instead of building a custom Docker image, I think you'd need to open an issue to ask them to offer a custom Docker image that includes OpenSSL.

@ZanderBrown
Copy link

fwiw the workaround doesn't seem to work with the v2 resolver, and thus 2021 edition default settings

@andrewbanchich
Copy link

I've been using it with the 2021 edition without any issues. What error are you seeing @ZanderBrown ?

@ZanderBrown
Copy link

Despite setting openssl to be vendored somehow the overall tree often ends up with openssl trying to find openssl

Of course this may well be a problem with the openssl crate

@andrewbanchich
Copy link

And my solution is not an option for you?

@ZanderBrown
Copy link

If you mean rusttls, no — for whatever reason connections fail

What does work is overriding the resolver version back to v1

@Emilgardis
Copy link
Member

If you mean rusttls, no — for whatever reason connections fail

What does work is overriding the resolver version back to v1

If setting resolver to v1 is working for you than you have a dependency issue, some crate you're using does not have the correct features enabled in the dev/release profile, you should be able to solve it if you compare what features are enabled when v1 is set, it's most likely a dev dependency that depends on the feature you need. The only workaround for this issue from cross' side is custom-docker-images.

@Mohsen7s
Copy link

Mohsen7s commented Feb 3, 2022

@andrewbanchich Your solution is only applicable in situations where OpenSSL is used by rust itself. When there its a C code which based on OpenSSL its not possible to switch to rustls without making change to underlying C project based on OpenSSL. To me this is called a hack or trick. There are plenty of C libraries based on OpenSSL which are used by rust bridges.

@andrewbanchich
Copy link

I also explained you can create a custom Docker image. This should work for whatever use case you have.

@Mohsen7s
Copy link

Mohsen7s commented Feb 3, 2022

@andrewbanchich Yeah I knew that but I guess the whole point of using cross-rs, which described itself as “Zero setup” cross compilation its to use it without setup. That's why I ask developers to support OpenSSL, at least they can provide a custom docker image. Anyway thanks for your tips.

@sify21
Copy link

sify21 commented Feb 16, 2022

rustls has an issue connecting to ip addresses, the issue has been around for a long time.

@realtica
Copy link

The same issued here :(

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented May 29, 2022

This is fixed and documented.This also links to the relevant documentation for using external dependencies. You will need to use the vendored option or build from source:

openssl = { version = "0.10", features = ["vendored"] }

For glibc images (not musl ones), see my comment here. For these glibc images, support for pkg-config has now been added to the pre-built images, so you only need to install these dependencies from the package manager.

Please note that you may have to use an older version of cross (the latest from crates.io, not from git), since we currently need to downgrade musl libc due to #485, which I believe affects the non-vendored versions of OpenSSL.

I've also added instructions for how to use OpenSSL specifically on the Recipes page on the wiki, since it is a common dependency.

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented May 29, 2022

@andrewbanchich Yeah I knew that but I guess the whole point of using cross-rs, which described itself as “Zero setup” cross compilation its to use it without setup. That's why I ask developers to support OpenSSL, at least they can provide a custom docker image. Anyway thanks for your tips.

We can't exactly support every external C dependency or our builds would become very complex, our images large, and it would be way beyond the scope of this project. Especially for musl targets where it would need to be compiled from source. We've started documenting how to set up using cross with external dependencies to minimize the effort required.

@newmizanur
Copy link

2024: Following working for me. reqwest = { version = "0.12.9", features = [ "json", "rustls-tls", ], default-features = false }

@Emilgardis
Copy link
Member

2024: Following working for me. reqwest = { version = "0.12.9", features = [ "json", "rustls-tls", ], default-features = false }

You dont need cross-rs for this, you could just use cargo :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests