mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-22 05:59:31 +08:00
* feat: support wasm32-wasi as a production target - Add production LLVM WASI codegen with a 32-bit ABI, coroutines, and dynamic modules - Integrate WASI builds and execution into the CLI with capability diagnostics - Add differential coverage and document the fourth production target Co-authored-by: Albert <57402359+bulatovv@users.noreply.github.com> * fix: address wasm target review findings * fix WASI guest paths and fetch alias detection * fix WASI async bridge and fetch detection --------- Co-authored-by: Albert <57402359+bulatovv@users.noreply.github.com>
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { join, resolve } from "node:path";
|
|
import { buildTargetPlatform } from "@scriptc/compiler";
|
|
import { expect, test } from "vitest";
|
|
import { defaultExecutableName, wasiEnvironment, wasiPreopens } from "../src/paths.js";
|
|
|
|
test("default executable names use the Windows PE suffix", () => {
|
|
expect(defaultExecutableName("main", "win32")).toBe("main.exe");
|
|
expect(defaultExecutableName("main", "linux")).toBe("main");
|
|
expect(defaultExecutableName("main", "darwin")).toBe("main");
|
|
expect(defaultExecutableName("main", "wasi")).toBe("main.wasm");
|
|
});
|
|
|
|
test("WASI cross-builds use the WebAssembly suffix", () => {
|
|
const platform = buildTargetPlatform({
|
|
SCRIPTC_CC: "zigcc",
|
|
SCRIPTC_TARGET: "wasm32-wasi",
|
|
});
|
|
expect(platform).toBe("wasi");
|
|
expect(defaultExecutableName("main", platform)).toBe("main.wasm");
|
|
});
|
|
|
|
test("WASI preopens map guest /tmp to the host platform temp directory", () => {
|
|
expect(wasiPreopens("C:\\work\\repo", "C:\\Users\\runner\\AppData\\Local\\Temp")).toEqual({
|
|
"/": "C:\\work\\repo",
|
|
"/tmp": "C:\\Users\\runner\\AppData\\Local\\Temp",
|
|
});
|
|
});
|
|
|
|
test("WASI environment paths name guest-visible capabilities", () => {
|
|
const cwd = resolve("work/repo");
|
|
const hostTmp = resolve("host/tmp");
|
|
const outside = resolve("elsewhere");
|
|
|
|
expect(wasiEnvironment({
|
|
KEEP: "yes",
|
|
PWD: cwd,
|
|
HOME: outside,
|
|
TMPDIR: hostTmp,
|
|
TMP: hostTmp,
|
|
TEMP: hostTmp,
|
|
USERPROFILE: outside,
|
|
OLDPWD: outside,
|
|
INIT_CWD: join(cwd, "package"),
|
|
}, cwd, hostTmp)).toEqual({
|
|
KEEP: "yes",
|
|
PWD: "/",
|
|
HOME: "/",
|
|
TMPDIR: "/tmp",
|
|
TMP: "/tmp",
|
|
TEMP: "/tmp",
|
|
USERPROFILE: "/",
|
|
INIT_CWD: "/package",
|
|
});
|
|
});
|
|
|
|
test("Windows cross-builds use the PE suffix on a non-Windows host", () => {
|
|
const platform = buildTargetPlatform({
|
|
SCRIPTC_CC: "zigcc",
|
|
SCRIPTC_TARGET: "x86_64-windows-gnu",
|
|
});
|
|
expect(platform).toBe("win32");
|
|
expect(defaultExecutableName("main", platform)).toBe("main.exe");
|
|
});
|