3

I've created a program which works as expected:

extern crate base64;
// decode base64
let bytes = base64::decode(res[1]).unwrap();
[dependencies]
base64 = "0.13.0"
serde_json = "1.0.64"

When I add this code to Webassembly for an Envoy filter with base64 lib , I get the error:

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 works with the default "Run" button, but this playground doesn't work if you run it as "Wasm". You will get the error which described above. Both links have the exact same code.

my cargo.toml look like following

[dependencies]
base64 = "0.13.0"
serde_json = "1.0.64"
serde = { version = "1.0.126", features = ["derive"] }

It seems that web-assemble rust doesn't support base64 lib (as far as I understand it as I'm new to Rust)
My question: which options I have to overcome this issue ?**

How to reproduce the full scenario (quite simple with the following steps)

Download wasme (which generate a rust project)

curl -sL https://run.solo.io/wasme/install | sh

Init skeleton project

wasme init ./new-filter ---> choose rust

Add to the filter.rs file the base64 code

Run the build

wasme build rust -t mytest . (needs docker)

More info about wasme etc could be found here

And you will see the error which I provided above and is the same as the run the playground with WASM

If something is missing or isn't clear please let me know and I'll add

Jenney
  • 171
  • 6
  • 18
  • I don't know if this is the problem, but by default `base64` relies on the standard library which might make it incompatible with WASM. You can turn that off in your `Cargo.toml` by putting `base64 = { version = "0.13.0", features = [] }` instead of `base64 = "0.13.0"`. Hope that's it. – isaactfa Jul 03 '21 at 11:51
  • @isaactfa - thanks! I try it out and I got the same error , do you have any other idea how can I overcome this issue? – Jenney Jul 03 '21 at 14:54

1 Answers1

0

I don't think this is an issue with the base64 crate itself; I've been able to use it both in a Rust project targeting browser (via wasm-bindgen) and in a project creating an envoy filter (using the proxy-wasm-rust-sdk crate).

I think the issue you are experiencing has to do with the way dependencies are declared in wasme specifically - see the autogenerated BUILD file in your project, you might need to adjust it. (And the solo.io folks often provide focused help at their wasm slack channel.)

M.A. Hanin
  • 8,044
  • 33
  • 51