Files
scriptc/packages/llvm-darwin-arm64/scripts/build.mjs
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

49 lines
2.0 KiB
JavaScript

#!/usr/bin/env node
import { execFileSync } from "node:child_process";
import { chmodSync, copyFileSync, mkdirSync, readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const packageRoot = fileURLToPath(new URL("..", import.meta.url));
const repoRoot = fileURLToPath(new URL("../../..", import.meta.url));
if (process.platform !== "darwin" || process.arch !== "arm64") {
process.stdout.write("@scriptc/llvm-darwin-arm64: skipped on this host\n");
process.exit(0);
}
const manifest = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
const buildDir = join(repoRoot, "node_modules/.cache/scriptc-llvm-darwin-arm64");
const llvmDir = process.env.LLVM_DIR ?? "/opt/homebrew/opt/llvm@22/lib/cmake/llvm";
execFileSync("cmake", [
"-S", join(repoRoot, "native/llvm-codegen"),
"-B", buildDir,
"-G", "Ninja",
`-DLLVM_DIR=${llvmDir}`,
`-DSCRIPTC_PACKAGE_VERSION=${manifest.version}`,
"-DSCRIPTC_TARGET_BACKENDS=AArch64;WebAssembly",
"-DSCRIPTC_ALLOWED_TARGETS=arm64-apple-macosx14.0.0,wasm32-unknown-wasi",
"-DCMAKE_BUILD_TYPE=Release",
], { stdio: "inherit" });
execFileSync("cmake", ["--build", buildDir, "--target", "scriptc-llvm-codegen"], {
stdio: "inherit",
});
const binDir = join(packageRoot, "bin");
mkdirSync(binDir, { recursive: true });
const output = join(binDir, "scriptc-llvm-codegen");
copyFileSync(join(buildDir, "scriptc-llvm-codegen"), output);
execFileSync("strip", ["-x", output], { stdio: "inherit" });
chmodSync(output, 0o755);
const version = JSON.parse(execFileSync(output, ["version", "--format=json"], {
encoding: "utf8",
}));
if (
version.protocol_version !== "1" ||
version.scriptc_package_version !== manifest.version ||
version.llvm_version !== "22.1.8" ||
!Array.isArray(version.supported_targets) ||
!version.supported_targets.includes("arm64-apple-macosx14.0.0")
) {
throw new Error(`built helper reported an incompatible identity: ${JSON.stringify(version)}`);
}