15

When i run cargo install wasm-pack on windows 10 64-bit i get this error:

error: failed to run custom build command for `openssl-sys v0.9.65`

Caused by:
  process didn't exit successfully: `C:\Users\vilgo\AppData\Local\Temp\cargo-install2J8ZNz\release\build\openssl-sys-932395a164949059\build-script-main` (exit code: 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
  openssl-src: Enable the assembly language routines in building OpenSSL.
  running "perl" "./Configure" "--prefix=C:\\Users\\vilgo\\AppData\\Local\\Temp\\cargo-install2J8ZNz\\release\\build\\openssl-sys-a51d272dcebf1fc5\\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" "VC-WIN64A"

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "Det går inte att hitta filen." }', C:\Users\vilgo\.cargo\registry\src\github.com-1ecc6299db9ec823\openssl-src-111.15.0+1.1.1k\src\lib.rs:469:39
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: failed to compile `wasm-pack v0.10.0`, intermediate artifacts can be found at `C:\Users\vilgo\AppData\Local\Temp\cargo-install2J8ZNz`

Caused by:
  build failed

How can i fix it? I ran it in regular cmd.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
VilgotanL
  • 328
  • 2
  • 9
  • 1
    I fixed it by just downloading wasm-pack directly from the [github pages page](https://rustwasm.github.io/wasm-pack/installer/) – VilgotanL Sep 11 '21 at 18:34
  • for me, with rust just installed today, running the binary just results in an error saying rustup couldnt be found on path, even though rustup is definitely on my path. Just like [this issue](https://github.com/rustwasm/wasm-pack/issues/1015), which has no solutions yet... – apc518 Jan 02 '22 at 18:33

2 Answers2

20

The problem

I think your problem happened because all three of these things happened:

  1. You probably started the wasm-pack build from an msys shell.
  2. wasm-pack depends on Rust's OpenSSL bindings, which by default try to build OpenSSL by source.
  3. OpenSSL's build scripts are written in Perl. The msys Perl doesn't create Windows paths with \ as a directory separator, which causes the OpenSSL build to fail.

The solutions

Any one of these three solutions should solve your problem:

Fix Step #3: Compile OpenSSL with the native Windows Perl

Make sure your default Perl installation is a "native" Windows Perl like Strawberry Perl. Make sure your build environment does not default to the msys perl. Then, retry compiling both wasm-pack and OpenSSL from source.

Fix Step #2: Use a precompiled OpenSSL library

You can build wasm-pack from source, but instruct the Rust OpenSSL bindings to look for a precompiled OpenSSL.

If you don't have it already, download and install vcpkg, which we'll use to install OpenSSL:

git clone https://github.com/Microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat

Then use vcpkg to install OpenSSL:

vcpkg install openssl:x64-windows-static-md

(If this does not work, try vcpkg install openssl:x64-windows.)

And then try compiling wasm-pack. Set VCPKG_ROOT to tell the Rust OpenSSL build script where to look, and also set OPENSSL_NO_VENDOR=1 to discourage the build script from compiling OpenSSL from source.

set VCPKG_ROOT=c:\path\to\vcpkg\installation
set OPENSSL_NO_VENDOR=1
cargo install wasm-pack

Fix Step #1: Use a pre-compiled wasm-pack binary on Windows.

If you do not want to compile either wasm-pack or OpenSSL, you can use the Windows installer (wasm-pack-init.exe) on the rustwasm downloads page. Alternatively, you could also run your wasm-pack builds in Windows Subsystem for Linux (WSL).

James Mishra
  • 4,249
  • 4
  • 30
  • 35
  • 3
    Any of these solutions are not really suitable for beginners following [this](https://developer.mozilla.org/en-US/docs/WebAssembly/Rust_to_wasm) to learn wasm. Well, the direct download is fine... but still... Especially because a previous version of `wasm-pack` (`0.9.1`) installed without issue. – Elias Sep 02 '21 at 14:44
  • @Elias I agree. The problem is with openssl-sys, not wasm-pack, though. Maybe that could be improved. – Jay Sep 28 '21 at 19:06
  • I believe that openssl-sys is looking for the `openssl:x64-windows-static-md` target, not the `openssl:x64-windows` target. – Jay Sep 29 '21 at 13:41
  • 1
    @Jay thank you! I updated my answer – James Mishra Sep 29 '21 at 23:16
  • I installed Strawberry Perl using Chocolatey and then ran the cargo command again and that fixed my issue! – Icemanind Feb 24 '23 at 22:59
2

Make sure you have the development packages of Open SSL installed. For example, libssl-dev on Ubuntu or openssl-devel on Fedora. If OpenSSL is already installed and the crate still had trouble finding it, you can set the OPENSSL_DIR environment variable to specify the path for your Open SSL installation. If you are using windows you can use the Win32/Win64 OpenSSL Installation Project to provide a simple installation of OpenSSL on windows.

Anhad Singh
  • 49
  • 1
  • 3
  • in windows its the combination of setting the OPENSSL_DIR flag and downloading the static lib's openssl:x64-windows-static-md – user63898 May 27 '23 at 07:25