Code Monkey home page Code Monkey logo

Comments (14)

jeschkies avatar jeschkies commented on June 15, 2024 1

@maxmcd, thanks so much for your help. This seems to be it 🙂

from wasmtime-go.

alexcrichton avatar alexcrichton commented on June 15, 2024 1

Ah yeah I believe that'll solve those issues. In that case I'll go ahead and close this issue.

from wasmtime-go.

maxmcd avatar maxmcd commented on June 15, 2024

Can you try changing this:

wasi, err := wasmtime.NewWasiInstance(store, wasiConfig, "wasi_unstable")

To this:

wasi, err := wasmtime.NewWasiInstance(store, wasiConfig, "wasi_snapshot_preview1")

I think that might do it.

from wasmtime-go.

jeschkies avatar jeschkies commented on June 15, 2024

Thanks. Does it mean the WASM binary was compiled against wasi_snapshot_preview1?

the changed helped but now I get this

wasm trap: unreachable
wasm backtrace:
  0: 0x9661 - <unknown>!std::panicking::rust_panic_with_hook::h3a0a1147e3efaaf2
  1: 0xd6c4 - <unknown>!rust_begin_unwind
  2: 0xd873 - <unknown>!core::panicking::panic_fmt::h6bf85cafed31336d
  3: 0xcb57 - <unknown>!core::option::expect_none_failed::h7dfd2381e84fa608
  4: 0x9bd1 - <unknown>!run_nom

from wasmtime-go.

maxmcd avatar maxmcd commented on June 15, 2024

Yes, I believe wasi_snapshot_preview1 is the current supported phase for rust. I think that is determined by this crate: https://github.com/bytecodealliance/wasi

Can you show your rust code? It looks like your code might be panicking on an option .unwrap with option::expect_none_failed? (or maybe something similar, not sure why it would be "expect_none".

from wasmtime-go.

jeschkies avatar jeschkies commented on June 15, 2024

Sure, this is the run_nom method. And I already see an .unwrap() 🙈

#[no_mangle]
pub extern "C" fn run_nom() {
    let data = std::fs::read_to_string("data/small_access.log").unwrap();
    let p = nom::CommonLogParser { input: &data };
    assert_eq!(p.count(), 161761);
}

EDIT: I changed the code to print the error failed to find a preopened file descriptor through which "data/small_access.log" could be opened.

PreopenDir has little documentation. What should the guest path be? I used . for both paths.

from wasmtime-go.

maxmcd avatar maxmcd commented on June 15, 2024

Maybe better docs here: http://docs.wasmtime.dev/c-api/wasi_8h.html#a6d738a3510c5f3aa4a6f49d7bb658cd1

If you click into the Go src you can usually find which function is being called in the wasmtime C api.

Maybe try wasiConfig.PreopenDir(".", "/"), the first path is the path on the host, the second path is where the directory is mounted for wasm.

from wasmtime-go.

jeschkies avatar jeschkies commented on June 15, 2024

Thanks for the link. Still no luck. I tried a few combinations such as wasiConfig.PreopenDir(".", "/") and wasiConfig.PreopenDir("./data", "/data"). I do get the same error when I try to use the wasmtime CLI wasmtime --dir=. target/wasm32-wasi/release/loki_bench.wasm --invoke run_nom 🤔

from wasmtime-go.

maxmcd avatar maxmcd commented on June 15, 2024

Can't get it working either. Maybe it's this issue? rust-lang/rust#79199

from wasmtime-go.

maxmcd avatar maxmcd commented on June 15, 2024

btw, in case it's unclear. I was able to get your code working by just using the parse.wasm output. Since the parse wasm binary isn't a lib it seems to work if I update nom := instance.GetExport("run_nom").Func() to be nom := instance.GetExport("_start").Func()

That then runs this code: https://github.com/jeschkies/common-log-parser-bench/blob/karsten/go/src/bin/parse.rs#L5

And finds the right file

from wasmtime-go.

jeschkies avatar jeschkies commented on June 15, 2024

Thanks. That helped me with my original goal. I wanted to benchmark nom in WASM. How did you pass the argument to parse?

from wasmtime-go.

alexcrichton avatar alexcrichton commented on June 15, 2024

To confirm, I think everything here's been figured out? Or are there lingering questions I could help resolve?

from wasmtime-go.

jeschkies avatar jeschkies commented on June 15, 2024

I'm not sure how to pass the main args to a WASM. However, that should be unrelated to this issue. I guess rust-lang/rust#79199 will solve this issue.

from wasmtime-go.

maxmcd avatar maxmcd commented on June 15, 2024

@jeschkies you might just want to use command line arguments or environment variables.

from wasmtime-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.