Map directory for instance
Is it possible to map directory for WASI instance?
I did not find any reference to this.
I need equivalent of wasmtime run app.wasm --mapdir /guest::/host ...
You're right, it is not implemented. We'd need to add a wrapper around preopened_dir in ext/src/ruby_api/wasi_ctx_builder.rs.
Do you want to take a stab at it?
@jbourassa I have the implementation ready but I don't know how to test it. The rake pkg:ruby command produces unusable gem.
I get error:
cannot load such file -- wasmtime/wasmtime_rb (LoadError)
cannot load such file -- wasmtime/3.4/wasmtime_rb (LoadError)
rake compile:dev produces the compiled binary. You should be able to use it directly with either: ruby -I lib or irb -I lib, then require "wasmtime":
❯ rake compile:dev
...snip...
❯ irb -I lib
>> require "wasmtime"
=> true
>> Wasmtime::Engine.new
=> #<Wasmtime::Engine:0x0000000104f6d470>
Got it, thanks! The preopened_dir works.
I will write some specs and issue a pull request.
One last thing, when I run it with wasmtime-rb locally, the Wasmtime::Module.from_file takes 1-2 minutes to load. When I use wasmtime-rb from rubygems.org it takes to load 3-5 seconds. Do you have any idea why?
Could the :dev in compile:dev cause it?
The
rake pkg:rubycommand produces unusable gem.
How did you install it? Was there any error on install? I don't know what's different in my env but it worked for me:
gem install --local pkg/wasmtime-29.0.0.gem && \
ruby -e 'require "wasmtime"; Wasmtime::Module.new(Wasmtime::Engine.new, "(module)")'
Asking to see if something's broken so that we can fix it.
One last thing, when I run it with
wasmtime-rblocally, theWasmtime::Module.from_filetakes 1-2 minutes to load. When I usewasmtime-rbfrom rubygems.org it takes to load 3-5 seconds. Do you have any idea why?Could the
:devincompile:devcause it?
That would be my guess -- you can try the slower rake compile:release and see if that brings it back to 3-5s?
I will write some specs and issue a pull request.
Testing WASI is tricky, looking forward to seeing the specs you'll come up with! Please keep in mind that we want the test suite to be fast, so a very small Wasm would be ideal.
Yes, the compile:release helped to speed it up back to 3-5 seconds. 👌
Here is the PR without tests for now. Can you take a quick look at it? WDYT?
https://github.com/bytecodealliance/wasmtime-rb/pull/427