eclipse / paho.mqtt.rust

paho.mqtt.rust
Other
516 stars 102 forks source link

Problems using openssl-sys on Windows #138

Closed fpagliughi closed 2 years ago

fpagliughi commented 2 years ago

So far, using openssl-sys has been great on Linux, especially when cross-compiling; now we don't have to try to find a cross-compiled version of OpenSSL for the target. The build handles it.

But it seems that openssl-sys made things slightly worse on Window.

I'm wondering if we should avoid openssl-sys on Windows and let build.rs look for it in the standard locations? Or leave it as-is and tell Windows users they must always set OPENSSL_DIR?

Or am I doing something wrong on Windows?!?

@svanharmelen and thoughts?


When attempting to build for Window x86_64 using MSVC, the vendored openssl-sys produces the following error:

   Compiling openssl-sys v0.9.67
       Fresh libc v0.2.104
     Running `K:\mqtt\paho-rust\paho-mqtt-sys\target\debug\build\openssl-sys-807a6c23aaec1dc2\build-script-main`
[openssl-sys 0.9.67] cargo:rustc-cfg=const_fn
[openssl-sys 0.9.67] cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_NO_VENDOR
[openssl-sys 0.9.67] X86_64_PC_WINDOWS_MSVC_OPENSSL_NO_VENDOR unset
[openssl-sys 0.9.67] cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
[openssl-sys 0.9.67] OPENSSL_NO_VENDOR unset
[openssl-sys 0.9.67] running "perl" "./Configure" "--prefix=K:\\mqtt\\paho-rust\\paho-mqtt-sys\\target\\debug\\build\\openssl-sys-d3362f1ce6cce1
9c\\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" "no-engine" "no-asm" "VC-WIN64A"
[openssl-sys 0.9.67] 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\Frank\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-src-111.16.0+1.1.1l\src\lib.rs:477:3
9
[openssl-sys 0.9.67] stack backtrace:
[openssl-sys 0.9.67]    0: std::panicking::begin_panic_handler
[openssl-sys 0.9.67]              at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b\/library\std\src\panicking.rs:515
[openssl-sys 0.9.67]    1: core::panicking::panic_fmt
[openssl-sys 0.9.67]              at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b\/library\core\src\panicking.rs:92
[openssl-sys 0.9.67]    2: core::result::unwrap_failed
[openssl-sys 0.9.67]              at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b\/library\core\src\result.rs:1599
[openssl-sys 0.9.67]    3: enum$<core::result::Result<std::process::ExitStatus,std::io::error::Error> >::unwrap<std::process::ExitStatus,std::io
::error::Error>
[openssl-sys 0.9.67]              at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b\library\core\src\result.rs:1281
[openssl-sys 0.9.67]    4: openssl_src::Build::run_command
[openssl-sys 0.9.67]              at C:\Users\Frank\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-src-111.16.0+1.1.1l\src\lib.rs:477
[openssl-sys 0.9.67]    5: openssl_src::Build::build
[openssl-sys 0.9.67]              at C:\Users\Frank\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-src-111.16.0+1.1.1l\src\lib.rs:418
[openssl-sys 0.9.67]    6: build_script_main::find_vendored::get_openssl
[openssl-sys 0.9.67]              at .\build\find_vendored.rs:5
[openssl-sys 0.9.67]    7: build_script_main::find_openssl
[openssl-sys 0.9.67]              at .\build\main.rs:56
[openssl-sys 0.9.67]    8: build_script_main::main
[openssl-sys 0.9.67]              at .\build\main.rs:63
[openssl-sys 0.9.67]    9: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
[openssl-sys 0.9.67]              at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b\library\core\src\ops\function.rs:227
[openssl-sys 0.9.67] note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: failed to run custom build command for `openssl-sys v0.9.67`

Caused by:
  process didn't exit successfully: `K:\mqtt\paho-rust\paho-mqtt-sys\target\debug\build\openssl-sys-807a6c23aaec1dc2\build-script-main` (exit co
de: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_NO_VENDOR
  X86_64_PC_WINDOWS_MSVC_OPENSSL_NO_VENDOR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
  OPENSSL_NO_VENDOR unset
  running "perl" "./Configure" "--prefix=K:\\mqtt\\paho-rust\\paho-mqtt-sys\\target\\debug\\build\\openssl-sys-d3362f1ce6cce19c\\out\\openssl-bu
ild\\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-ca
mellia" "no-idea" "no-seed" "no-engine" "no-asm" "VC-WIN64A"

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "The system cannot find the fil
e specified." }', C:\Users\Frank\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-src-111.16.0+1.1.1l\src\lib.rs:477:39
  stack backtrace:
     0: std::panicking::begin_panic_handler
               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b\/library\std\src\panicking.rs:515
     1: core::panicking::panic_fmt
               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b\/library\core\src\panicking.rs:92
     2: core::result::unwrap_failed
               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b\/library\core\src\result.rs:1599
     3: enum$<core::result::Result<std::process::ExitStatus,std::io::error::Error> >::unwrap<std::process::ExitStatus,std::io::error::Error>
               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b\library\core\src\result.rs:1281
     4: openssl_src::Build::run_command
               at C:\Users\Frank\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-src-111.16.0+1.1.1l\src\lib.rs:477
     5: openssl_src::Build::build
               at C:\Users\Frank\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-src-111.16.0+1.1.1l\src\lib.rs:418
     6: build_script_main::find_vendored::get_openssl
               at .\build\find_vendored.rs:5
     7: build_script_main::find_openssl
               at .\build\main.rs:56
     8: build_script_main::main
               at .\build\main.rs:63
     9: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
               at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b\library\core\src\ops\function.rs:227
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

When attempting a non-vendored build with openssl-sys, if OPENSSL_DIR is not set

warning: `cmake` (lib) generated 1 warning
   Compiling openssl-sys v0.9.67
       Fresh libc v0.2.104
     Running `K:\mqtt\paho-rust\paho-mqtt-sys\target\debug\build\openssl-sys-9a902e1719db51b3\build-script-main`
[openssl-sys 0.9.67] cargo:rustc-cfg=const_fn
[openssl-sys 0.9.67] cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR
[openssl-sys 0.9.67] X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR unset
[openssl-sys 0.9.67] cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
[openssl-sys 0.9.67] OPENSSL_LIB_DIR unset
[openssl-sys 0.9.67] cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR
[openssl-sys 0.9.67] X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR unset
[openssl-sys 0.9.67] cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
[openssl-sys 0.9.67] OPENSSL_INCLUDE_DIR unset
[openssl-sys 0.9.67] cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR
[openssl-sys 0.9.67] X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR unset
[openssl-sys 0.9.67] cargo:rerun-if-env-changed=OPENSSL_DIR
[openssl-sys 0.9.67] OPENSSL_DIR unset
[openssl-sys 0.9.67] note: vcpkg did not find openssl: Could not find Vcpkg tree: No vcpkg installation found. Set the VCPKG_ROOT environment va
riable or run 'vcpkg integrate install'
[openssl-sys 0.9.67] thread 'main' panicked at '
[openssl-sys 0.9.67]
[openssl-sys 0.9.67] Could not find directory of OpenSSL installation, and this `-sys` crate cannot
[openssl-sys 0.9.67] proceed without this knowledge. If OpenSSL is installed and this crate had
[openssl-sys 0.9.67] trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
[openssl-sys 0.9.67] compilation process.
[openssl-sys 0.9.67]
[openssl-sys 0.9.67] Make sure you also have the development packages of openssl installed.
[openssl-sys 0.9.67] For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.
[openssl-sys 0.9.67]
[openssl-sys 0.9.67] If you're in a situation where you think the directory *should* be found
[openssl-sys 0.9.67] automatically, please open a bug at https://github.com/sfackler/rust-openssl
[openssl-sys 0.9.67] and include information about your system as well as this message.
[openssl-sys 0.9.67]
[openssl-sys 0.9.67] $HOST = x86_64-pc-windows-msvc
[openssl-sys 0.9.67] $TARGET = x86_64-pc-windows-msvc
[openssl-sys 0.9.67] openssl-sys = 0.9.67
[openssl-sys 0.9.67]
[openssl-sys 0.9.67]
[openssl-sys 0.9.67] It looks like you're compiling for MSVC but we couldn't detect an OpenSSL
[openssl-sys 0.9.67] installation. If there isn't one installed then you can try the rust-openssl
[openssl-sys 0.9.67] README for more information about how to download precompiled binaries of
[openssl-sys 0.9.67] OpenSSL:
[openssl-sys 0.9.67]
[openssl-sys 0.9.67] https://github.com/sfackler/rust-openssl#windows
[openssl-sys 0.9.67]
[openssl-sys 0.9.67] ', C:\Users\Frank\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-sys-0.9.67\build\find_normal.rs:174:5
[openssl-sys 0.9.67] note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: failed to run custom build command for `openssl-sys v0.9.67`

Caused by:
  process didn't exit successfully: `K:\mqtt\paho-rust\paho-mqtt-sys\target\debug\build\openssl-sys-9a902e1719db51b3\build-script-main` (exit co
de: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR
  X86_64_PC_WINDOWS_MSVC_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR
  X86_64_PC_WINDOWS_MSVC_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR
  X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset
  note: vcpkg did not find openssl: Could not find Vcpkg tree: No vcpkg installation found. Set the VCPKG_ROOT environment variable or run 'vcpk
g integrate install'

  --- 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-pc-windows-msvc
  $TARGET = x86_64-pc-windows-msvc
  openssl-sys = 0.9.67

  It looks like you're compiling for MSVC but we couldn't detect an OpenSSL
  installation. If there isn't one installed then you can try the rust-openssl
  README for more information about how to download precompiled binaries of
  OpenSSL:

  https://github.com/sfackler/rust-openssl#windows

  ', C:\Users\Frank\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-sys-0.9.67\build\find_normal.rs:174:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
svanharmelen commented 2 years ago

I don't have a Windows machine myself, but can use one at the office. So will have a look later this week...

svanharmelen commented 2 years ago

Last week was a bad week... I'll hopefully have a better week this week, so keep you posted.

rkudryashov commented 2 years ago

In my case, it was also needed to install perl to compile an application

fpagliughi commented 2 years ago

Yes, thanks @rkudryashov. Finally thought to RTFM! Sure enough it mentions that:

The [vendored] build process requires a C compiler, perl, and make.

in the Rust OpenSSL docs

I should probably summarize those docs in the README here. Then I can probably get rid of most of the SSL/TLS code in build.rs and just let openssl-sys do its thing. The only exception I can think of right now, though, would be to add back in the check for the library in the usual manually-installed locations on Windows, like C:\OpenSSL-Win64 if it's not found automatically.

fpagliughi commented 2 years ago

I think there are a whole list of usage constraints, but overall, with a few guidelines and some additions like #113, things can generally be made to work. This probably needs a few additions to the README, but overall, openssl-sys has been a big improvement.