Home Docs Download About Contact
Download

Cross-platform compilation

One source, nine targets. Targets, conditionals and platform checks.

Guides Updated 2026-08-01 Edit this page

Prism’s default position: the same source compiles everywhere. This guide covers the mechanics — targets, platform checks, and the small set of tools for code that genuinely must differ.

Targets

A target names an OS and a CPU:

TargetPlatform
windows/x64Windows
linux/x64, linux/arm64Linux
macos/arm64, macos/x64macOS
ios/arm64iOS
android/arm64Android
freebsd/x64FreeBSD
openbsd/x64OpenBSD
netbsd/x64NetBSD
wasmWeb

Build any of them:

prism targets

prism targets lists every target this project can compile for, and the build command accepts the per-target flags shown there.

Note: headless (Cairo offscreen), GPU and TUI are render backends — they decide how a program draws, not where it runs. They are not platforms.

Platform checks

Platform checks are builtins — no module import needed:

fn main() {
    if is_windows() {
        println("windows")
    } else {
        println("other")
    }
}

The is_* builtins are available everywhere and compile to nothing — the conditions are evaluated at compile time and dead branches are removed.

Configuring per target

pub fn max_connections() -> int {
    if is_wasm() { return 1_024 }
    return 100_000
}

is_* checks are evaluated at compile time; the branch that isn’t compiled is removed entirely.

Keeping the main path clean

The rule of thumb: put platform code behind a small interface, and implement it per platform.

trait Notifier {
    fn notify(title: str, body: str);
}

impl Notifier for int {
    fn notify(title: str, body: str) {
        println(title)
        println(body)
    }
}

The main code path never branches on platform — it calls notify(). This keeps the interesting logic testable on any platform and the platform-specific code small enough to audit.

Testing everything

prism targets
prism test

prism targets lists every target your project can compile for, and prism test runs the suite. CI templates in prism init build and test each configured target, so cross-platform breakage shows up as a failed build, not a user report.

Note: UI targets require a windowing system to test interactively. Headless CI runs the logic tests everywhere and the visual suite on desktop targets only.