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

Map directory for instance #426

Open
alhafoudh opened this issue Feb 4, 2025 · 6 comments
Open

Map directory for instance #426

alhafoudh opened this issue Feb 4, 2025 · 6 comments

Comments

@alhafoudh
Copy link

alhafoudh commented Feb 4, 2025

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 ...

@jbourassa
Copy link
Collaborator

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?

@alhafoudh
Copy link
Author

@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)

@jbourassa
Copy link
Collaborator

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>

@alhafoudh
Copy link
Author

alhafoudh commented Feb 5, 2025

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?

@jbourassa
Copy link
Collaborator

The rake pkg:ruby command 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-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?

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.

@alhafoudh
Copy link
Author

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?

#427

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