lulliezy
lulliezy

Reputation: 2043

How to fix "Error building OpenSSL" when targetting WASM?

I'm building a web assembly project using Rust that uses the openssl crate. Now the problem comes when I want to build the app, it fails with the following output:

[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling openssl-sys v0.9.58
error: failed to run custom build command for `openssl-sys v0.9.58`

Caused by:
  process didn't exit successfully: `/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/release/build/openssl-sys-815e530f9615c049/build-script-main` (exit code: 101)
--- stdout
cargo:rustc-cfg=const_fn
cargo:rerun-if-env-changed=WASM32_UNKNOWN_UNKNOWN_OPENSSL_NO_VENDOR
WASM32_UNKNOWN_UNKNOWN_OPENSSL_NO_VENDOR unset
cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
OPENSSL_NO_VENDOR unset
CC_wasm32-unknown-unknown = None
CC_wasm32_unknown_unknown = None
TARGET_CC = None
CC = None
CFLAGS_wasm32-unknown-unknown = None
CFLAGS_wasm32_unknown_unknown = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
running "perl" "./Configure" "--prefix=/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/wasm32-unknown-unknown/release/build/openssl-sys-881fa1458604c2ea/out/openssl-build/install" "no-dso" "no-ssl3" "no-unit-test" "no-comp" "no-zlib" "no-zlib-dynamic" "no-shared" "gcc" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown"
Configuring OpenSSL version 1.1.1g (0x1010107fL) for gcc
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile

The library could not be configured for supporting multi-threaded
applications as the compiler options required on this system are not known.
See file INSTALL for details if you need multi-threading.

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************
running "make" "depend"
running "make" "build_libs"
/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
    "-oMakefile" include/crypto/bn_conf.h.in > include/crypto/bn_conf.h
/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
    "-oMakefile" include/crypto/dso_conf.h.in > include/crypto/dso_conf.h
/usr/bin/perl "-I." -Mconfigdata "util/dofile.pl" \
    "-oMakefile" include/openssl/opensslconf.h.in > include/openssl/opensslconf.h
make depend && make _build_libs
make[1]: Entering directory '/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/wasm32-unknown-unknown/release/build/openssl-sys-881fa1458604c2ea/out/openssl-build/build/src'
make[1]: Leaving directory '/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/wasm32-unknown-unknown/release/build/openssl-sys-881fa1458604c2ea/out/openssl-build/build/src'
make[1]: Entering directory '/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/wasm32-unknown-unknown/release/build/openssl-sys-881fa1458604c2ea/out/openssl-build/build/src'
clang  -I. -Iinclude  -O3 -O2 -ffunction-sections -fdata-sections -fPIC --target=wasm32-unknown-unknown -DOPENSSLDIR="\"/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/wasm32-unknown-unknown/release/build/openssl-sys-881fa1458604c2ea/out/openssl-build/install/ssl\"" -DENGINESDIR="\"/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/wasm32-unknown-unknown/release/build/openssl-sys-881fa1458604c2ea/out/openssl-build/install/lib/engines-1.1\"" -DNDEBUG   -c -o apps/app_rand.o apps/app_rand.c
clang  -I. -Iinclude  -O3 -O2 -ffunction-sections -fdata-sections -fPIC --target=wasm32-unknown-unknown -DOPENSSLDIR="\"/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/wasm32-unknown-unknown/release/build/openssl-sys-881fa1458604c2ea/out/openssl-build/install/ssl\"" -DENGINESDIR="\"/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/wasm32-unknown-unknown/release/build/openssl-sys-881fa1458604c2ea/out/openssl-build/install/lib/engines-1.1\"" -DNDEBUG   -c -o apps/apps.o apps/apps.c
clang  -I. -Iinclude  -O3 -O2 -ffunction-sections -fdata-sections -fPIC --target=wasm32-unknown-unknown -DOPENSSLDIR="\"/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/wasm32-unknown-unknown/release/build/openssl-sys-881fa1458604c2ea/out/openssl-build/install/ssl\"" -DENGINESDIR="\"/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/wasm32-unknown-unknown/release/build/openssl-sys-881fa1458604c2ea/out/openssl-build/install/lib/engines-1.1\"" -DNDEBUG   -c -o apps/bf_prefix.o apps/bf_prefix.c
make[1]: Leaving directory '/home/hamisi/Projects/payment-gateway/checkout/web/payload-formatter-wasm/target/wasm32-unknown-unknown/release/build/openssl-sys-881fa1458604c2ea/out/openssl-build/build/src'

--- stderr
/bin/sh: 1: clang: not found
make[1]: *** [Makefile:672: apps/app_rand.o] Error 127
make[1]: *** Waiting for unfinished jobs....
/bin/sh: 1: clang: not found
make[1]: *** [Makefile:674: apps/apps.o] Error 127
/bin/sh: 1: clang: not found
make[1]: *** [Makefile:676: apps/bf_prefix.o] Error 127
make: *** [Makefile:175: build_libs] Error 2
thread 'main' panicked at '


Error building OpenSSL:
    Command: "make" "build_libs"
    Exit status: exit code: 2


    ', /home/hamisi/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-src-111.10.0+1.1.1g/src/lib.rs:386:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit code: 101
  full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

I have tried every solution in the internet, installed libssldev, pkg-config, I also reinstalled openssl in my machine several times, still no fruits. I have debugged this for hours without any success.

The following is my Cargo.toml content dependencies section:

[dependencies]
wasm-bindgen = "0.2.63"
openssl-sys = "0.9"
openssl = { version = "0.10", features = ["vendored"] }
base64 = "0.12.1"

I am using Ubuntu 20.04 and openssl version outputs:

OpenSSL 1.1.1g  21 Apr 2020

Upvotes: 1

Views: 2563

Answers (1)

Marcos Casagrande
Marcos Casagrande

Reputation: 40404

According to rustwasm/wasm-bindgen, openssl crate does not support WebAssembly

This is actually an error reported by the openssl-sys build script and that's because the openssl crate doesn't have support for WebAssembly yet (I'm not sure that OpenSSL itself even does...).

Upvotes: 4

Related Questions