-
Notifications
You must be signed in to change notification settings - Fork 15
Begin sketching out a new high-level fs
API.
#91
Conversation
src/fs/ctx.rs
Outdated
use crate::WasiCtx; | ||
|
||
lazy_static! { | ||
// TODO: Should we allow the context to be passed alternate arguments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I guess we should. How otherwise are we going to pass in the preopens? Or are we going to add another mid-level call for that perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this a little more, I don't think a lazy_static
singleton is the way to go, because people using this API may want to have multiple distinct WasiCtx
s that are isolated from each other. I've now updated the patch to have Dir
and File
hold a reference to a WasiCtx
. We may further want to make it an Rc
, but we'll see how things go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
78132c9
to
522a9fc
Compare
This is now complete enough to compile, and a lot of the API surface area is now in place, though most of the functionality isn't implemented yet. |
))?; | ||
*/ | ||
|
||
let ctx = self.ctx; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary here? Could we not simply pass self.ctx
directly?
Err(io::Error::from_raw_os_error(raw_os_error)) | ||
} | ||
|
||
#[cfg(windows)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that in the future it'd be useful to have the same setup as for the hostcalls? That is, separate host specifics in modules and then just do a cfg_if
instead of multiple #[cfg(..)]
s? Mind you, this is an idea for the future and not now; I'm happy with the state of error.rs
as is :-)
/// | ||
/// [`std::fs::Metadata`]: https://doc.rust-lang.org/std/fs/struct.Metadata.html | ||
#[derive(Clone)] | ||
pub struct Metadata {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct Metadata {} | |
pub struct Metadata; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Here's a thought: could we actually re-use this interface and the implementation in Rust's libstd
? I might be way off base here but browsing through the changes here looks as if it could be re-used in libstd
. @alexcrichton thoughts?
Seems possible perhaps! I suspect this'd want to bake a bit more before going into libstd, but the internal details of libstd are up for grabs to change at any time! |
Interesting idea. In addition to obviously baking :-), a few additional pieces we'd need:
@cc newpavlov since this is one possible path to a libc-free libstd for WASI targets. |
cc @newpavlov even, since this is one possible path to a libc-free libstd for WASI targets. |
I am not sure if I understand how it will work. All WASI code still works via Core API at the lowest level, right? And this high-level API is still built on top of Core API? Right now, we depend on Not strictly relevant, but can you explain how |
This is a very preliminary sketch of #83. It doesn't even compile yet, but it shows a possible high-level structure of such an API.
This builds, and although most of the functionality is not yet implemented, I'd like to land it and continue to iterate incrementally. |
@sunfishcode sounds great to me! Feel free to merge it or I can do that if you want. Also, apologies for little to no activity lately but got swamped with preparation work for the upcoming Devcon5 conference :-) |
This is a very preliminary sketch of #83. It doesn't even compile yet, but it shows a possible high-level structure of such an API.