首页 > 解决方案 > Rust Web 程序集无法构建并出现 openssl 错误

问题描述

我对 rust 很陌生,我使用它构建了一个 Web 程序集项目,在项目中使用 openssl 包。现在问题来了,当我想构建应用程序时,它失败并显示以下输出:

[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"

我已经尝试了互联网上的所有解决方案,安装了libssldev,,pkg-config我也在openssl我的机器上重新安装了几次,仍然没有结果。我已经调试了几个小时没有任何成功。

以下是我的Cargo.toml内容依赖部分

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

并且正在使用ubuntu 20.04. 任何帮助将不胜感激,因为我已经没有时间了,在此先感谢。

openssl version输出OpenSSL 1.1.1g 21 Apr 2020

当您需要更多信息时,请告诉我。

标签: rustopensslwebassembly

解决方案


根据 rustwasm/wasm-bindgen,opensslcrate 不支持 WebAssembly

这实际上是 openssl-sys 构建脚本报告的错误,这是因为 openssl crate 尚不支持 WebAssembly(我不确定 OpenSSL 本身是否支持......)。


推荐阅读