Skip to content
Prismio docs
ImplementedPrismio 0.1.0

Platform

The std.platform module — the operating system, architecture and ABI environment a program is compiled for, as compile-time constants.

Last verified

Implemented. Available in the audited Prismio 0.1.0 compiler. Pre-1.0 syntax may still change.

import std.platform. Which platform a program is compiled for — answered by the compiler from the target triple, not asked of the machine while the program runs.

prismio
import std.io
import std.platform

fn main() -> Int {
    match (platform.current()) {
        Platform.Windows => { println("Windows") }
        Platform.Linux => { println("Linux") }
        Platform.MacOS => { println("macOS") }
        Platform.Unknown => { println("somewhere else") }
    }
    if (platform.architecture() == Architecture.ARM64) { println("ARM64") }
    return 0
}
CallReturns
platform.current()PlatformWindows, Linux, MacOS or Unknown
platform.isWindows()Bool — the same as platform.current() == Platform.Windows
platform.isLinux()Bool — the same as platform.current() == Platform.Linux
platform.isMacOS()Bool — the same as platform.current() == Platform.MacOS
platform.architecture()ArchitectureX86_64, ARM64 or Unknown
platform.environment()EnvironmentGNU, Musl, MSVC, MinGW or Unknown

platform is a global the module declares, of an empty struct type, PlatformQuery; the calls above are its methods.

The target, not the host

These are facts about the compile target. A native build targets the machine it runs on, so there the answer is that machine's too. A cross build answers for the target it names:

text
prismio build app.psm --target x86_64-pc-windows-msvc    # platform.current() is Platform.Windows

Every answer is a constant, so if (platform.isLinux()) { ... } else { ... } compiles to the one branch it takes. There is no run-time check and no call.

How a triple maps

Target triplePlatformArchitectureEnvironment
x86_64-pc-windows-msvcWindowsX86_64MSVC
x86_64-pc-windows-gnu, x86_64-w64-mingw32WindowsX86_64MinGW
x86_64-unknown-linux-gnuLinuxX86_64GNU
aarch64-unknown-linux-muslLinuxARM64Musl
aarch64-linux-androidLinuxARM64Unknown
arm64-apple-macosMacOSARM64Unknown
x86_64-apple-darwinMacOSX86_64Unknown
wasm32-unknown-unknownUnknownUnknownUnknown

A target outside these sets — iOS, FreeBSD, i686, riscv64 — answers Unknown for whatever it does not match, so a match over Platform should have a Platform.Unknown arm. Android reports Linux because its triple's operating system is Linux, and macOS has no ABI environment in its triple at all.