Skip to content
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/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
node-version: 22

- uses: mlugg/setup-zig@v2
- uses: mlugg/setup-zig@v2.0.5

- name: Install binaryen
run: |
Expand Down
13 changes: 12 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-ignore
import zigTarGz from "../zig-out/zig.tar.gz?inline";
import { untar } from "@andrewbranch/untar.js";
import { Directory, File } from "@bjorn3/browser_wasi_shim";
import { Directory, File, ConsoleStdout, wasi as wasi_defs } from "@bjorn3/browser_wasi_shim";

export async function getLatestZigArchive() {
const ds = new DecompressionStream("gzip");
Expand Down Expand Up @@ -43,3 +43,14 @@ function convert(node: TreeNode): Directory {
})
)
}

export function stderrOutput(): ConsoleStdout {
const dec = new TextDecoder("utf-8", { fatal: false });
const stderr = new ConsoleStdout((buffer) => {
postMessage({ stderr: dec.decode(buffer, { stream: true }) });
});
stderr.fd_pwrite = (data, offset) => {
return { ret: wasi_defs.ERRNO_SPIPE, nwritten: 0 };
}
return stderr;
}
10 changes: 2 additions & 8 deletions src/workers/runner.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// Runs compiled Zig code

import { WASI, PreopenDirectory, OpenFile, File, ConsoleStdout } from "@bjorn3/browser_wasi_shim";

function stderrOutput(): ConsoleStdout {
const dec = new TextDecoder("utf-8", { fatal: false });
return new ConsoleStdout((buffer) => {
postMessage({ stderr: dec.decode(buffer, { stream: true }) });
});
}
import { WASI, PreopenDirectory, OpenFile, File } from "@bjorn3/browser_wasi_shim";
import { stderrOutput } from "../utils";

async function run(wasmData: Uint8Array) {
let args = ["main.wasm"];
Expand Down
11 changes: 2 additions & 9 deletions src/workers/zig.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { WASI, PreopenDirectory, Fd, File, ConsoleStdout, OpenFile, Inode } from "@bjorn3/browser_wasi_shim";
import { getLatestZigArchive } from "../utils";
import { WASI, PreopenDirectory, Fd, File, OpenFile, Inode } from "@bjorn3/browser_wasi_shim";
import { getLatestZigArchive, stderrOutput } from "../utils";
// @ts-ignore
import zigWasm from "../../zig-out/bin/zig.wasm?url";

function stderrOutput(): ConsoleStdout {
const dec = new TextDecoder("utf-8", { fatal: false });
return new ConsoleStdout((buffer) => {
postMessage({ stderr: dec.decode(buffer, { stream: true }) });
});
}

let currentlyRunning = false;
async function run(source: string) {
if (currentlyRunning) return;
Expand Down