Skip to content

Chapter 22: Mobile Development

Wyn cross-compiles to native arm64 binaries for iOS and Android - no JavaScript bridge, no virtual machine. Mobile support today covers the compiled core of an app: you write and test the app logic on your desktop, and wyn cross produces a device-architecture binary from the same source. The platform UI shell (the layer that turns wyn_ui_* calls into real UILabel/UIButton widgets and packages an installable .app/.apk) is not shipped yet, so the wyn_* mobile functions below are stubs you declare yourself.

The Mobile App Shape

wyn
// Mobile SDK stubs - you declare these yourself for now.
// They keep the app buildable and testable on your desktop.
fn wyn_ui_text(ctx: int, text: string, size: int) {}
fn wyn_ui_button(ctx: int, label: string, id: int) {}
fn wyn_ios_main(a: int, b: int) -> int { return 0 }

fn wyn_app_title() -> string {
    return "Hello Wyn"
}

fn wyn_app_build(ctx: int) {
    wyn_ui_text(ctx, "Welcome!", 28)
    wyn_ui_button(ctx, "Tap Me", 1)
}

fn wyn_on_button(id: int) {
    println("Tapped!")
}

fn main() -> int {
    return wyn_ios_main(0, 0)
}

This builds and runs on your desktop (wyn run app.wyn), where the stubs do nothing and you can drive wyn_on_button from tests or from main.

Cross-Compiling

For iOS (requires Xcode's iOS SDK - the Command Line Tools alone are not enough):

bash
wyn cross ios app.wyn
# Produces app.wyn.ios (arm64 Mach-O, min iOS 15)

For Android (requires the Android NDK - Android Studio, SDK Manager, NDK):

bash
wyn cross android app.wyn
# Produces app.wyn.android (arm64)

Both paths are exercised by CI on every push. Note the output is a bare executable, not an installable app bundle: shipping it to a device still requires an Xcode or Gradle host project that embeds the binary, plus signing. .app/.apk packaging from the CLI is on the roadmap.

Conventions for the Future Shell

The stub names above are the planned contract with the platform shell:

  • wyn_app_title() - the app's display name
  • wyn_app_build(ctx) - build the UI (called on launch and after events)
  • wyn_on_button(id) - button-tap callback
  • wyn_ui_text(ctx, text, size), wyn_ui_button(ctx, title, id), wyn_ui_spacer(ctx, height) - UI elements

Runtime behaviors that make no sense on mobile are already guarded: on an iOS or Android build, System::exec returns an empty string and Process::exec_status returns -1 instead of shelling out.

Fast Iteration

bash
wyn watch app.wyn

Edit your code, save, and wyn watch rebuilds and reruns automatically. Develop the app logic on your desktop with stubs, then wyn cross ios/android to produce the device binary.

MIT License - v1.19.1