使用 Rust 写的 .wasm 文件,在 iOS 端微信小程序可能会报错 CompileError: invalid wasm file
,这篇笔记分享报错的理由,以及解决方法。
从 1.82.0 开始,Rust 的 WebAssembly target 增加了 multivalue
和 reference-types
两个新特性,iOS 端对这两个特性支持不完善。
解决方法有两种。
wasm-pack build --target web
;RUSTFLAGS="-C target-feature=-multivalue,-reference-types" wasm-pack build --target web
方法二可能不是最佳实践?对于所谓的 on-by-default 特性,官方建议重新编译 rust。
If you're compiling WebAssembly code for an engine that does not support a feature in LLVM's default feature set then the feature must be disabled at compile time. 出处
相关阅读:
reference-types
了,Safari 13.1 就支持 multivalue
了;multivalue
和 reference-types
这两个功能;