title: How to work with OpenSSL for Rust within a Windows development environment
body: <p>I can't build my Rust project when I add an SSL dependency in my cargo file.
  This isn't new to Windows, but I'd like to resolve the issue such that I can use Powershell and native Windows development to work on my Rust project.</p>
  
  <p>The dependency in question is the following:</p>
  
  <pre><code>[dependencies.ws]
  version = "0.8.0"
  features = ["ssl"]
  </code></pre>
  
  <p>When I run <code>cargo build</code>, I get a lot of errors regarding SSL as I'm on Windows so let us begin debugging this step by step.</p>
  
  <p>First errors:</p>
  
  <pre><code>PS C:\Users\sam\vcs\project&gt; cargo build
     Compiling openssl-sys v0.9.43
  error: failed to run custom build command for `openssl-sys v0.9.43`
  process didn't exit successfully: `C:\Users\sam\vcs\project\target\debug\build\openssl-sys-d964f46e4c48d206\build-script-main` (exit code: 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 as libcrypto and libssl: Aborted because VCPKGRS_DYNAMIC is not set
  note: vcpkg did not find openssl as ssleay32 and libeay32: Aborted because VCPKGRS_DYNAMIC is not set
  </code></pre>
  
  <p>Alright, lets set <code>OPENSSL_LIB_DIR</code>, <code>OPENSSL_INCLUDE_DIR</code>, and <code>OPENSSL_DIR</code></p>
  
  <pre><code>$env:OPENSSL_LIB_DIR="C:\OpenSSL-Win64\lib"
  $env:OPENSSL_INCLUDE_DIR="C:\OpenSSL-Win64\include"
  $env:OPENSSL_DIR="C:\OpenSSL-Win64"
  </code></pre>
  
  <p>However, now running <code>cargo build</code> or <code>cargo run</code> actually compiles, but I don't think SSL works correctly since the code path that connects to the websocket fails with error none.</p>
  
  <p>I installed the latest (1.1.0j) full (non-slim) version of OpenSSL from the following website: <a href="https://slproweb.com/products/Win32OpenSSL.html" rel="noreferrer">https://slproweb.com/products/Win32OpenSSL.html</a></p>
  
  <p>The only environment variable it had set was: </p>
  
  <pre><code>OPENSSL_CONF: C:\OpenSSL-Win64\bin\openssl.cfg
  </code></pre>
  
  <p>But I also added <code>C:\OpenSSL-Win64\bin</code> to my <code>PATH</code>.</p>
  
  <p>When <code>cargo build</code> actually compiled, the websocket fails with error <code>None</code></p>
  
  <p>The <code>on_error</code> block is executed on my Windows box, but my Linux machine never executes this code block.</p>
  
  <p>Just so we're on the same page, this is the output of the print statement:</p>
  
  <pre><code>fn on_error(&amp;mut self, err: ws::Error) {
      println!("On Error, {}", err)
  }
  </code></pre>
  
  <p>None isn't a very descriptive answer. So I assumed that I just needed some certs since OpenSSL doesn't come with certs.
  I downloaded a cacert.pem from somewhere online and placed it into the certs folder of the OpenSSL installation but that didn't make much difference either. Still the same <code>None</code> error.</p>
  
  <p>On my Linux box, I would expect the websocket connection to succeed and for the code to proceed to <code>on_open</code>:</p>
  
  <pre><code>fn on_open(&amp;mut self, _: ws::Handshake) -&gt; ws::Result&lt;()&gt; {
  ...
  }
  </code></pre>
  
  <hr>
  
  <p>Has anyone worked through this OpenSSL issue on their Windows development environment?</p>
  
  <hr>
  
  <h2><em>UPDATE 0</em></h2>
  
  <p>As per Cloud's advice, I tried to use VCPKG. Unfortunately it didn't work.</p>
  
  <pre><code>PS C:\Users\sam\vcs\vcpkg&gt; .\vcpkg.exe list
  openssl-windows:x64-windows-static                 1.0.2q-2         OpenSSL is an open source project that provides ...
  openssl-windows:x86-windows                        1.0.2q-2         OpenSSL is an open source project that provides ...
  openssl:x64-windows-static                         0                OpenSSL is an open source project that provides ...
  openssl:x86-windows                                0                OpenSSL is an open source project that provides ...
  </code></pre>
  
  <p>Then I set the variables in my powershell window:</p>
  
  <pre><code>PS C:\Users\sam\vcs\project&gt; $env:OPENSSL_DIR = 'C:\Users\sam\vcs\vcpkg\installed\x64-windows-static'
  PS C:\Users\sam\vcs\project&gt; $env:OPENSSL_STATIC = 'Yes'
  PS C:\Users\sam\vcs\project&gt; $env:VCPKGRS_DYNAMIC='1'
  </code></pre>
  
  <p>Then I ran <code>cargo clean</code> and then <code>cargo build</code> and I still got the same error where my websocket throws the error <code>None</code>.</p>
  
  <p>Still no luck here.</p>