74 Commits

Author SHA1 Message Date
David Desmarais-Michaud 5dd247b60e wazevo: concurrent local wasm function compilation (#2381)
Signed-off-by: David Desmarais-Michaud <desmarais.michaud.david@gmail.com>
Co-authored-by: Nuno Cruces <ncruces@users.noreply.github.com>
2025-10-27 14:59:02 -07:00
Anuraag (Rag) Agrawal 8358482d4a Update to latest TinyGo and Rust (#2368)
Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
2025-01-21 07:42:05 -08:00
Takeshi Yoneda 6016a705fa cli: clarifies it is possible to escape the mount in help (#2328)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-10-03 15:48:52 -07:00
Takeshi Yoneda 7ad2b70626 Removes GOOS=js related leftovers (#2193)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-04-22 11:17:10 +09:00
Nuno Cruces c6a907bb9d experimental: cleanup context keys (#2175)
Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2024-04-06 21:04:55 +09:00
Edoardo Vacchi f2c9a986b6 chore: ensure all tinygo binaries have been built with 0.31.1 (#2140)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2024-03-08 14:57:01 +09:00
Takeshi Yoneda 3c7bc733c5 Nuke old singlepass compiler, enable optimizing compiler by default (#2130)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-03-07 15:26:45 +09:00
Takeshi Yoneda ccf60cb7a9 Enables amd64 backend for optimizing compiler in experimental pkg (#2071)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-02-19 10:00:13 +09:00
Takeshi Yoneda 0a03e179df Deletes experimental GOOS=js support (#2027) 2024-02-07 18:44:00 -08:00
Takeshi Yoneda fe8d467cac wazevo(amd64): set up spectests (#1972)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2024-01-29 10:42:33 -08:00
Takeshi Yoneda 87a48d8eee Introduces the new optimizing compiler (wazevo) in experimental pkg (#1869)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-12-14 08:27:35 -08:00
Takeshi Yoneda 352b7e2644 ci: use the latest Go 1.21 (#1616)
https://go.dev/blog/go1.21

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
2023-08-09 09:01:25 +09:00
Crypt Keeper 2f2b6a9d2c sysfs: Makes ReadFS and AdaptFS embeddable (#1607)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-08-02 08:27:50 +08:00
Crypt Keeper 1f8c908f1c Exposes writeable filesystem as experimentalsys.FS (#1605)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-31 07:56:28 +08:00
Shoki Hata 6ffb2d61dd docs: replace relative path (#1591)
Signed-off-by: Shoki Hata <syouki100241@gmail.com>
2023-07-22 10:54:42 -07:00
Crypt Keeper 2f8dd23097 adds experimental sys.Errno to begin decoupling from the syscall package (#1582)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-17 08:13:29 +08:00
Crypt Keeper 276257102f gojs: removes user/group behavior (#1566)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-07 10:27:41 +08:00
Crypt Keeper 7498ad335f gojs: drops HTTP support to be compatible with Go 1.21 (#1557)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-07-05 16:56:18 +08:00
Crypt Keeper 53ce5eea83 Allows wasip1 guests to use arbitrarily nested pre-opens (#1536)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-06-27 10:02:57 +08:00
Edoardo Vacchi 97d0d70b73 wasi: add support for sockets (#1493)
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
Co-authored-by: Achille <achille.roussel@gmail.com>
Co-authored-by: Adrian Cole <adrian@tetrate.io>
2023-06-02 20:45:42 +08:00
Achille 1c2ca99834 wazero: add -count option to compile command (#1470)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-15 18:54:45 -07:00
Achille ab116e9c21 compiler: reuse asm.Node slice collecting NOP instructions for source mapping (#1465)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-14 15:20:17 -07:00
Achille b42ec37d0b wazero: allow cpu and memory profiling when compiling or running modules (#1462)
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
2023-05-13 23:23:57 -07:00
Achille d5a2d3c7b4 wasip1: fix file open modes used by wasi-libc (#1421)
This extends wazero's interpretation of rights in wasi_snapshot_preview1.path_open to allow programs to open files in either read-only, write-only, or read-write mode.

Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Crypt Keeper <64215+codefromthecrypt@users.noreply.github.com>
2023-05-02 09:48:26 +08:00
Nuno Cruces 197facf7a9 Close certain api interfaces for external implementation (#1396)
This adds a new type `internalapi.WazeroOnly` which should be embedded on types users are likely to accidentally implement despite docs saying otherwise.

Signed-off-by: Nuno Cruces <ncruces@users.noreply.github.com>
2023-04-28 15:32:32 +08:00
Crypt Keeper 451c792ee8 Avoids returning ExitError on exit code zero, and optimizes for no allocations (#1284)
Fixes #1283

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-24 16:42:30 +01:00
Crypt Keeper 8464474e21 gojs: adds support for uid and gid (#1245)
This adds `gojs.WithOSUser` which passes through current user IDs so
that GOOS=js compiled wasm can read them. This also adds support for
reading back the uid and gid on files. In summary, this passes
`os.TestChown` except on windows where it will not work due to lack of
support.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-16 11:07:27 +08:00
Crypt Keeper 12e80b4bc5 cli: removes experimental-workdir-inherit flag (#1242)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-15 13:09:19 +08:00
Takeshi Yoneda f24a3f49a4 gojs: refactors out gojs.Config type (#1240)
In order to support more configuration, we should stop using context as
it is getting gnarly.

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-15 12:27:47 +08:00
Crypt Keeper ced3011837 cli: exposes all hostlogging scope (#1238)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-14 13:56:19 +08:00
Crypt Keeper 14c409eaf7 cli: changes experimental workdir flag to inherit (#1235)
This changes the experimental flag introduced yesterday to
`-experimental-workdir-inherit=true`, to reduce edge cases needed to
produce the same behavior as go's wasm test runner.

After this, we have the same failure count, though the latter is likely
related to my machine:

```bash
$ wasm=$PWD/os.wasm; (cd $(go env GOROOT)/src/os; wazero run -mount=/:/ --experimental-workdir-inherit=true $wasm)
--- FAIL: TestMkdirAllAtSlash (0.00s)
    path_test.go:111: MkdirAll "/_go_os_test/dir": mkdir /_go_os_test: I/O error, I/O error
--- FAIL: TestOpenFileLimit (0.01s)
    rlimit_test.go:31: open rlimit.go: I/O error
FAIL
```

See https://github.com/golang/go/blob/master/misc/wasm/wasm_exec_node.js#L24

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-14 10:20:44 +08:00
Edoardo Vacchi c45f0ef062 fix: --experimental-workdir test case on Windows (#1233)
Interesting issue due to a lot of weird interactions between
path handling and system defaults.

The test will pass outside of CI (e.g. on my local machine),
because usually you will run this on C:\, which is the root
of your filesystem.

However, GitHub Actions mounts the test filesystem on D:,
causing the path handling routines to miss it.

You can simulate this even if you don't have a second drive:
assuming you have `wazero` under `%USERPROFILE%\Devel\wazero`

    subst X: %USERPROFILE%\Devel
    cd X:\wazero
    make test

However, we are ignoring path information because:

```go
func WithWorkdir(ctx context.Context, workdir string) context.Context {
	// Ensure if used on windows, the input path is translated to a POSIX one.
	workdir = workdir[len(filepath.VolumeName(workdir)):]
```

strips the Volume

The other weird bit happens in the test itself:

```
--mount=/:/ --experimental-workdir=$bearDir
```

What is happening here is that we are mount the root of our FS
to / (thereby exposing the entire FS to the test) and then
telling the guest to set the CWD to `$bearDir`.

However, on Windows we don't have a unique `/` (well technically
we do; see [UNC Paths][0] but that's another story) but each `/` has a volume attached.

So, on Windows we shouldn't `--mount=/:/` but rather one root volume
(in fact, the other tests work because they do `--mount=$bearDir:/`)
i.e. X:\ or, more generally `VolumeName($bearDir)`

Finally, although `WithWorkdir` is stripping the volume name,
we should probably pass a path without the volume name or at least ensuring
that that CWD makes sense together with the host mount directive; i.e.

when we pass `--mount=x:\:/` we should either pass `--workdir=\wazero\...`
or ensure that the volume name matches `--workdir=x:\wazero\...` and
return an error otherwise.

For now I am only fixing the test.

[0]: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-14 07:34:53 +08:00
Crypt Keeper 7e953d7483 gojs: introduces --experimental-workdir CLI arg (#1226)
When compiled to `GOOS=js`, wasm does not maintain the working
directory: it is defined by the host. While not explicitly documented,
`os.TestDirFSRootDir` in Go suggests the working directory must be valid
to pass (literally the directory holding the file).

This adds an experimental CLI flag that gives the initial working
directory. This is experimental because while GOOS=js uses this, current
WASI compilers will not, as they maintain working directory in code
managed by wasi-libc, or as a convention (e.g. in Zig).

It is not yet known if wasi-cli will maintain working directory
externally or not.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-13 15:43:45 +08:00
Crypt Keeper 6243091dc2 renames exit log scope to proc and resolves gojs files to cwd (#1223)
Many tests failed in gojs due to needing to be resolved against the CWD,
which is atypically stored host side. This fixes that and renames the
"exit" scope to "proc" so we can use it for other proc concerns besides
exit.

This reduces known failures on GOOS=js from 23 to 14:
```bash
$ wazero run -mount=/usr/local/go/src/os:/:ro -mount=/tmp:/tmp -mount=/etc:/etc:ro -mount=/usr:/usr:ro -mount=/dev:/dev:ro os.wasm |grep '^--- FAIL'|wc -l
      14
```

See #1222

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-03-13 11:41:19 +08:00
Edoardo Vacchi 19773267ba cli: support wasi_unstable namespace (#1217)
While playing with interesting examples to show off Wazero CLI,
I found that older binaries that still use the `wasi_unstable`
namespace are rejected.

This is a small refactoring to support running these binaries
as well.

Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
2023-03-11 06:48:58 +08:00
Crypt Keeper 25493fe271 gojs: makes experimental status explicit (#1200)
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>
2023-03-06 09:22:58 +08:00
Edoardo Vacchi 5598e491f7 Add timeout support in wazero run cli (#1173)
- 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>
2023-03-01 07:46:57 +08:00
Egon Elbre 350f4de23c cmd/wazero: fix temp dir handling in TestRun (#1125)
TestRun clears the environment, which means the os specific temporary
directory is also cleared; which then either creates the directory to
the wrong place or it doesn't have any access to create the directory
altogether.

Move the temporary directory creation before clearing the environment
variables.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
2023-02-14 07:50:31 -10:00
Crypt Keeper fac714eaa4 cli: adds env-inherit flag for SCRATCH images (#1117)
This adds an `env-inherit` boolean flag which adds all variables to the
guest ENV.

For example, the below `env-reader.wasm` guest will see the variable
`STAR` and anything set via the runner (docker, podman, etc.):
```
--snip--
FROM scratch
COPY --from=build /build/wazero/wazero /bin/wazero

ENTRYPOINT ["/bin/wazero", "run", "-env-inherit", "-cachedir=/cache", "-mount=.:/"]

ENV STAR=wazero

COPY --from=wasm / .
CMD ["env-reader.wasm"]
```

Note: This isn't appropriate otherwise as it will also propagate
variables like PATH and TMPDIR which aren't likely valid on the guest,
or in worst case may risk crashing.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-10 08:05:57 -10:00
Crypt Keeper b4cb7d0702 cli: renames interp flag to interpreter (#1116)
non-shortcut flags should be complete words or abbreviations, not
truncated words.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-09 20:43:01 -10:00
YAMAMOTO Takashi e2fde2500e cli: add an option to force interpreter (#1115)
Signed-off-by: YAMAMOTO Takashi <imuwoto@gmail.com>
2023-02-10 14:24:35 +09:00
Crypt Keeper 8918d73020 ci: supports building with Go 1.20 and raises floor version to 1.18 (#1096)
This moves our floor version to the same we'll release 1.0 with: 1.18.
This is congruent with our version policy which is current-2.

Fixes #921

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-06 17:29:08 +02:00
Crypt Keeper add9020b33 cli: adds an example Dockerfile (#1099)
It is important for understanding the recent trends in Docker and
WebAssembly to see what a Dockerfile looks like in wazero. For example,
things that natively support wasm right now can take off the 4.5MB our
binary would cost, as well hide some of the configuration you can see,
such as coercing arguments or ENV. Since wasm isn't quite prime time in
Docker, some will be happy to use wazero instead or until it is ready.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-02-06 08:32:57 +09:00
Crypt Keeper d04199d1c3 cli,wasi: passes mounts directly as preopens to run rust wasi-testsuite (#1078)
This allows wasi to see mounts as individual preopens instead of
virtualized under a root. (GOOS=js doesn't use pre-opens so it still
sees a virtual root). This allows us to progress wasi-testsuite rust
tests, but acknowledges a current glitch in zig support, which is
tracked separately as #1077

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-30 08:11:16 +02:00
Crypt Keeper 282ffc5ced logging: adds memory scope (#1076)
This allows you to specify the memory scope amongst existing logging scopes, both in API and the CLI.

e.g for the CLI.
```bash
$ wazero run --hostlogging=memory,filesystem --mount=.:/:ro cat.wasm
```

e.g. for Go
```go
loggingCtx := context.WithValue(testCtx, experimental.FunctionListenerFactoryKey{},
	logging.NewHostLoggingListenerFactory(&log, logging.LogScopeMemory|logging.LogScopeFilesystem))
```

This is helpful for emscripten and gojs which have memory reset
callbacks. This will be much more interesting once #1075 is implemented.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-29 10:58:59 +02:00
Crypt Keeper da99a7f5c0 logging: adds exit scope and fixes mtim bug (#1074)
This allows you to specify the exit scope amongst existing logging scopes, both in API and the CLI.

e.g for the CLI.
```bash
$ wazero run --hostlogging=exit,filesystem --mount=.:/:ro cat.wasm
```

e.g. for Go
```go
loggingCtx := context.WithValue(testCtx, experimental.FunctionListenerFactoryKey{},
	logging.NewHostLoggingListenerFactory(&log, logging.LogScopeExit|logging.LogScopeFilesystem))
```

This is helpful to know if the wasm called exit or if it exited
implicitly. This is one of the few host functions that exists in three
places: assemblyscript, gojs and wasi.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-29 08:43:14 +02:00
Crypt Keeper 67662efac9 logging: cleanups and allows comma-separated scope expansion (#1073)
This allows the CLI to use `-hostlogging=filesystem,poll` instead of or
in addition to multiple flags.

This also makes the parameter loggers more debugable by using pointer
receivers. When they are copied, the field names end up garbage in the
debugger.

Finally, this fixes a glitch where we used GOOS=js where we thought we
were using WASI (in cmd tests).

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-29 07:38:53 +02:00
Crypt Keeper 9cf07b4d44 logging: adds poll scope (#1072)
This allows you to specify the poll scope amongst existing logging scopes, both in API and the CLI.

e.g for the CLI.
```bash
$ wazero run --hostlogging=poll --hostlogging=filesystem --mount=.:/:ro cat.wasm
```

e.g. for Go
```go
loggingCtx := context.WithValue(testCtx, experimental.FunctionListenerFactoryKey{},
	logging.NewHostLoggingListenerFactory(&log, logging.LogScopePoll|logging.LogScopeFilesystem))
```

This is particularly helpful to understand side-effects of GC. For
example, in `GOOS=js` GC will trigger events and these have been tricky
to troubleshoot in the past.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-29 06:22:49 +02:00
Crypt Keeper d944c3c70d logging: adds clock scope (#1071)
Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-28 19:11:37 +02:00
Crypt Keeper bd9a791c7a logging: rename crypto scope to random (#1070)
This is to avoid a collision with an emerging wasi-crypto. They will
have both wasi-random and wasi-crypto

Signed-off-by: Adrian Cole <adrian@tetrate.io>
2023-01-28 13:15:28 +02:00