Files
scriptc/docs/content/docs/platforms.mdx
T
Chris Tate 8fbc1d9b77 Document the wasm32-wasi runtime pack and fix the SC3003 hint
The WebAssembly and platform docs now say that wasm32-wasi builds need
zig and the @scriptc/runtime-wasm32-wasi package where the target is
introduced. A missing cross-target runtime pack still reports SC3003
with the package name and version; its hint now says that scriptc
includes the runtime pack for its own platform only, instead of
suggesting a reinstall with optional dependencies.

Fixes #717
Co-authored-by: guest271314 <4174848+guest271314@users.noreply.github.com>
2026-10-17 16:39:20 -05:00

161 lines
8.3 KiB
Plaintext

---
title: "Platform Support"
---
By default, `scriptc build` produces an executable for the machine you are building on. To build for another operating system, another architecture, or WebAssembly, set `SCRIPTC_TARGET` to the target you want. This page lists the supported platforms and shows how to cross-compile for each one.
<span id="owned-llvm-targets" />
## Supported platforms
The compiler runs on:
- macOS 15 or later on arm64 and x64.
- Linux on arm64 and x64, with glibc 2.34 or later or with musl.
- Windows on x64.
It can build:
- Executables for macOS (arm64, x64; macOS 14.0 minimum), Linux (arm64, x64; glibc or musl), and Windows (x64).
- WebAssembly modules for WASI Preview 1.
- Static libraries for iOS and Android apps, in [library mode](#ios-and-android-arm64-library-mode).
Building an executable needs a linker and the platform's SDK or system libraries: clang from the Xcode Command Line Tools on macOS, clang on glibc-based Linux, and [zig](https://ziglang.org) on Windows, on musl-based Linux, and for WASI, Android, and cross-compiled targets. Set `SCRIPTC_LINKER` to use a different linker driver. Assembly and object output (`--emit=asm` or `--emit=obj`) need no external tools.
<span id="cross-compilation-via-zig" />
## Cross-compile
The installed compiler can build for its own platform out of the box. To build for another target:
1. Install [zig](https://ziglang.org), which scriptc uses to link executables for other targets.
2. Add the target's runtime pack to your project, at the same version as `scriptc --version`. Runtime packs are named `@scriptc/runtime-<target>`, for example `@scriptc/runtime-linux-arm64-gnu` or `@scriptc/runtime-wasm32-wasi`.
3. Run `scriptc build` from your project with `SCRIPTC_TARGET` set to the target triple.
```console
$ npm install --save-dev @scriptc/runtime-linux-arm64-gnu@0.3.0
$ SCRIPTC_TARGET=aarch64-linux-gnu.2.36 scriptc build fib.ts -o fib-linux >/dev/null
```
You can also point `SCRIPTC_RUNTIME_PACK` at a runtime pack directory, which is useful with the standalone compiler archives. Adding a pack doesn't require reinstalling the compiler.
### Linux (arm64, x86_64)
GNU/Linux triples can name the minimum glibc version, `2.34` (the default) or `2.36`:
```console
$ SCRIPTC_TARGET=aarch64-linux-gnu.2.36 scriptc build fib.ts -o fib-linux
$ file fib-linux
fib-linux: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 2.0.0, with debug_info, not stripped
```
`x86_64-linux-gnu.2.36` works the same way. For Alpine and other musl-based systems, use `aarch64-linux-musl` or `x86_64-linux-musl`; these produce statically linked executables.
Linux executables use the native Linux implementations of the event loop (epoll), servers, TLS (with the system's CA bundle), and `fs.watch`, and they are tested against Node.js on Linux, including Alpine.
### Windows (x86_64)
```console
$ SCRIPTC_TARGET=x86_64-windows-gnu scriptc build fib.ts -o fib.exe
$ file fib.exe
fib.exe: PE32+ executable (console) x86-64, for MS Windows
```
Windows executables support `child_process`, `net`, `http`, `https`, `tls`, `http2`, `dgram`, `dns`, and `fetch`, and they are tested against Node.js on Windows.
Executables open a console window by default. For an application that shows its own window, build with `--windows-subsystem=gui` so Windows doesn't open an extra console.
<span id="webassembly-wasi-preview-1" />
### WebAssembly (WASI)
WASI is a cross-compile target, so it needs [zig](https://ziglang.org) and the `@scriptc/runtime-wasm32-wasi` runtime pack, as described in [Cross-compile](#cross-compilation-via-zig). Install the runtime pack in your project at the same version as `scriptc --version`. Without it, the build fails with `SC3003`.
Set `SCRIPTC_TARGET=wasm32-wasi` to build a standalone `.wasm` module:
```console
$ npm install --save-dev @scriptc/runtime-wasm32-wasi@0.3.5
$ SCRIPTC_TARGET=wasm32-wasi scriptc build hello.ts >/dev/null
$ SCRIPTC_TARGET=wasm32-wasi scriptc run hello.ts
hello, world
```
Without `-o`, the module is written to `.scriptc/hello.wasm`. `scriptc run` runs it with Node.js's WASI implementation, so it needs Node.js 24 or later on your `PATH`. It passes through stdio and environment variables, makes the current directory available as `/`, and maps the host's temporary directory to `/tmp`. You can run a built module in any other WASI Preview 1 runtime too.
WASI modules support the same language features as native executables, including async functions, promises, generators, timers, stdin and readline, and filesystem callbacks and promises. WASI Preview 1 has no sockets, process spawning, signals, network interfaces, or file watching, so networking and `fetch`, child processes, signal APIs, `os.networkInterfaces()`, the `os` host facts without a WASI equivalent (`cpus()`, `hostname()`, `freemem()`, `loadavg()`, `uptime()`, `getPriority()`), and `fs.watch` fail the build with `SC3002`. `--sanitize` and native FFI aren't available for WASI.
To build a module that a web or native application calls into, see [WebAssembly Modules](/docs/wasm).
<span id="ios-and-android-arm64-library-mode" />
### iOS and Android (arm64)
On mobile, the app is the executable, so scriptc builds a static library that the app links. Use library mode with one of these targets:
<dl>
<dt><code>SCRIPTC_TARGET=aarch64-apple-ios</code></dt>
<dd>iOS devices. Requires a macOS host. Minimum iOS 15.0.</dd>
<dt><code>SCRIPTC_TARGET=aarch64-apple-ios-simulator</code></dt>
<dd>The iOS simulator on Apple silicon. Requires a macOS host. Minimum iOS 15.0.</dd>
<dt><code>SCRIPTC_TARGET=aarch64-linux-android</code></dt>
<dd>Android devices, built against API level 26; the app's <code>minSdkVersion</code> must be 26 or higher. Builds from any supported host with zig.</dd>
</dl>
```console
$ SCRIPTC_TARGET=aarch64-apple-ios scriptc build --lib --profile app.profile.json
$ SCRIPTC_TARGET=aarch64-linux-android scriptc build --lib --profile app.profile.json
```
The library profile declares the exported functions, the host callbacks the library can call, and options such as running several independent instances in one app (`abi.localize_runtime`) or one instance per thread (`abi.instance_per_thread`). Xcode or the Android NDK performs the final link against the platform SDK. Building these targets without `--lib` fails with `SC3002`, and library builds don't support async functions, promises, or timers.
## Cross-target limits
- `--sanitize` is available only when building for the host platform.
- Native FFI inputs (objects and archives) must already be built for the target; scriptc doesn't translate them.
- iOS targets build only on macOS hosts.
- WASI builds can't use APIs that need capabilities WASI Preview 1 lacks, as described above.
## Summary
<table>
<thead>
<tr>
<th>Platform</th>
<th>How to build</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>macOS arm64 / x64</td>
<td>Build on a Mac</td>
<td>Needs the Xcode Command Line Tools. Supports <code>--sanitize</code>.</td>
</tr>
<tr>
<td>Linux arm64 / x86_64</td>
<td>Build on Linux, or <code>SCRIPTC_TARGET=&lt;arch&gt;-linux-gnu</code> or <code>&lt;arch&gt;-linux-musl</code></td>
<td>Servers, TLS, <code>fetch</code>, <code>fs.watch</code>, and <code>child_process</code>. musl builds are statically linked.</td>
</tr>
<tr>
<td>Windows x86_64</td>
<td>Build on Windows, or <code>SCRIPTC_TARGET=x86_64-windows-gnu</code></td>
<td>Servers, TLS, <code>fetch</code>, and <code>child_process</code>. Links with zig's Windows sysroot.</td>
</tr>
<tr>
<td>iOS arm64 (device and simulator)</td>
<td><code>SCRIPTC_TARGET=aarch64-apple-ios</code> or <code>aarch64-apple-ios-simulator</code> on macOS</td>
<td>Library mode only. Static libraries for Xcode projects, iOS 15.0 minimum.</td>
</tr>
<tr>
<td>Android arm64</td>
<td><code>SCRIPTC_TARGET=aarch64-linux-android</code> with zig</td>
<td>Library mode only. Static libraries for Gradle and NDK projects, API level 26 minimum.</td>
</tr>
<tr>
<td>WebAssembly (WASI Preview 1)</td>
<td><code>SCRIPTC_TARGET=wasm32-wasi</code></td>
<td>Full language support. APIs that need sockets, processes, signals, or file watching are unavailable.</td>
</tr>
</tbody>
</table>