Platform blocks
Platform blocks
Code that only applies to some targets is gated by a platform or arch block.
The compiler includes the body only when building for a listed target and skips
it entirely otherwise, so a call to an API that exists on one platform does not
have to compile on the others.
platform macos {
// included only in a macOS build
}Several targets are listed with |:
platform macos | linux {
// included for both
}arch gates on the processor architecture the same way:
arch arm {
// included only for arm builds
}The recognized platform names are macos, windows, linux, ios, and
android. The architectures are arm and x86_64.
The excluded branch is not checked
A skipped body is not analyzed at all. Type errors, unresolved names, and bad
imports inside a platform windows { } block never surface on a macOS build;
they appear the first time you build for Windows.
So check each target you support:
peko test src/main.peko --os windows --arch x86_64
An unknown platform name is also not an error. It simply never matches, so a misspelling silently removes the code.
A demo { } block behaves differently: analysis tools do check it, so demo code
is type-checked in the editor even though a release build strips it.
demo blocks
A demo { ... } block is a related form of conditional compilation. Its body is
included only in a demo build and is stripped from a normal or release build.
It exists so fixtures and automation hooks can live beside the code they drive
without shipping in the real binary.
demo {
// present only in a demo build
}