extism icon indicating copy to clipboard operation
extism copied to clipboard

Docs - quickstart - Write a Plug-in - the wasm*-unknown-unknown targets are not supported by default, you may need to enable the "js" feature

Open rmoraes92 opened this issue 1 year ago • 1 comments

Hi,

I was following the Write a Plug-in example at https://extism.org/docs/quickstart/plugin-quickstart and got the following message with cargo build --target wasm32-unknown-unknown:

   Compiling memchr v2.7.4
   Compiling byteorder v1.5.0
   Compiling num-traits v0.2.19
   Compiling cfg-if v1.0.0
   Compiling thiserror-impl v1.0.69
   Compiling serde_derive v1.0.214
   Compiling regex-syntax v0.8.5
   Compiling wasm-bindgen-backend v0.2.95
   Compiling crossbeam-utils v0.8.20
   Compiling zerocopy-derive v0.7.35
   Compiling aho-corasick v1.1.3
   Compiling itoa v1.0.11
   Compiling ryu v1.0.18
   Compiling chrono-tz-build v0.3.0
   Compiling crossbeam-epoch v0.9.18
   Compiling wasm-bindgen-macro-support v0.2.95
   Compiling bstr v1.10.0
   Compiling regex-automata v0.4.8
   Compiling zerocopy v0.7.35
   Compiling getrandom v0.2.15
error: the wasm*-unknown-unknown targets are not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support
   --> /home/random-user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.15/src/lib.rs:342:9
    |
342 | /         compile_error!("the wasm*-unknown-unknown targets are not supported by \
343 | |                         default, you may need to enable the \"js\" feature. \
344 | |                         For more information see: \
345 | |                         https://docs.rs/getrandom/#webassembly-support");
    | |________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> /home/random-user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.15/src/lib.rs:398:9
    |
398 |         imp::getrandom_inner(dest)?;
    |         ^^^ use of undeclared crate or module `imp`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `getrandom` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

rmoraes92 avatar Nov 11 '24 00:11 rmoraes92

Does your lib.rs include any modifications from the generated plugin?

I just ran extism gen plugin -l Rust -o plugin and generated a plugin with the following code in lib.rs:

use extism_pdk::*;
use serde::{Deserialize, Serialize};

// start with something simple
#[plugin_fn]
pub fn greet(name: String) -> FnResult<String> {
    Ok(format!("Hello, {}!", name))
}

// use json data for inputs and outputs
#[derive(FromBytes, Deserialize, PartialEq, Debug)]
#[encoding(Json)]
struct Add {
    left: i32,
    right: i32,
}
#[derive(ToBytes, Serialize, PartialEq, Debug)]
#[encoding(Json)]
struct Sum {
    value: i32,
}

#[plugin_fn]
pub fn add(input: Add) -> FnResult<Sum> {
    Ok(Sum {
        value: input.left + input.right,
    })
}

From inside of plugin, it built with cargo build --target wasm32-unknown-unknown without any issue.

G4Vi avatar Nov 11 '24 00:11 G4Vi