Adam C. Foltzer 2fe353044f Improvements to WasiCtxBuilder, and a couple bug fixes (#175)
* fix Linux `isatty` implementation

* defer `WasiCtxBuilder` errors to `build()`; don't change API yet

This changes the fields on the builder to types that let the various `.arg()`, `.env()`, etc methods
infallible, so we don't have to worry about handling any errors till we actually build. This reduces
line noise when using a builder in a downstream application.

Deferring the processing of the builder fields also has the advantage of eliminating the opening and
closing of `/dev/null` for the default stdio file descriptors unless they're actually used by the
resulting `WasiCtx`.

Unicode errors when inheriting arguments and environment variables no longer cause a panic, but
instead go through `OsString`. We return `ENOTCAPABLE` at the end if there are NULs, or if UTF-8
conversion fails on Windows.

This also changes the bounds on some of the methods from `AsRef<str>` to `AsRef<[u8]>`. This
shouldn't break any existing code, but allows more flexibility when providing arguments. Depending
on the outcome of https://github.com/WebAssembly/WASI/issues/8 we may eventually want to require
these bytes be UTF-8, so we might want to revisit this later.

Finally, this fixes a tiny bug that could arise if we had exactly the maximum number of file
descriptors when populating the preopens.

* make `WasiCtxBuilder` method types less restrictive

This is a separate commit, since it changes the interface that downstream clients have to use, and
therefore requires a different commit of `wasmtime` for testing. That `wasmtime` commit is currently
on my private fork, so this will need to be amended before merging.

Now that failures are deferred until `WasiCtxBuilder::build()`, we don't need to have `Result` types
on the other methods any longer.

Additionally, using `IntoIterator` rather than `Iterator` as the trait bound for these methods is
slightly more general, and saves the client some typing.

* enforce that arguments and environment variables are valid UTF-8

* remove now-unnecessary platform-specific OsString handling

* `ENOTCAPABLE` -> `EILSEQ` for failed arg/env string conversions

* fix up comment style

* Apply @acfoltzer's fix to isatty on Linux to BSD
2019-11-07 11:50:47 +01:00
2019-10-22 15:27:21 +02:00
2019-11-05 14:56:18 -08:00
2019-11-05 15:13:13 -08:00
2019-09-06 20:38:50 -07:00
2019-11-05 14:56:18 -08:00
2019-11-07 11:23:52 +01:00
2019-10-25 11:52:18 +02:00

wasi-common

build-status rustc-1.37

This repo will ultimately serve as a library providing a common implementation of WASI hostcalls for re-use in any WASI (and potentially non-WASI) runtimes such as Wasmtime and Lucet.

The library is an adaption of lucet-wasi crate from the Lucet project, and it is currently based on 40ae1df git revision.

Please note that the library requires Rust compiler version at least 1.37.0.

Supported syscalls

*nix

In our *nix implementation, we currently support the entire WASI API with the exception of socket hostcalls:

  • sock_recv
  • sock_send
  • sock_shutdown

We expect these to be implemented when network access is standardised.

We also currently do not support the proc_raise hostcall, as it is expected to be dropped entirely from WASI.

Windows

In our Windows implementation, we currently support the minimal subset of WASI API which allows for running the very basic "Hello world!" style WASM apps. More coming shortly, so stay tuned!

Development hints

When testing the crate, you may want to enable and run full wasm32 integration testsuite. This requires wasm32-wasi target installed which can be done as follows using rustup

rustup target add wasm32-wasi

Next initiate submodules containing the integration testsuite

git submodule update --init

Now, you should be able to run the integration testsuite by enabling the wasm_tests feature

cargo test --features wasm_tests

Third-Party Code

Significant parts of our hostcall implementations are derived from the C implementations in cloudabi-utils. See LICENSE.cloudabi-utils for license information.

Description
No description provided
Readme 125 MiB
Languages
Rust 77.8%
WebAssembly 20.6%
C 1.3%