Auto-generate the hostcalls module of wasi-common (#846)
* Auto-generate shims for old `wasi_unstable` module This commit is effectively just doing what #707 already did, but applying it to the `snapshot_0` module as well. The end result is the same, where we cut down on all the boilerplate in `snapshot_0` and bring it in line with the main `wasi_snapshot_preview1` implementation. The goal here is to make it easier to change the two in tandem since they're both doing the same thing. * Migrate `wasi_common::hostcalls` to a macro This commit migrates the `hostcalls` module to being auto-generated by a macro rather than duplicating a handwritten signature for each wasi syscall. * Auto-generate snapshot_0's `hostcalls` module Similar to the previous commit, but for `snapshot_0` * Delete the `wasi-common-cbindgen` crate This is no longer needed with the hostcalls macro now, we can easily fold the definition of the cbindgen macro into the same crate. * Rustfmt * Fix windows build errors * Rustfmt * Remove now no-longer-necessary code * rustfmt
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::fs::{error::wasi_errno_to_io_error, Metadata};
|
||||
use crate::{host, hostcalls, wasi, WasiCtx};
|
||||
use crate::fs::Metadata;
|
||||
use crate::{host, hostcalls, hostcalls_impl, wasi, Result, WasiCtx};
|
||||
use std::io;
|
||||
|
||||
/// A reference to an open file on the filesystem.
|
||||
@@ -34,8 +34,11 @@ impl<'ctx> File<'ctx> {
|
||||
/// This corresponds to [`std::fs::File::sync_all`].
|
||||
///
|
||||
/// [`std::fs::File::sync_all`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.sync_all
|
||||
pub fn sync_all(&self) -> io::Result<()> {
|
||||
wasi_errno_to_io_error(unsafe { hostcalls::fd_sync(self.ctx, &mut [], self.fd) })
|
||||
pub fn sync_all(&self) -> Result<()> {
|
||||
unsafe {
|
||||
hostcalls_impl::fd_sync(self.ctx, &mut [], self.fd)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// This function is similar to `sync_all`, except that it may not synchronize
|
||||
@@ -44,8 +47,11 @@ impl<'ctx> File<'ctx> {
|
||||
/// This corresponds to [`std::fs::File::sync_data`].
|
||||
///
|
||||
/// [`std::fs::File::sync_data`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.sync_data
|
||||
pub fn sync_data(&self) -> io::Result<()> {
|
||||
wasi_errno_to_io_error(unsafe { hostcalls::fd_datasync(self.ctx, &mut [], self.fd) })
|
||||
pub fn sync_data(&self) -> Result<()> {
|
||||
unsafe {
|
||||
hostcalls_impl::fd_datasync(self.ctx, &mut [], self.fd)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Truncates or extends the underlying file, updating the size of this file
|
||||
@@ -54,10 +60,11 @@ impl<'ctx> File<'ctx> {
|
||||
/// This corresponds to [`std::fs::File::set_len`].
|
||||
///
|
||||
/// [`std::fs::File::set_len`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.set_len
|
||||
pub fn set_len(&self, size: u64) -> io::Result<()> {
|
||||
wasi_errno_to_io_error(unsafe {
|
||||
hostcalls::fd_filestat_set_size(self.ctx, &mut [], self.fd, size)
|
||||
})
|
||||
pub fn set_len(&self, size: u64) -> Result<()> {
|
||||
unsafe {
|
||||
hostcalls_impl::fd_filestat_set_size(self.ctx, &mut [], self.fd, size)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Queries metadata about the underlying file.
|
||||
@@ -65,7 +72,7 @@ impl<'ctx> File<'ctx> {
|
||||
/// This corresponds to [`std::fs::File::metadata`].
|
||||
///
|
||||
/// [`std::fs::File::metadata`]: https://doc.rust-lang.org/std/fs/struct.File.html#method.metadata
|
||||
pub fn metadata(&self) -> io::Result<Metadata> {
|
||||
pub fn metadata(&self) -> Result<Metadata> {
|
||||
Ok(Metadata {})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user