Skip to content

Commit f86be01

Browse files
committed
test: make golang check into a bundle
1 parent e5f4a78 commit f86be01

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

test/wasi/golang/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
golangcheck.wasm
1+
golangcheck.wasm
2+
golangcheck.tgz

test/wasi/golang/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11

2-
build:
3-
GOOS=wasip1 GOARCH=wasm go build -o golangcheck.wasm .
2+
build: golangcheck.tgz
43
.PHONY: build
54

5+
golangcheck.tgz: golangcheck.wasm init.js
6+
tar -czf golangcheck.tgz golangcheck.wasm init.js
7+
8+
golangcheck.wasm: main.go
9+
GOOS=wasip1 GOARCH=wasm go build -o golangcheck.wasm .
10+
611
clean:
712
rm -f golangcheck.wasm
13+
rm -f golangcheck.tgz
814
.PHONY: clean

test/wasi/golang/init.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(async () => {
2+
// convert \n to \r\n since we have no line discipline in this setup
3+
const transform = new TransformStream({
4+
transform(chunk, controller) {
5+
const text = new TextDecoder().decode(chunk);
6+
const converted = text.replace(/\n/g, '\r\n');
7+
controller.enqueue(new TextEncoder().encode(converted));
8+
}
9+
});
10+
11+
console.log("running golang init.js");
12+
const w = window.wanix.instance;
13+
const tid = (await w.readText("task/new/wasi")).trim();
14+
await w.writeFile(`task/${tid}/cmd`, "#bundle/golangcheck.wasm");
15+
const stdout = await w.openReadable(`task/${tid}/fd/1`);
16+
const cons = await w.openWritable(`#console/data1`);
17+
await w.writeFile(`task/${tid}/ctl`, "start");
18+
stdout.pipeThrough(transform).pipeTo(cons);
19+
})();

0 commit comments

Comments
 (0)