Home Docs Download About Contact
Download

Cross-platform compilation

One source, seven 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
wasmWeb
headlessServers, CI, embedded

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.

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_headless() { return 100_000 }
    return 1_024
}

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.