【发布时间】:2019-09-11 12:19:43
【问题描述】:
我正在尝试通过构建一个演示应用程序来操作一些存档文件来学习 Rust 和 WebAssembly。
添加“zip”包后,我能够成功运行cargo build,但不能成功运行wasm-pack build(也不是cargo build --target wasm32-unknown-unknown)。
我在尝试构建我的文件时收到 cargo:warning=#error Unsupported architecture,而 clang 似乎对它不满意。
起初我得到一些stdio.h not found,所以我跑了
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
安装它们。
我现在遇到以下错误:
Compiling bzip2-sys v0.1.7
error: failed to run custom build command for `bzip2-sys v0.1.7`
process didn't exit successfully: `/Users/projects/rust/hello-wasm/target/release/build/bzip2-sys-b7b1e1aeb1e6f42f/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("wasm32-unknown-unknown")
OPT_LEVEL = Some("s")
HOST = Some("x86_64-apple-darwin")
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: "clang" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "bzip2-1.0.6" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "/Users/projects/rust/hello-wasm/target/wasm32-unknown-unknown/release/build/bzip2-sys-3be942e6fa7d3879/out/lib/bzip2-1.0.6/blocksort.o" "-c" "bzip2-1.0.6/blocksort.c"
cargo:warning=In file included from bzip2-1.0.6/blocksort.c:22:
cargo:warning=In file included from bzip2-1.0.6/bzlib_private.h:25:
cargo:warning=In file included from /usr/include/stdlib.h:62:
cargo:warning=/usr/include/sys/cdefs.h:784:2: error: Unsupported architecture
cargo:warning=#error Unsupported architecture
cargo:warning= ^
cargo:warning=In file included from bzip2-1.0.6/blocksort.c:22:
cargo:warning=In file included from bzip2-1.0.6/bzlib_private.h:25:
cargo:warning=In file included from /usr/include/stdlib.h:64:
cargo:warning=In file included from /usr/include/_types.h:27:
cargo:warning=In file included from /usr/include/sys/_types.h:33:
cargo:warning=/usr/include/machine/_types.h:34:2: error: architecture not supported
cargo:warning=#error architecture not supported
cargo:warning= ^
cargo:warning=In file included from bzip2-1.0.6/blocksort.c:22:
cargo:warning=In file included from bzip2-1.0.6/bzlib_private.h:25:
cargo:warning=In file included from /usr/include/stdlib.h:64:
cargo:warning=In file included from /usr/include/_types.h:27:
cargo:warning=/usr/include/sys/_types.h:55:9: error: unknown type name '__int64_t'; did you mean '__int128_t'?
cargo:warning=typedef __int64_t __darwin_blkcnt_t; /* total blocks */
cargo:warning= ^
cargo:warning=note: '__int128_t' declared here
[...]
Internal error occurred: Command "clang" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "bzip2-1.0.6" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "/Users/projects/rust/hello-wasm/target/wasm32-unknown-unknown/release/build/bzip2-sys-3be942e6fa7d3879/out/lib/bzip2-1.0.6/blocksort.o" "-c" "bzip2-1.0.6/blocksort.c" with args "clang" did not execute successfully (status code exit code: 1).
然后我跑了:
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup default nightly
安装目标 wasm32-unknown-unknown 但我仍然收到错误。
为 wasm 编译“zip”板条箱时我缺少什么?
环境
macOS 10.14.4
gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
rustc --version
rustc 1.36.0-nightly (31a75a172 2019-04-21)
rustup show
Default host: x86_64-apple-darwin
installed toolchains
--------------------
stable-x86_64-apple-darwin
nightly-2019-04-16-x86_64-apple-darwin
nightly-x86_64-apple-darwin (default)
installed targets for active toolchain
--------------------------------------
wasm32-unknown-unknown
x86_64-apple-darwin
active toolchain
----------------
nightly-x86_64-apple-darwin (default)
rustc 1.36.0-nightly (31a75a172 2019-04-21)
【问题讨论】:
-
#error Unsupported architecture是 C 编译器错误(您可以在周围的行中看到 .c 文件)。您选择了一个实际编译 C 库以完成所有繁重的压缩工作的 crate,但该 C 库无法编译为 WASM(至少在您的配置中)。最简单的事情是找到一个纯 Rust 实现。 -
非常感谢。我最终从这个 crate 中禁用了 bzip 支持,因为作者在我的 Cargo.toml 中使用以下配置通过功能标志离开了这样做的可能性:
zip = { version = "0.5.2", default-features = false, features = ["deflate"] }
标签: rust webassembly