Rust replit breaks if adding Request

Hi,

I’ve started a small project, and all was going well until I did:
cargo add reqwest

Then rust complained about pkg-config or openssl or libssl-dev, I’m not sure. Here is what is says:

[...]
Compiling openssl-sys v0.9.77
error: failed to run custom build command for `openssl-sys v0.9.77`

Caused by:
  process didn't exit successfully: `/home/runner/reqwest-test/target/debug/build/openssl-sys-a80daff917dc506e/build-script-main` (exit status: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rustc-cfg=openssl
  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 unset
  cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  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-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  run pkg_config fail: "Could not run `\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\"`\nThe pkg-config command could not be found.\n\nMost likely, you need to install a pkg-config package for your OS.\nTry `apt install pkg-config`, or `yum install pkg-config`,\nor `pkg install pkg-config`, or `apk add pkgconfig` depending on your distribution.\n\nIf you've already installed it, ensure the pkg-config command is one of the\ndirectories in the PATH environment variable.\n\nIf you did not expect this build to link to a pre-installed system library,\nthen check documentation of the openssl-sys crate for an option to\nbuild the library from source, or disable features or dependencies\nthat require pkg-config."

  --- 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.77


  It looks like you're compiling on Linux and also targeting Linux. Currently this
  requires the `pkg-config` utility to find OpenSSL but unfortunately `pkg-config`
  could not be found. If you have OpenSSL installed you can likely fix this by
  installing `pkg-config`.

  ', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.77/build/find_normal.rs:191:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
exit status 101

This can be reproduced by starting a new Rust project, and simply adding reqwest and trying to run the hello wolrd code again. See this replit: https://replit.com/@Pierric82/reqwest-test

Any idea how to fix this? Reqwest is a fairly common crate, and I do need to use retrieve some JSON from remote URLs.

Thanks!
Pierric.

1 Like

Hi @Pierric thanks for your message and details of how to replicate.

I think this definitely needs to go to Replit Support if it hasn’t already as you might have found a bug with the Rust template or the reqwest crate in Replit.

To do this click on the ? icon bottom left of any Repl and select Report a Bug. There is an option to record a video when you do this which would be really useful to show the support team how simply adding reqwest to a new Rust project can cause the issue.

Thank you @IanAtReplit, I have done that. Hope it gets looked at soon! It’s blocking me in my learning project.

1 Like

Hi,

This is the reply I got for my bug report:

From what the logs are showing, everything looks to be all clean on our end. If you need help on your code, you can reach out to the community at https://replit.com/discord or https://ask.replit.com

This is obviously not the answer I was expecting. I like the concept of replit but I think it’s just not mature enough when it comes to Rust. I don’t think I will buy more cycles when I run out.

Hi @Pierric thanks for the update. I’ve gone back to the Replit team to see if someone can offer further advice here. Hold tight!

Hi @Pierric, it looks like you will need to install OpenSSL and pkg-config. You can do this by adding them to the replit.nix file (you may have to enable showing hidden files in the filetree).

Then add pkgs.openssl and pkgs.pkg-config to the deps list and rerun the repl.

Here is a fork of your repl with this set up https://replit.com/@ConnorBrewster/reqwest-test

Hope this helps!

1 Like

Thank you @cbrewster , it did solve the issue.
Is there some documentation somewhere about what this replit.nix file is, how it works, and how I might solve future similar issues if they arrive by adding the right lines?
Regards,
Pierric.

Great! You can read our docs on Nix here: https://docs.replit.com/programming-ide/nix-on-replit

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.