Skip to content
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

Added webassembly build test using javy and wasmtime #296

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
continue-on-error: true

- name: Run Prettiers
run: npx prettier --tab-width 4 --print-width 100 --trailing-comma es5 --ignore-path "$(CURDIR)/node_modules/*" --write JS/
run: npx prettier --tab-width 4 --print-width 100 --trailing-comma es5 --ignore-path "$(CURDIR)/.prettierignore" --write JS/
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
Expand Down
101 changes: 101 additions & 0 deletions .github/workflows/webassembly-pr-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Webassembly PR Build

on:
pull_request_target:
types:
- opened
- reopened
- synchronize
paths:
- 'JS/wasm/**'

jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
wasm: ${{ steps.filter.outputs.wasm }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
wasm:
- 'JS/wasm/**'

wasm:
needs: changes
if: ${{ needs.changes.outputs.wasm == 'true' }}
permissions:
contents: write
pull-requests: write

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Cache wasmjs-engine
uses: actions/cache@v2
with:
path: ./JS/wasm/crates/wasmjs-engine/target
key: wasmjs-engine
restore-keys: |
wasmjs-engine

- name: Check if wasmjs-engine is cached
id: wasmjs-engine-hit
run: |
echo "cache-hit=$(test -d ./JS/wasm/crates/wasmjs-engine/target && echo true || echo false)" >> $GITHUB_OUTPUT

- name: Build wasmjs-engine
if: steps.wasmjs-engine-hit.outputs.cache-hit != 'true'
working-directory: ./JS/wasm/crates/wasmjs-engine
run: |
npm install -g @go-task/cli
task build

- name: Cache wasmjs-runtime
uses: actions/cache@v2
with:
path: ./JS/wasm/crates/wasmjs-runtime/target
key: wasmjs-runtime
restore-keys: |
wasmjs-runtime

- name: Check if wasmjs-runtime is cached
id: wasmjs-runtime-hit
run: |
echo "cache-hit=$(test -d ./JS/wasm/crates/wasmjs-runtime/target && echo true || echo false)" >> $GITHUB_OUTPUT

- name: Build wasmjs-runtime
if: steps.wasmjs-runtime-hit.outputs.cache-hit != 'true'
working-directory: ./JS/wasm/crates/wasmjs-runtime
run: |
cargo build --release

- name: Build ec-wasmjs-hono
working-directory: ./JS/wasm/examples/ec-wasmjs-hono
run: |
npm install
npm run build

- name: Run ec-wasmjs-hono
working-directory: ./JS/wasm/crates/wasmjs-runtime
run: |
./target/release/wasmjs-runtime run ../../examples/ec-wasmjs-hono/bin
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/node_modules
JS/wasm/*
29 changes: 29 additions & 0 deletions JS/wasm/assets/wasmjs/wit/arakoo-geo.witx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(typename $arakoo_status
(enum (@witx tag u32)
$ok
$error
$inval
$badf
$buflen
$unsupported
$badalign
$httpinvalid
$httpuser
$httpincomplete
$none
$httpheadtoolarge
$httpinvalidstatus
$limitexceeded
$again
))

(module $arakoo_geo
(@interface func (export "lookup")
(param $addr_octets (@witx const_pointer (@witx char8)))
(param $addr_len (@witx usize))
(param $buf (@witx pointer (@witx char8)))
(param $buf_len (@witx usize))
(param $nwritten_out (@witx pointer (@witx usize)))
(result $err (expected (error $arakoo_status)))
)
)
41 changes: 41 additions & 0 deletions JS/wasm/assets/wasmjs/wit/http-types.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
type uri = string
type http-status = u16
type http-header = tuple<string, string>
type http-headers = list<http-header>
enum http-method {
get,
post,
put,
patch,
delete,
options,
head
}
type http-param = tuple<string, string>
type http-params = list<http-param>
type http-body = list<u8>
record http-request {
body: option<http-body>,
headers: http-headers,
method: http-method,
params: http-params,
uri: uri,
}
record http-request-error {
error: http-error,
message: string
}
record http-response {
body: option<http-body>,
headers: http-headers,
status: http-status,
}
enum http-error {
invalid-request,
invalid-request-body,
invalid-response-body,
not-allowed,
internal-error,
timeout,
redirect-loop,
}
2 changes: 2 additions & 0 deletions JS/wasm/assets/wasmjs/wit/http.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use * from http-types
send-http-request: func(request: http-request) -> expected<http-response, http-request-error>
2 changes: 2 additions & 0 deletions JS/wasm/crates/wasmjs-engine/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
**/node_modules/
Loading
Loading