Stream: git-wasmtime

Topic: wasmtime / issue #2968 Wasmtime tutorial is incorrect: Im...


view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2021 at 14:56):

seanaye opened issue #2968:

After following the wasmtime tutorial https://github.com/bytecodealliance/wasmtime/blob/main/docs/WASI-tutorial.md I am unable to run the resulting output in the polyfill site.

The site errors with Import #0 module="wasi_snapshot_preview1" error: module is not an object or function

I have compiled the rust example in the tutorial, and even dumbed it down slighty so that it doesnt require CLI arguments. Here is my code.

use std::fs;
use std::io::{Write, self};

fn process(input_str: &str, output_fname: &str) -> Result<(), String> {

    let mut output_file = fs::File::create(output_fname)
        .map_err(|err| format!("error opening output {}: {}", output_fname, err))?;
    output_file
        .write_all(input_str.as_bytes())
        .map_err(|err| format!("write error: {}", err))
}

fn main() -> io::Result<()> {
    if let Err(err) = process(&"Hello World", &"tmp/file.txt") {
        eprintln!("{}", err)
    }

    io::stdout().write_all(b"done writing")?;
    Ok(())
}

I have confirmed that this code runs as expected in the wasmtime cli

view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2021 at 15:02):

bjorn3 commented on issue #2968:

The javascript polyfill is very much outdated.

view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2021 at 15:08):

seanaye commented on issue #2968:

@bjorn3 ah that makes, sense, thanks. Are there plans to update it?

view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2021 at 15:08):

seanaye closed issue #2968:

After following the wasmtime tutorial https://github.com/bytecodealliance/wasmtime/blob/main/docs/WASI-tutorial.md I am unable to run the resulting output in the polyfill site.

The site errors with Import #0 module="wasi_snapshot_preview1" error: module is not an object or function

I have compiled the rust example in the tutorial, and even dumbed it down slighty so that it doesnt require CLI arguments. Here is my code.

use std::fs;
use std::io::{Write, self};

fn process(input_str: &str, output_fname: &str) -> Result<(), String> {

    let mut output_file = fs::File::create(output_fname)
        .map_err(|err| format!("error opening output {}: {}", output_fname, err))?;
    output_file
        .write_all(input_str.as_bytes())
        .map_err(|err| format!("write error: {}", err))
}

fn main() -> io::Result<()> {
    if let Err(err) = process(&"Hello World", &"tmp/file.txt") {
        eprintln!("{}", err)
    }

    io::stdout().write_all(b"done writing")?;
    Ok(())
}

I have confirmed that this code runs as expected in the wasmtime cli

view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2021 at 15:08):

seanaye reopened issue #2968:

After following the wasmtime tutorial https://github.com/bytecodealliance/wasmtime/blob/main/docs/WASI-tutorial.md I am unable to run the resulting output in the polyfill site.

The site errors with Import #0 module="wasi_snapshot_preview1" error: module is not an object or function

I have compiled the rust example in the tutorial, and even dumbed it down slighty so that it doesnt require CLI arguments. Here is my code.

use std::fs;
use std::io::{Write, self};

fn process(input_str: &str, output_fname: &str) -> Result<(), String> {

    let mut output_file = fs::File::create(output_fname)
        .map_err(|err| format!("error opening output {}: {}", output_fname, err))?;
    output_file
        .write_all(input_str.as_bytes())
        .map_err(|err| format!("write error: {}", err))
}

fn main() -> io::Result<()> {
    if let Err(err) = process(&"Hello World", &"tmp/file.txt") {
        eprintln!("{}", err)
    }

    io::stdout().write_all(b"done writing")?;
    Ok(())
}

I have confirmed that this code runs as expected in the wasmtime cli

view this post on Zulip Wasmtime GitHub notifications bot (Jun 05 2021 at 16:47):

bjorn3 commented on issue #2968:

Not that I am aware of. Created a pure js polyfill for a subset of wasi a couple of months ago: https://github.com/bjorn3/rust/blob/compile_rustc_wasm4/rustc.html You could try if it works well enough for you.


Last updated: Dec 23 2024 at 13:07 UTC