Skip to content

Commit 92861f1

Browse files
authored
proof-of-concept playground (#1597)
* proof-of-concept playground * make playground part of the workspace * do not use the workspace lints * print * add redirect * color printing * checkbox for printing skeletons * cross-link, also make parse errors red * allow CI to run * I guess we cannot avoid committing this generated file
1 parent 8dc6ddf commit 92861f1

21 files changed

Lines changed: 1817 additions & 0 deletions

.github/workflows/playground.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build playground
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
merge_group:
7+
8+
# Cancel any in-flight jobs for the same PR/branch so there's only one active
9+
# at a time
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
defaults:
15+
run:
16+
shell: bash
17+
18+
jobs:
19+
build:
20+
name: Build
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
with:
25+
submodules: true
26+
- uses: actions/setup-node@v4
27+
with:
28+
node-version: 20
29+
- uses: bytecodealliance/wasmtime/.github/actions/install-rust@v20.0.0
30+
- uses: cargo-bins/cargo-binstall@v1.6.9
31+
- run: cargo binstall cargo-component -y
32+
- run: rustup component add rustfmt # needed for cargo-component, apparently?
33+
- run: npm ci
34+
working-directory: playground
35+
- run: npm run build
36+
working-directory: playground
37+
38+
# also prepare to deploy GH pages on main
39+
- if: github.ref == 'refs/heads/main'
40+
uses: actions/configure-pages@v5
41+
- if: github.ref == 'refs/heads/main'
42+
uses: actions/upload-pages-artifact@v3
43+
with:
44+
path: "./playground/dist"
45+
46+
deploy:
47+
name: Deploy
48+
if: github.ref == 'refs/heads/main'
49+
needs: build
50+
permissions:
51+
pages: write
52+
id-token: write
53+
runs-on: ubuntu-latest
54+
environment:
55+
name: github-pages
56+
url: ${{ steps.deployment.outputs.page_url }}
57+
steps:
58+
- id: deployment
59+
uses: actions/deploy-pages@v4

Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ members = [
3939
'fuzz',
4040
'crates/wit-parser/fuzz',
4141
'crates/wit-component/dl',
42+
'playground/component',
4243
]
4344

4445
[workspace.lints.rust]

playground/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
component-built/
3+
dist/

playground/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Playground
2+
3+
This is a simple online playground for `wasm-tools parse`, available at https://bytecodealliance.gthub.io/wasm-tools/.
4+
5+
## Building
6+
7+
In addition to `cargo`, you'll need to have `node` and [`cargo-component`](https://github.com/bytecodealliance/cargo-Component) installed and on your path.
8+
9+
Then
10+
11+
```sh
12+
npm ci
13+
```
14+
to install dependencies and
15+
```sh
16+
npm run build
17+
```
18+
to build.
19+
20+
Output will be placed under `dist`.
21+
22+
## Making changes
23+
24+
The [./component/wit/world.wit](./component/wit/world.wit) file defines the exported functions for use by the playground. After changing it you'll need to `npm run build` to regenerate the bindings file (the command will fail but still generate the bindings) and then implement the functions in [./component/src/lib.rs](./component/src/lib.rs).
25+
26+
After `npm run build`ing again you can make use of those functions from [./src/worker.ts](./src/worker.ts), with full type safety (thanks to [`jco`](https://github.com/bytecodealliance/jco)).
27+
28+
It is also possible to use them outside of a worker, but since they run synchronously and block their thread the playground is designed to do all calls off the main thread.
29+
30+
To preview your changes after building you'll need to run a web server; the worker will not load from a `file:` URL. The simplest way to do this is by running `npx http-server dist`, but you can use whatever means you'd like.

playground/component/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/

playground/component/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "component"
3+
publish = false
4+
edition.workspace = true
5+
6+
[dependencies]
7+
wit-bindgen-rt = { version = "0.26.0", features = ["bitflags"] }
8+
wat = { workspace = true }
9+
wasmprinter = { workspace = true }
10+
11+
[lib]
12+
crate-type = ["cdylib"]
13+
14+
[profile.release]
15+
codegen-units = 1
16+
opt-level = "s"
17+
debug = false
18+
strip = true
19+
lto = true
20+
21+
[package.metadata.component]
22+
package = "component:component"
23+
24+
[package.metadata.component.dependencies]

0 commit comments

Comments
 (0)