rustopensslwebassemblyrust-cargowasm-pack

can't install cargo wasm-pack


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.


Solution

  • 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).