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

Implement preopened_dir using set_mapped_directories setting #427

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

alhafoudh
Copy link

No description provided.

Copy link
Collaborator

@jbourassa jbourassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasmtime's API for this takes 1 dir at a time -- not a collection of (src, dest). Unless we have a reason to, I'd rather stick to the Rust API shape and naming.

Sticking to the rust crate API been a general rule of thumb for the Ruby bindings. In this case, it makes the API easier to describe. Especially as we eventually migrate to wasmtime_wasi instead of wasi_common which has additional params for permissions.

VERSION = "29.0.0"
VERSION = "30.0.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not bump the version number

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

use magnus::{
class, function, gc::Marker, method, typed_data::Obj, value::Opaque, DataTypeFunctions, Error,
Module, Object, RArray, RHash, RString, Ruby, TryConvert, TypedData,
Integer, Module, Object, RArray, RHash, RString, Ruby, TryConvert, TypedData,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see Integer being used, I think we can revert that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I will revert this.

@@ -47,6 +49,7 @@ struct WasiCtxBuilderInner {
stderr: Option<WriteStream>,
env: Option<Opaque<RHash>>,
args: Option<Opaque<RArray>>,
mapped_directories: Option<Opaque<RArray>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When holding references to Ruby objects, we must GC mark them, otherwise the GC might collect the object. See WasiCtxBuilderInner::mark on L56 for how it's done.

@alhafoudh
Copy link
Author

Wasmtime's API for this takes 1 dir at a time -- not a collection of (src, dest). Unless we have a reason to, I'd rather stick to the Rust API shape and naming.

Sticking to the rust crate API been a general rule of thumb for the Ruby bindings. In this case, it makes the API easier to describe. Especially as we eventually migrate to wasmtime_wasi instead of wasi_common which has additional params for permissions.

Should I just append one by one to the array and then call the builder.preopened_dir() by iterating the array?

@jbourassa
Copy link
Collaborator

Should I just append one by one to the array and then call the builder.preopened_dir() by iterating the array?

Sounds reasonable to me.

The array should contain RStrings to avoid memcopys from owned Strings ((RString, RString) maybe?). And then, when creating the paths / bufs, try and avoid creating owned strings with RString::as_str (unsafe). Note: this only works if we are guaranteed to not allocate for the duration of the str reference, which I think here we can guarantee.

Let me know once you're done with the change and the tests.

@alhafoudh
Copy link
Author

I have updated the way how set_mapped_directory works. This is my first time writing rust, sorry. I dont have the insight into the magnus, rust and memory management alltogether. :-)
Maybe can you finish it up so it is written correctly?

@jbourassa
Copy link
Collaborator

I can take a look at cleaning it up once the tests are in -- care to add those in?

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

Successfully merging this pull request may close these issues.

2 participants