Skip to content

Commit

Permalink
feat: WebIDL support & browser test suite (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Jul 17, 2024
1 parent e0919a1 commit 7f1f11e
Show file tree
Hide file tree
Showing 28 changed files with 2,749 additions and 205 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- os: macos-latest
node: 18.x
- os: windows-latest
node: 20.x
node: latest
- os: windows-latest
node: 18.x
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
run: cargo install wasm-tools
- name: Generate WASI Tests
if: steps.cache-wasi-tests.outputs.cache-hit != 'true'
run: cargo xtask generate tests
run: cargo xtask generate preview2-tests
- name: Upload Generated WASI Tests
uses: actions/upload-artifact@v4
with:
Expand Down
139 changes: 112 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ strip = true
[workspace.dependencies]
anyhow = "1.0.86"
base64 = "0.22.1"
heck = "0.5.0"
heck = "0.5.0"
js-component-bindgen = { path = "./crates/js-component-bindgen" }
structopt = "0.3.26"
wasm-encoder = "0.209.1"
wasm-metadata = "0.209.1"
wasmparser = "0.209.1"
wasmprinter = "0.209.1"
wasmtime-environ = { version = "22.0.0", features = ["component-model", "compile"] }
wasmtime-environ = { version = "22.0.0", features = [
"component-model",
"compile",
] }
wat = "1.209.1"
wit-bindgen = "0.26.0"
wit-bindgen-core = "0.26.0"
Expand All @@ -53,4 +56,3 @@ xshell = "0.2.6"

[dev-dependencies]
anyhow = { workspace = true }
xshell = { workspace = true }
40 changes: 3 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Jco can be used as either a library import or as a CLI via the `jco` command.

## Example

See the [example workflow](docs/src/example.md) page for a full usage example.
See the [Example Workflow](https://bytecodealliance.github.io/jco/example.html) page for a full usage example.

## CLI

Expand Down Expand Up @@ -77,41 +77,7 @@ For help with individual command options, use `jco <cmd> --help`.

### Transpile

To transpile a component into JS:

```
jco transpile component.wasm -o out-dir
```

The resultant file can be imported providing the bindings of the component as if it were imported directly:

app.js
```
import { fn } from './out-dir/component.js';
fn();
```

Imports can be remapped using the `--map` flag, or to provide imports as an argument use the `--instantiation` option.

Components relying on WASI bindings will contain external WASI imports, which are automatically updated
to the `@bytecodealliance/preview2-shim` package. This package can be installed from npm separately for
runtime usage. This shim layer supports both Node.js and browsers.

Options include:
* `--name`: Give a custom name for the component JS file in `out-dir/[name].js`
* `--minify`: Minify the component JS
* `--optimize`: Runs the internal core Wasm files through Binaryen for optimization. Optimization options can be passed with a `-- <binaryen options>` flag separator.
* `--tla-compat`: Instead of relying on top-level-await, requires an `$init` promise to be imported and awaited first.
* `--js`: Converts core Wasm files to JavaScript for environments that don't even support core Wasm.
* `--base64-cutoff=<number>`: Sets the maximum number of bytes for inlining Wasm files into the JS using base64 encoding. Set to zero to disable base64 inlining entirely.
* `--no-wasi-shim`: Disable the WASI shim mapping to `@bytecodealliance/preview2-shim`.
* `--map`: Provide custom mappings for world imports. Supports both wildcard mappings (`*` similarly as in the package.json "exports" field) as well as `#` mappings for targetting exported interfaces. For example, the WASI mappings are internally defined with mappings like `--map wasi:filesystem/*=@bytecodealliance/preview2-shim/filesystem#*` to map `import as * filesystem from 'wasi:filesystem/types'` to `import { types } from '@bytecodealliance/preview2-shim/filesystem`.
* `--no-nodejs-compat`: Disables Node.js compat in the output to load core Wasm with FS methods.
* `--instantiation [mode]`: Instead of a direct ES module, export an `instantiate` function which can take the imports as an argument instead of implicit imports. The `instantiate` function can be async (with `--instantiation` or `--instantiation async`), or sync (with `--instantiation sync`).
* `--valid-lifting-optimization`: Internal validations are removed assuming that core Wasm binaries are valid components, providing a minor output size saving.
* `--tracing`: Emit tracing calls for all function entry and exits.
* `--no-namespaced-exports`: Removes exports of the type `test as "test:flavorful/test"` which are not compatible with typescript
See the [Transpiling Docs](https://bytecodealliance.github.io/jco/transpiling.html) for more background and info.

#### Bindgen Crate

Expand Down Expand Up @@ -191,7 +157,7 @@ Add new producer metadata to a component or core Wasm binary.

## Contributing

See the [Contributing](docs/src/contributing.md) chapter of the Jco book.
See the [Contributing](https://bytecodealliance.github.io/jco/contributing.html) chapter of the Jco book.

# License

Expand Down
Loading

0 comments on commit 7f1f11e

Please sign in to comment.