Help with cross compiling openssl from Windows to aarch64

Hi all,
I'm still new to Rust, hence my question. I'm lost in the dark and don't see any light in any direction (despite spinning in circles) and am hoping I can get some assistance... PLEEEEEASE :slight_smile: .

(Apologies for the long question)

I have a project that is developed on Windows and compiled for Windows and also cross compiled for aarch64. The project has a lot of functionality already implemented and now I wish to do a HTTP call. I've looked into a few HTTP crates and have chosen to use reqwest. So I added the reqwest crate to my Cargo.toml file and did a small experimental code and it builds fine and runs fine on Windows. I then tried to cross compile the project and the build failed.

Upon further reading of the reqwest crate documentation it says that the Requirements for Windows and MacOS are "nothing" and for Linux you need openssl. So I added the openssl crate to the Cargo.toml and when I tried to build I got the following output:

error: failed to run custom build command for `openssl-sys v0.9.67`
Caused by:
  process didn't exit successfully: `C:\projects\src\application\target\debug\build\openssl-sys-10437381c6d14ee4\build-script-main` (exit code: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR
  AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR
  AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_DIR
  AARCH64_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_ALLOW_CROSS_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64_unknown_linux_gnu
  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_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_unknown_linux_gnu
  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 has not been configured to support cross-compilation.\n\nInstall a sysroot for the target platform and configure it via\nPKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a\ncross-compiling wrapper for pkg-config and set it via\nPKG_CONFIG environment variable."
  --- 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 = i686-pc-windows-gnu
  $TARGET = aarch64-unknown-linux-gnu
  openssl-sys = 0.9.67

So I googled around to try and find some guidance or solutions to these build errors. I came across this post which points to this thread. Reading through all of this I tried to add the "vendored" feature as described in this post. When trying to build this I got the error output of:

error: failed to run custom build command for `openssl-sys v0.9.67`
Caused by:
  process didn't exit successfully: `C:\projects\src\application\target\debug\build\openssl-sys-3fc5e4ea71298efe\build-script-main` (exit code: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_NO_VENDOR
  AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_NO_VENDOR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
  OPENSSL_NO_VENDOR unset
  CC_aarch64-unknown-linux-gnu = None
  CC_aarch64_unknown_linux_gnu = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_aarch64-unknown-linux-gnu = None
  CFLAGS_aarch64_unknown_linux_gnu = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = None
  running "perl" "./Configure" "--prefix=/C/projects/src/application/target/aarch64-unknown-linux-gnu/debug/build/openssl-sys-c48002440e24cf61/out/openssl-build/install" "no-dso" "no-shared" "no-ssl3" "no-unit-test" "no-comp" "no-zlib" "no-zlib-dynamic" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "linux-aarch64" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer"
  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }', C:\Users\chris.nocker\.cargo\registry\src\github.com-1285ae84e5963aae\openssl-src-111.16.0+1.1.1l\src\lib.rs:477:39

Then further reading of the openssl crate documentation openssl it says that I need perl installed. So I've fumbled my way through and figured out how to install perl and then try to build again. This time the error output is like this:

error: failed to run custom build command for `openssl-sys v0.9.68`
Caused by:
  process didn't exit successfully: `C:\projects\src\application\target\debug\build\openssl-sys-0d56d4dde1f85b49\build-script-main` (exit code: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_NO_VENDOR
  AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_NO_VENDOR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
  OPENSSL_NO_VENDOR unset
  CC_aarch64-unknown-linux-gnu = None
  CC_aarch64_unknown_linux_gnu = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_aarch64-unknown-linux-gnu = None
  CFLAGS_aarch64_unknown_linux_gnu = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = None
  running "perl" "./Configure" "--prefix=/C/projects/src/application/target/aarch64-unknown-linux-gnu/debug/build/openssl-sys-d24f09c66f9a5610/out/openssl-build/install" "no-dso" "no-shared" "no-ssl3" "no-unit-test" "no-comp" "no-zlib" "no-zlib-dynamic" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "linux-aarch64" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer"
  Configuring OpenSSL version 1.1.1l (0x101010cfL) for linux-aarch64
  Using os-specific seed configuration
  --- stderr
  ******************************************************************************
  This perl implementation doesn't produce Unix like paths (with forward slash
  directory separators).  Please use an implementation that matches your
  This Perl version: 5.32.1 for MSWin32-x64-multi-thread
  ******************************************************************************

Now I feel like I'm being guided to install MSYS2.

I've been researching how to get this cross compile to work for a fair while now, can anyone tell me:
Am I even on the right track any more?
Is this right, I need perl to be able to compile the openssl crate?
Could anyone point me to some documentation or guide or other that might assist me?

TIA :wink:

1 Like

Cross-compiling when you depend on native libraries can be a pain, perhaps, instead of messing around with openssl, you can try switching reqwest to use the rustls-tls feature:

reqwest = { version = "0.11.6", default-features = false, features = ["rustls-tls"] }
1 Like

Thank you! The project is now able to cross compile :+1:

With such a simple answer it is disheartening that I spent so long researching :slightly_frowning_face:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.