Fixes#1211
Previously, host functions are getting api.Module for the "originating" module,
which is the module for api.Function currently invoked, except that the api.Module
is modified by withMemory with the caller's memory instance, therefore there
haven't been no problem for most cases. The only issues were the methods
besides Memory() of api.Module, and this commit fixes them.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Go has a test that forces us to handle Mkdir with zero as its
permissions. In GOOS=js, the result of fs.mkdir is a file descriptor,
and to open that, we can't use literally 0. Hence, to solve this we need
to coerce 0 to 0500 in GOOS=js.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This implements `platform.UtimesFile` which is similar to futimes.
Before, we were using path-based functionality even though the call site
was for a file descriptor.
Note: right now, there's no obvious code in Go to invoke the `futimens`
syscall. This means non-windows isn't implemented at nanos granularity,
so ends up falling back to the path based option.
Finally, this removes tests for the seldom supported updates with
negative epoch time. There's little impact to this as setting times on
files before 1970 isn't a typical use case.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This finishes the last remaining syscalls in `GOOS=js`. After this is
merged, further bugs are easier to hunt down as we know ENOSYS is not
expected on writeable file systems.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Before, our README said gojs `GOOS=js compiled wasm` was experimental.
However, as we head to 1.0 we should be more explicit about that.
When we started gojs, there was no likely future where `GOOS=wasi` would
happen in the standard go compiler. This has changed, so we'll only keep
the gojs package around until wasi is usable for two Go releases. Being
in an experimental package helps others know to watch out for this.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This implements the last remaining link functions using the same logic
as WASI. In doing so, this changes the signature for FS.ReadLink to be
more similar to the rest of the functions. Particularly, it stops
reading the result into a buffer.
After this, the only syscalls left to implement in gojs are chown.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
It looks like $(subst from,to,text) works differently on BSD make
vs GNU make. The behavior we expected for
$(subst,$(space),$(comma),$(var))
is instead the behavior of `$(patsubst ...)` on GNU Make.
The alternative syntax `$(var: =,)` seems portable across the two
and shows the same behavior.
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
In previous releases, passing a `nil` value as an FS config
did not cause any error. However, in 1.0.0-rc.1 this leads
to the creation of an invalid `adapter{fs: nil}`, which
eventually leads to a panic (nil):
(f *FileEntry) Stat(st *platform.Stat_t) =>
(r *lazyDir) file() =>
r.fs.OpenFile(".", os.O_RDONLY, 0)
with fs == nil
The backwards-compatible fix is to make Adapt()
return UnimplementedFS, and ensuring `nil` is a valid value
that config is able to handle.
However, we may want to consider returning an error somewhere,
because configuring a nil FS may be unintended.
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
This makes the headings mostly in order by tier, like libraries, then
middleware before compiled binaries.
This also adds Trivy, which was one of the original end users of wazero!
cc @knqyf263 who I asked permission from.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This adds a wazero adapter which passes wasi-testsuite 100pct on darwin,
linux and windows. While the main change was adding inodes to the wasi
`fd_readdir` dirents, there was a lot of incidental work needed.
Most of the work was troubleshooting in nature, around windows
specifically, but also wrapping of files. This backfills a lot of tests
and reworked how wrapping works, particularly around windows.
To accommodate this, we drop `os.File` special casing except for
`sysfs.DirFS`
Signed-off-by: Adrian Cole <adrian@tetrate.io>
- ensure the module initialization function is evaluated
regardless if it's WASI or GoJS
- add a `-timeout duration` flag
- ensure flag gets propagated to the rt config builder
(also ensure cache flag gets propagated to the rt config builder)
- print a message to stderr when the deadline is exceeded
- configure GitHub Actions to use `-timeout=10m` flag
instead of GHA's `timeout-minutes: 10`
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
gojs: implements lstat
This implements platform.Lstat and uses it in GOOS=js. Notably,
directory listings need to run lstat on their entries to get the correct
inodes back. In GOOS=js, directories are a fan-out of names, then lstat.
This also fixes stat for inodes on directories. We were missing a test
so we didn't know it was broken on windows. The approach used now is
reliable on go 1.20, and we should suggest anyone using windows to
compile with go 1.20.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This updates our examples to the latest SDKs as particularly this can
help reveal issues around fan-out stats.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
This handles EOF even if current and possibly future wasi don't have a
way to propagate an EOF signal. This is mainly to match up with go
semantics and ensure we don't have any error conditions (by adding
tests).
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Updated `newMemorySizer()` to return the updated value, but also
ensure that an invalid `max` still throws an error (invalid module).
- Minor cleanup to use the `memorySizer` type instead of the full
func signature for clarity
- Added a wat+wasm under `internal/integration_test/vs/testdata/`
simply because that's where the other cache-related testdata was.
Closes#1153.
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
We formerly cached only the directory type, to avoid re-stat'ing the
same directory many times. Since we are there, we can also cache the
inode, which is strictly required by wasi and costly to fetch. Note:
this only affects the directory: its contents still need a potential
fan-out of stats which will be handled in another change.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Before, we only tested wrapped filesystems implemented with `fs.FS`.
This adds our native filesystem type, showing the current benchmarks are
about the same for reading a directory, but a lot faster for stat.
Signed-off-by: Adrian Cole <adrian@tetrate.io>
If a context is canceled after a gust func call has returned it could
cause the module to close in some cases. This change ensures that
a delayed check of the context cancelation is ignored.
I've also reduced the cost of context cancelation a bit.
Signed-off-by: Clifton Kaznocha <ckaznocha@users.noreply.github.com>
wasi_snapshot_preview1 recently requires fd_readdir to return actual
inode values. On zero, wasi-libc will call fdstat to retrieve them.
This introduces our own `platform.Dirent` type and `Readdir` function
which a later change will allow fetching of inodes.
See https://github.com/WebAssembly/wasi-libc/pull/345
Signed-off-by: Adrian Cole <adrian@tetrate.io>