Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Err value: unknown import: wasi_snapshot_preview1::fd_write has not been defined #8521

Open
maxwellflitton opened this issue May 1, 2024 · 1 comment

Comments

@maxwellflitton
Copy link

There's been some changes in the API, however, I'm getting the same error. My Cargo.toml has the following:

wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
wasm-bindgen-futures = "0.4.42"
bincode = "1.3.3"
tokio = { version = "1.0", features = ["full"] }
wasmtime = { version = "20.0.0", features = ["runtime", "async"] }
wasmtime-wasi = { version = "20.0.0", features = ["preview1"] }

And my code consists of the following:

use wasmtime::*;
use wasmtime_wasi::WasiCtxBuilder;
use wasmtime_wasi::preview1::wasi_snapshot_preview1::add_to_linker;

#[tokio::main]
async fn main() {
    let mut config = Config::new();
    config.async_support(true);
    let engine = Engine::new(&config).unwrap();

    let mut linker = Linker::new(&engine);

    let wasi = WasiCtxBuilder::new()
        .inherit_stdio()
        .inherit_args()
        .build_p1();
    let mut store = Store::new(&engine, wasi);

    add_to_linker(&mut linker, |s| s).unwrap();

    let module = Module::from_file(&engine, "../wasi-server/wasi_server.wasm").unwrap();
    let link = linker.instantiate_async(&mut store, &module).await.unwrap();
}

But I get the following error on the let link = linker.instantiate_async(&mut store, &module).await.unwrap();:

called `Result::unwrap()` on an `Err` value: unknown import: `wasi_snapshot_preview1::fd_write` has not been defined
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@alexcrichton
Copy link
Member

Ah I commented elsewhere too, but:

@maxwellflitton you might be interested in the documentation to get started here, namely you're missing a call to add_to_linker_async

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants