Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why rust is failing to build command for openssl-sys v0.9.60 even after local installation?

Tags:

openssl

rust

I'm facing the error failed to run custom build command for openssl-sys v0.9.60 while trying to build my rust program. Here are the main.rs and the Cargo.toml files.

main.rs

extern crate reqwest;

fn main() {
    let mut resp = reqwest::get("http://www.governo.mg.gov.br/Institucional/Equipe").unwrap();
    assert!(resp.status().is_success());
}

Cargo.toml

[package]
name = "get_sct"
version = "0.1.0"
authors = ["myname <myemail>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
reqwest = "0.10.10"

I installed openssl locally (as suggested in this question), using:

git clone git://git.openssl.org/openssl.git
cd openssl
./config --openssldir=/usr/local/ssl
make
make test
sudo make install

Finally, I ran export OPENSSL_DIR="/usr/local/ssl"

I noted I already had a anaconda instalation of openssl which was in my default path. To change the default path of openssl to the github instalation I ran chmod -x MYPATH/anaconda3/bin/openssl and now which openssl returns /usr/local/bin/openssl.

I also have pkg-config installed (as suggested in this question). Running which pkg-config returns /usr/bin/pkg-config

However, when I run cargo run again the program print the same error message. Here is the entire error message:

> cargo run
   Compiling openssl-sys v0.9.60
   Compiling tokio v0.2.24
   Compiling pin-project-internal v0.4.27
   Compiling pin-project-internal v1.0.2
   Compiling mime_guess v2.0.3
   Compiling url v2.2.0
error: failed to run custom build command for `openssl-sys v0.9.60`

Caused by:
  process didn't exit successfully: `/PACKAGEPATH/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_GNU_OPENSSL_LIB_DIR
  X86_64_UNKNOWN_LINUX_GNU_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_GNU_OPENSSL_INCLUDE_DIR
  X86_64_UNKNOWN_LINUX_GNU_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_GNU_OPENSSL_DIR
  X86_64_UNKNOWN_LINUX_GNU_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR = /usr/local/ssl

  --- stderr
  thread 'main' panicked at 'OpenSSL library directory does not exist: /usr/local/ssl/lib', /home/lucas/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.60/build/main.rs:66:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build faile

It looks like that rust is searching for ssl in /usr/local/ssl/lib. In fact, there is a /usr/local/ssl folder in my PC, but there is no lib there.

What am I doing wrong here? How can make my local installation of openssl work with rust correctly?

like image 256
Lucas Avatar asked Jan 03 '21 18:01

Lucas


People also ask

Could not find directory of OpenSSL installation and this `- Sys?

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. The fix is, luckily, rather easy.

What is the latest version of OpenSSL for rust?

OpenSSL bindings for the Rust programming language. Documentation. The current supported release of openssl is 0.10 and openssl-sys is 0.9. New major versions will be published at most once per year. After a new release, the previous major version will be partially supported with bug fixes for 3 months, after which support will be dropped entirely.

How do I build a supported version of OpenSSL?

In order to build a supported version of OpenSSL, you will have to switch to some 1.1.1 branch or tag. Alternatively, you can download the 1.1.1 version from OpenSSL's download page.

Should I use environment variables to find the OpenSSL installation directory?

If so, then you should unset the OPENSSL_DIR environment variable otherwise that will (continue to) override the crate's automatic mechanisms to find the OpenSSL installation. If you still want to stick with the Manual configuration, then indeed you should use environment variables, and OPENSSL_DIR seems a convenient one.

How do I install OpenSSL locally on GitHub?

I installed openssl locally (as suggested in this question ), using: I noted I already had a anaconda instalation of openssl which was in my default path. To change the default path of openssl to the github instalation I ran chmod -x MYPATH/anaconda3/bin/openssl and now which openssl returns /usr/local/bin/openssl.


3 Answers

I have no experience with installing this myself but may be able to give some pointers.

First of all about your effort to install OpenSSL. After cloning the repository, you do not select any particular branch before configuring and making. This means that you are building the master branch, which is an evolving version of OpenSSL 3.0.0. This is not a supported version according to the crate's documentation. In order to build a supported version of OpenSSL, you will have to switch to some 1.1.1 branch or tag. Alternatively, you can download the 1.1.1 version from OpenSSL's download page.

That said, it does not seem necessary to install OpenSSL from source. Under the section Automatic, the documentation explains that the crate can deal with all kinds of typical OpenSSL installations. It may be easier for you to follow that, if possible in your case. If so, then you should unset the OPENSSL_DIR environment variable otherwise that will (continue to) override the crate's automatic mechanisms to find the OpenSSL installation.

If you still want to stick with the Manual configuration, then indeed you should use environment variables, and OPENSSL_DIR seems a convenient one. However, it does not mean the same thing as the openssldir parameter that you used in your configure command ./config --openssldir=/usr/local/ssl. To get the details, check out the meaning of that configuration parameter. In fact, the crate's meaning of OPENSSL_DIR corresponds to the --prefix setting (which you did not configure).

The problem you are running into now is that your OPENSSL_DIR variable points to your directory for OpenSSL configuration files, whereas the crate expects it to point to the top of the actual OpenSSL installation directory tree (which in your case seems to reside at /usr/local).

like image 97
Reinier Torenbeek Avatar answered Nov 15 '22 07:11

Reinier Torenbeek


This solved the issue for me in Ubuntu:

sudo apt install libssl-dev
like image 21
Julian Avatar answered Nov 15 '22 07:11

Julian


I used the following set of commands

 sudo apt install pkg-config
 sudo apt-get install libudev-dev
like image 45
Sadaf Shafi Avatar answered Nov 15 '22 06:11

Sadaf Shafi