watchOS
Bern compiles the watchOS target (platform = "watchos") to a standalone Watch-Only SwiftUI application targeting watchOS 10 or newer. watchOS targets must be built on a Mac.
Prerequisites
- macOS host with Rust 1.99+ and Xcode 26 or newer (with the watchOS platform SDK and Apple Watch simulators installed).
- Add the Rust targets for the watchOS simulator and Apple Watch hardware:
# On Apple Silicon Macs (use x86_64-apple-watchos-sim on Intel Macs)
rustup target add aarch64-apple-watchos-sim aarch64-apple-watchos
bern doctorConfiguration in Bern.toml
[app]
id = "tasks"
bundle_id = "com.example.tasks"
version = "0.1.0"
name = "Tasks"
[targets.watchos]
platform = "watchos"
ui = "swiftui"Mandatory watch layout (B401)
Because watch screens are tiny and scroll vertically with the Digital Crown, Bern requires every reachable Adaptive block in a watchOS target to provide an explicit Layout(size: watch) branch. If an Adaptive block lacks Layout(size: watch), bern check --target watchos fails with diagnostic B401.
At compile time, Bern prunes all non-watch branches (compact, medium, expanded, tv) so code and views for larger screens are never generated into the watch binary.
Adaptive {
Layout(size: watch) {
ScrollView {
Column(gap: 8) {
Text(tasks.title, style: title)
ForEach(tasks.items) |item| {
Button(item.title) => toggle(id: item.id)
}
}
}
}
Layout(size: compact) { /* pruned for watchOS */ }
}Build, run, and debug
# Check declarations (including B401 watch-layout coverage)
bern check --target watchos
# Build for the watchOS simulator
bern build --target watchos
# Launch on an Apple Watch simulator with IPC connected
bern run --target watchosDrive the running simulator app via the generated app CLI using --engine watchos:
target/bern/watchos/bin/tasks --engine watchos window screenshot --output watch.pngUseful debugging environment variables:
| Variable | Effect |
|---|---|
BERN_APPEARANCE=light|dark |
Overrides appearance for inspection. |
BERN_MOTION=reduce|slow |
Reduces motion or slows spring animations 10×. |
BERN_TRACE=<rules> |
Enables performance tracing. |
BERN_SNAPSHOT_DIR=<dir> |
Saves automatic window snapshots. |
Platform behavior and adaptations
- Watch-native controls:
MenuandPickerrender as crown-scrollable native watch sheets (BernWatchMenu/BernWatchPicker).Tablelowers to a verticalList.Formavoids nested row plates so stacked cards stay legible on small screens. - Navigation and modals: Secondary windows and
Modalviews open as full-screen watch sheets;TabViewuses vertical page tabs. - Animated SVG & JavaScript: Pure-Rust animated
Svg(BSVGbytecode) and opt-in in-processjavascript = trueboth run directly on watchOS with no WebView dependency. Static SVGs rasterize to PNGs at build time. - Unavailable capabilities:
WebPage,file_pick,paste:,MenuBar,StatusItem,ShortcutInput, and pointer-hover interactions are not available on watchOS. Declarations that keep those desktop/phone controls inside non-watchbranches ofAdaptivecompile cleanly because unused branches are pruned before target checking. - Native views: Co-located WatchKit/SwiftUI views can be embedded with
NativeView(watchos: "..."). See Native views.
Packaging and signing
bern package --target watchosbern package --target watchos builds a release Watch-Only .ipa (arm64 + arm64_32 where applicable) under target/bern/dist/. Re-sign the .ipa with your Apple distribution certificate and Watch provisioning profile before installing on a paired Apple Watch or uploading to App Store Connect.