Skip to content

Commit 54ab085

Browse files
fix: do not skip wasi:http export processing (#218)
This commit removes the ignored handling of `wasi:http/incoming-handler` which breaks components that have manually implemented the `handle` export. Signed-off-by: Victor Adossi <[email protected]>
1 parent 196f214 commit 54ab085

File tree

7 files changed

+118
-33
lines changed

7 files changed

+118
-33
lines changed

.github/workflows/main.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches: [main]
66
pull_request:
77
branches: [main]
8+
89
defaults:
910
run:
1011
shell: bash
@@ -15,6 +16,7 @@ concurrency:
1516
group: ${{ github.workflow }}-${{ github.ref }}
1617
cancel-in-progress: true
1718

19+
1820
jobs:
1921
lint:
2022
runs-on: ubuntu-latest
@@ -33,7 +35,12 @@ jobs:
3335
#########
3436

3537
build-splicer:
36-
runs-on: ubuntu-latest
38+
runs-on: ${{ matrix.os }}
39+
strategy:
40+
matrix:
41+
os:
42+
- windows-latest
43+
- ubuntu-latest
3744
steps:
3845
- uses: actions/checkout@v4
3946

@@ -164,6 +171,15 @@ jobs:
164171
key: starlingmonkey-${{matrix.build-type}}-${{ steps.starlingmonkey-commit.outputs.STARLINGMONKEY_HASH }}
165172
path: lib
166173

174+
- name: Restore Embedding Splicer from cache
175+
uses: actions/cache/restore@v4
176+
id: splicer-build
177+
with:
178+
key: splicer-${{ hashFiles('Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
179+
path: |
180+
lib
181+
target
182+
167183
- uses: actions/setup-node@v4
168184
with:
169185
node-version: ${{matrix.node-version}}
@@ -192,6 +208,15 @@ jobs:
192208
key: starlingmonkey-release-${{ steps.starlingmonkey-commit.outputs.STARLINGMONKEY_HASH }}
193209
path: lib
194210

211+
- name: Restore Embedding Splicer from cache
212+
uses: actions/cache/restore@v4
213+
id: splicer-build
214+
with:
215+
key: splicer-${{ hashFiles('Cargo.lock', 'crates/spidermonkey-embedding-splicer/src/**/*.rs') }}
216+
path: |
217+
lib
218+
target
219+
195220
- uses: actions/setup-node@v4
196221
with:
197222
node-version: '23.10.0'
@@ -203,8 +228,8 @@ jobs:
203228
uses: actions/cache@v4
204229
with:
205230
path: 'examples/hello-world/host/target/release/wasmtime-test*'
206-
key: example-hello-world-cargo-${{ hashFiles('examples/hello-world/host/src/main.rs',
207-
'examples/hello-world/host/Cargo.lock',
231+
key: example-hello-world-cargo-${{ hashFiles('examples/hello-world/host/src/main.rs',
232+
'examples/hello-world/host/Cargo.lock',
208233
'examples/hello-world/guest/hello.wit') }}
209234

210235
- name: Test Example

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# WASM_OPT ?= $(shell rm node_modules/.bin/wasm-opt ; which wasm-opt)
2-
JCO ?= ./node_modules/.bin/jco
2+
JCO ?= npx jco
33
STARLINGMONKEY_SRC ?= StarlingMonkey
44

55
ifndef JCO

crates/spidermonkey-embedding-splicer/src/bindgen.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ impl JsBindgen<'_> {
398398
) -> Result<()> {
399399
for (key, export) in &self.resolve.worlds[self.world].exports {
400400
let name = self.resolve.name_world_key(key);
401-
if name.starts_with("wasi:http/[email protected].") {
402-
continue;
403-
}
404401
// Do not generate exports when the guest export is not implemented.
405402
// We check both the full interface name - "ns:pkg@v/my-interface" and the
406403
// aliased interface name "myInterface". All other names are always

test/cases/http-server/source.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {
2+
IncomingRequest,
3+
ResponseOutparam,
4+
OutgoingBody,
5+
OutgoingResponse,
6+
Fields,
7+
} from 'wasi:http/[email protected]';
8+
9+
export const incomingHandler = {
10+
handle(incomingRequest, responseOutparam) {
11+
const outgoingResponse = new OutgoingResponse(new Fields());
12+
let outgoingBody = outgoingResponse.body();
13+
{
14+
let outputStream = outgoingBody.write();
15+
outputStream.blockingWriteAndFlush(
16+
new Uint8Array(new TextEncoder().encode('Hello world!')),
17+
);
18+
outputStream[Symbol.dispose]();
19+
}
20+
outgoingResponse.setStatusCode(200);
21+
OutgoingBody.finish(outgoingBody, undefined);
22+
ResponseOutparam.set(outgoingResponse, {
23+
tag: 'ok',
24+
val: outgoingResponse,
25+
});
26+
},
27+
};

test/cases/http-server/test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { strictEqual } from 'node:assert';
2+
3+
import { HTTPServer } from '@bytecodealliance/preview2-shim/http';
4+
5+
import { getRandomPort } from '../../util.js';
6+
7+
export const enableFeatures = ['http'];
8+
export const worldName = 'test3';
9+
10+
export async function test(instance) {
11+
const server = new HTTPServer(instance.incomingHandler);
12+
let port = await getRandomPort();
13+
server.listen(port);
14+
15+
try {
16+
const resp = await fetch(`http://localhost:${port}`);
17+
const text = await resp.text();
18+
strictEqual(text, 'Hello world!');
19+
} finally {
20+
server.stop();
21+
}
22+
}

test/test.js

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -138,41 +138,48 @@ suite('Bindings', () => {
138138
test(name, async () => {
139139
const source = await readFile(
140140
new URL(`./cases/${name}/source.js`, import.meta.url),
141-
'utf8'
141+
'utf8',
142142
);
143143

144+
const test = await import(`./cases/${name}/test.js`);
145+
146+
// Determine the relevant WIT world to use
144147
let witWorld,
145148
witPath,
146149
worldName,
147150
isWasiTarget = false;
148-
try {
149-
witWorld = await readFile(
150-
new URL(`./cases/${name}/world.wit`, import.meta.url),
151-
'utf8'
152-
);
153-
} catch (e) {
154-
if (e?.code == 'ENOENT') {
155-
try {
156-
isWasiTarget = true;
157-
witPath = fileURLToPath(
158-
new URL(`./cases/${name}/wit`, import.meta.url)
159-
);
160-
await readdir(witPath);
161-
} catch (e) {
162-
if (e?.code === 'ENOENT') {
163-
witPath = fileURLToPath(new URL('./wit', import.meta.url));
164-
worldName = 'test2';
165-
} else {
166-
throw e;
151+
if (test.worldName) {
152+
witPath = fileURLToPath(new URL('./wit', import.meta.url));
153+
worldName = test.worldName;
154+
isWasiTarget = true;
155+
} else {
156+
try {
157+
witWorld = await readFile(
158+
new URL(`./cases/${name}/world.wit`, import.meta.url),
159+
'utf8',
160+
);
161+
} catch (e) {
162+
if (e?.code == 'ENOENT') {
163+
try {
164+
isWasiTarget = true;
165+
witPath = fileURLToPath(
166+
new URL(`./cases/${name}/wit`, import.meta.url),
167+
);
168+
await readdir(witPath);
169+
} catch (e) {
170+
if (e?.code === 'ENOENT') {
171+
witPath = fileURLToPath(new URL('./wit', import.meta.url));
172+
worldName = 'test2';
173+
} else {
174+
throw e;
175+
}
167176
}
177+
} else {
178+
throw e;
168179
}
169-
} else {
170-
throw e;
171180
}
172181
}
173182

174-
const test = await import(`./cases/${name}/test.js`);
175-
176183
const enableFeatures = test.enableFeatures || ['http'];
177184
const disableFeatures =
178185
test.disableFeatures ||
@@ -229,14 +236,14 @@ suite('Bindings', () => {
229236

230237
await writeFile(
231238
new URL(`./output/${name}.component.wasm`, import.meta.url),
232-
component
239+
component,
233240
);
234241

235242
for (const file of Object.keys(files)) {
236243
let source = files[file];
237244
await writeFile(
238245
new URL(`./output/${name}/${file}`, import.meta.url),
239-
source
246+
source,
240247
);
241248
}
242249

test/wit/test1.wit

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,10 @@ world test2 {
6464

6565
export get-result: func() -> string;
6666
}
67+
68+
world test3 {
69+
import wasi:cli/environment@0.2.3;
70+
import wasi:http/types@0.2.3;
71+
72+
export wasi:http/incoming-handler@0.2.3;
73+
}

0 commit comments

Comments
 (0)