如何解决wasm rust base 64 支持
我创建了一个按预期工作的程序:
extern crate base64;
// decode base64
let bytes = base64::decode(res[1]).unwrap();
[dependencies]
base64 = "0.13.0"
serde_json = "1.0.64"
当我将此代码添加到带有 base64 lib 的 Envoy 过滤器的 Webassembly 时,出现错误:
INFO: From Compiling Rust cdylib filter (1 files):
error[E0463]: can't find crate for `base64`
--> filter.rs:1:1
|
1 | extern crate base64;
| ^^^^^^^^^^^^^^^^^^^^ can't find crate
This playground 与默认的“运行”按钮配合使用,但如果您将其作为“Wasm”运行,则 this playground 不起作用。您将收到上述错误。两个链接具有完全相同的代码。
我的cargo.toml 如下所示
[dependencies]
base64 = "0.13.0"
serde_json = "1.0.64"
serde = { version = "1.0.126",features = ["derive"] }
似乎 web-assemble rust 不支持 base64
lib(据我所知,因为我是 Rust 的新手)
我的问题:我有哪些选择可以解决这个问题?**
如何重现完整的场景(很简单,如下 步骤)
下载 wasme
(生成 Rust 项目)
curl -sL https://run.solo.io/wasme/install |嘘
Init skeleton project
wasme init ./new-filter ---> choose rust
将 base64 代码添加到 filter.rs
文件
Run the build
wasme build rust -t mytest . (needs docker)
有关 wasme
等的更多信息可以在 here
您将看到我上面提供的错误,与使用 WASM 运行 Playground 时相同
如果有什么遗漏或不清楚,请告诉我,我会补充
解决方法
我不认为这是 base64 板条箱本身的问题;我已经能够在面向浏览器的 Rust 项目(通过 wasm-bindgen)和创建特使过滤器的项目(使用 proxy-wasm-rust-sdk crate)中使用它。
我认为您遇到的问题与特定在 wasme 中声明依赖项的方式有关 - 请参阅项目中自动生成的 BUILD 文件,您可能需要对其进行调整。 (而且 solo.io 的人经常在他们的 wasm 松弛频道提供重点帮助。)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。