-
-
Notifications
You must be signed in to change notification settings - Fork 259
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
Draft of WASI support #610
Commits on Aug 5, 2022
-
This is a first pass at implementing support for [WASI](https://wasi.dev/). It adds a new `TeaVMTargetType` of `WASI`, which is mostly the same as `WEBASSEMBLY` except it generates a module suitable for execution by a WASI-compatible runtime such as [Wasmtime](https://github.com/bytecodealliance/wasmtime). Currently supported features: - A simple allocator for supporting the component model [canonical ABI](https://github.com/WebAssembly/component-model/blob/main/design/mvp/CanonicalABI.md) calls - CLI argument marshaling - Standard in/out/err - Filesystem operations and I/O - System clock See tests/wasi/src/main/java/wasi/Test.java and tests/wasi/test.sh for examples. Not yet implemented: - Networking (i.e. sockets) - Environment variables - System random numbers - Process exit, yield, etc. - [DWARF](https://dwarfstd.org/) debugging support - Better logging of uncaught exceptions Note that the current implementation is probably overly paranoid in that all pointer arguments passed to WASI functions are allocated by the aforementioned allocator rather than on the Java heap. I've done this because I'm not clear on when TeaVM guarantees that object address will not change. Thus I've assumed that they could change at any time whatsoever, which is probably not true. Also note that the filesystem implementation currently throws generic `IOException`s and `ErrnoException`s rather than those specified by the standard (e.g. `FileNotFoundException`). Additional work will be needed to throw the correct exception based on the `errno` value. The main goal of this PR is to start a discussion about WASI support in TeaVM and answer questions such as: - Is WASI support a reasonable goal for the TeaVM project? - If so, is the approach of this PR roughly correct, or are significant changes needed? - What other features are missing to make this useful? Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for 65d5328 - Browse repository at this point
Copy the full SHA 65d5328View commit details
Commits on Aug 8, 2022
-
allocate buffers for WASI calls from Java heap
My previous commit was based on the assumption that objects allocated on the Java heap could be moved by TeaVM at any time. It turns out TeaVM will not move objects which are referenced by stack variables, so we can use those instead of `malloc`ed buffers. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for 2f2159f - Browse repository at this point
Copy the full SHA 2f2159fView commit details -
remove
WASI
target type and generate WASI modules by defaultPer review feedback, this removes `TeaVMTargetType.WASI` and makes `TeaVMTargetType.WEBASSEMBLY` generate a WASI module unconditionally. Such modules won't run in a browser without a polyfill, which I plan to add in a later commit. Along the way, I noticed the `Console` intrinsics weren't working properly and fixed them. Finally, this adds a new `WasiRunStrategy` which runs the full TeaVM test suite using either Wasmtime or Wasmer. You can try it by running the following from the test directory: ``` mvn -e install \ -Dteavm.junit.js=false \ -Dteavm.junit.js.runner=none \ -Dteavm.junit.wasm=true \ -Dteavm.junit.wasm.runner=wasi-wasmer ``` Specify `-Dteavm.junit.wasm.runner=wasi-wasmtime` to use Wasmtime. Currently many of the tests are failing, but I haven't had a chance to investigate yet or compare the results to the same tests running in a browser using an unmodified TeaVM. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for 69394e1 - Browse repository at this point
Copy the full SHA 69394e1View commit details
Commits on Aug 9, 2022
-
add tests and fix bugs related to filesystem failure cases
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for 1a0f2f4 - Browse repository at this point
Copy the full SHA 1a0f2f4View commit details -
add support for WASI environmont variables
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for 35b56d4 - Browse repository at this point
Copy the full SHA 35b56d4View commit details -
reimplement imported functions for Wasm target
Previously, TeaVM used imported functions for timezone resolution, char case conversion, and floating point tests. Since WASI doesn't support any of those things, we implement them in Java as best we can. Floating point tests are easy; timezone resolution will have to wait for WebAssembly/WASI#467 (we hard-code UTC for now); case conversion can be done entirely in Java, although I've only handled ASCII characters in this commit. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for 17bc74b - Browse repository at this point
Copy the full SHA 17bc74bView commit details
Commits on Aug 10, 2022
-
implement WASI-based random number generation
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for 9cdc13b - Browse repository at this point
Copy the full SHA 9cdc13bView commit details -
add timeout to
WasiRunStrategy
One of the tests had been running for 90 minutes when I gave up on it. Now we time out any tests that takes longer than 5 minutes. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for 49b9330 - Browse repository at this point
Copy the full SHA 49b9330View commit details -
handle "/" preopened directory if present
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for c6fef38 - Browse repository at this point
Copy the full SHA c6fef38View commit details -
revert earlier stub implementations
A previous commit provided stub implementations of `getNativeOffset`, `toUpperCase`, and `toLowerCase`. This reverts that change and instead uses the JS versions in the browser. It won't work in a WASI runtime without providing the extra imports to the module, but there's currently no way to get the local timezone in WASI, and I'm not yet ready to take on a proper implementation of `toUpperCase` and `toLowerCase`. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for 6aff71c - Browse repository at this point
Copy the full SHA 6aff71cView commit details -
refactor WASI tests so they always use
_start
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for 71c29b6 - Browse repository at this point
Copy the full SHA 71c29b6View commit details -
update wasm-runtime.js to use a WASI shim
This uses https://github.com/bjorn3/browser_wasi_shim to emulate WASI features. Note that I had to change the API for TeaVM `main` since `browser_wasi_shim` requires that CLI arguments are known before the module is loaded. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for b3d2aeb - Browse repository at this point
Copy the full SHA b3d2aebView commit details
Commits on Aug 11, 2022
-
upgrade to latest browser_wasi_shim
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for d33f8d4 - Browse repository at this point
Copy the full SHA d33f8d4View commit details -
update browser_wasi_shim dep to use NPM-hosted package
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Configuration menu - View commit details
-
Copy full SHA for ecc35ba - Browse repository at this point
Copy the full SHA ecc35baView commit details