Files
scriptc/packages/cli/test/wasi-runtime-pack.test.ts
T
Chris Tate c41f1a8be9 Expand LLVM native output targets (#280)
* Expand LLVM native output targets

- Add owned helper and runtime-pack contracts for macOS x64, Linux glibc/musl, Windows x64, and WASI.
- Generalize LLVM target selection, package validation, linker plans, and release/CI matrices.
- Document linker boundaries and add focused native-output and runtime-pack coverage.

* Pin Windows LLVM helper CI to VS 2022

The official LLVM archive needs the Visual Studio 2022 CMake generator, which is not guaranteed by windows-latest.

* Align bootstrap cache with LLVM runtime-pack builds

Use the same target-specific helper and linker identity before and after compiler loading so routed executable cache hits remain lightweight.

* Install Windows LLVM CI tools with Chocolatey

windows-2022 includes Visual Studio but not winget; use its available Chocolatey bootstrap for CMake and Ninja.

* Prevent Zig version probes from leaving runtime-pack objects

Run runtime-pack compiler version probes in a private temporary directory and remove the accidental tracked WASI a.o file.

* Use 7-Zip for Windows LLVM setup

Extract the official LLVM development archive with two-stage 7-Zip instead of Windows tar.exe, which timed out while materializing the toolchain tree.

* Define ssize_t for the MSVC runtime pack

Clang's MSVC target does not expose POSIX ssize_t through sys/types.h; define the pointer-sized runtime type without affecting MinGW.

* Build the Windows runtime pack with Zig

Use the MinGW-compatible Windows sysroot required by the runtime while retaining COFF helper output and installing Zig in the Windows native CI lane.

* Give macOS LLVM differential shard time to finish

Shard 1 passed its setup and focused contracts but was cancelled during its cold LLVM differential slice at the 20-minute job limit.
2026-09-01 13:41:34 -05:00

45 lines
1.9 KiB
TypeScript

import { execFile } from "node:child_process";
import { existsSync } from "node:fs";
import { createRequire } from "node:module";
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { promisify } from "node:util";
import { afterEach, expect, test } from "vitest";
const execFileAsync = promisify(execFile);
const require = createRequire(import.meta.url);
const repoRoot = join(import.meta.dirname, "../../..");
const cliEntry = join(repoRoot, "packages/cli/src/main.ts");
const tsxLoader = join(dirname(require.resolve("tsx/package.json")), "dist/loader.mjs");
const helperPackage = require.resolve("@scriptc/llvm-darwin-arm64/package.json");
const helper = join(dirname(helperPackage), "bin", "scriptc-llvm-codegen");
const runtimePackage = require.resolve("@scriptc/runtime-wasm32-wasi/package.json");
const runtimeManifest = join(dirname(runtimePackage), "runtime-pack.json");
const supported = existsSync(helper) && existsSync(runtimeManifest);
const dirs: string[] = [];
afterEach(async () => {
await Promise.all(dirs.splice(0).map((path) => rm(path, { recursive: true, force: true })));
});
test.runIf(supported)("WASI helper object plus runtime pack builds and runs without SCRIPTC_CC", async () => {
const dir = await mkdtemp(join(tmpdir(), "scriptc-wasi-runtime-pack-"));
dirs.push(dir);
const output = join(dir, "hello.wasm");
const zigCache = join(dir, "zig-cache");
await expect(execFileAsync(process.execPath, [
"--import", tsxLoader, cliEntry, "run", join(repoRoot, "tests/corpus/001-hello.ts"), "-o", output,
], {
env: {
...process.env,
SCRIPTC_TARGET: "wasm32-wasi",
SCRIPTC_NO_CACHE: "1",
SCRIPTC_LEGACY_C_PIPELINE: "0",
ZIG_GLOBAL_CACHE_DIR: join(zigCache, "global"),
ZIG_LOCAL_CACHE_DIR: join(zigCache, "local"),
},
encoding: "utf8",
})).resolves.toMatchObject({ stdout: "hello world\n" });
});