waterui-cli
Cross-platform build orchestration and development tooling for WaterUI applications.
Overview
waterui-cli is the command-line interface that powers the water binary, the primary tool for building, running, and managing WaterUI applications across iOS, macOS, and Android. It abstracts platform-specific build systems (Xcode for Apple, Gradle for Android) and provides a unified developer experience with hot reload, device management, and project scaffolding.
The crate is split into two components:
- Library (
src/lib.rs): Core abstractions for platforms, devices, builds, and project management - Terminal (
src/terminal/): User-facing CLI with argument parsing and formatted output
This separation ensures all business logic lives in the library, while the terminal layer handles only user interaction.
Installation
Install the CLI from source within the WaterUI workspace:
Or build for development (not added to PATH):
Quick Start
Create a new WaterUI project and run it on iOS Simulator:
# Create a new project
# Run on iOS Simulator with hot reload
# Run on Android
Create a playground for quick experimentation (auto-managed backends):
Core Concepts
Platform Abstraction
The Platform trait represents a build target (iOS, macOS, Android with different ABIs). Each platform implementation handles:
- Device scanning: Enumerate connected devices and emulators
- Building: Compile Rust library for the target triple
- Packaging: Generate platform-specific artifacts (
.app,.apk) - Cleaning: Remove build artifacts
Example from src/platform.rs:
Implementations: ApplePlatform (iOS, macOS, simulators), AndroidPlatform (arm64-v8a, x86_64, etc.)
Device Management
The Device trait represents something that can run an app (simulator, emulator, or physical device). Each device has a two-phase lifecycle:
- Launch: Boot the emulator/simulator (no-op for physical devices)
- Run: Install and execute the artifact, returning a
Runningstream
Example from src/device.rs:
Implementations: AppleSimulator, MacOS, AndroidDevice, AndroidEmulator
Project Management
The Project type manages the Water.toml manifest and coordinates builds across platforms. Key methods:
Project::open(): Open existing projectProject::create(): Scaffold new projectProject::run(): Build, package, and run on a device with optional hot reload
Example from src/project.rs:
pub async
Hot Reload System
The hot reload system uses WebSocket to broadcast dylib updates to connected apps:
- CLI launches
HotReloadServeronlocalhost:2006+ - Server monitors file changes with 250ms debouncing
- On change, rebuild library and broadcast to all connected clients
- Apps reload the updated library without restarting
Example from src/debug/hot_reload.rs:
pub async
Environment variables WATERUI_HOT_RELOAD_HOST and WATERUI_HOT_RELOAD_PORT are passed to running apps.
Rust Build
The RustBuild type wraps cargo build with platform-specific configuration:
- Target triple selection (e.g.,
aarch64-apple-ios-sim) - Hot reload flag (
--cfg waterui_hot_reload_lib) - Simulator-specific clang args for bindgen
Example from src/build.rs:
let mut cmd = new;
let mut cmd = command
.arg
.arg
.args
.current_dir;
if self.hot_reload
Toolchain Management
The Toolchain trait checks for required dependencies and provides installation plans:
Example: AppleToolchain checks for Xcode, simulators, and rust targets. AndroidToolchain checks for Android SDK, NDK, and JDK.
Examples
Run with Device Logs
This streams device logs at debug level or above to the terminal.
Run on Specific Device
# List available devices
# Run on specific device by ID
Create Project with Local WaterUI Development
This creates a project that uses the local WaterUI repository (useful for framework development).
Build Without Running
Clean Build Artifacts
Check Development Environment
This validates toolchain dependencies (Xcode, Android SDK, Rust targets).
API Overview
Library (src/lib.rs)
platform: Platform trait and implementations (Apple, Android)device: Device trait, device types, run options, and eventsproject: Project management, manifest parsing, create/openbuild: Rust build orchestration with cargodebug: Hot reload server, build manager, file watchertoolchain: Toolchain checking and installationbackend: Backend configuration and scaffoldingtemplates: Project scaffolding templatesapple: Apple platform, devices, and backendandroid: Android platform, devices, and backendbrew: Homebrew package management utilitieswater_dir: Global WaterUI directory managementutils: Command execution helpers
Terminal (src/terminal/)
main.rs: CLI entry point, argument parsingshell.rs: Output formatting, spinners, colorscommands/create.rs: Project scaffolding commandcommands/run.rs: Build and run commandcommands/build.rs: Build-only commandcommands/package.rs: Packaging commandcommands/clean.rs: Cleanup commandcommands/doctor.rs: Toolchain validation commandcommands/devices.rs: Device listing command
Features
The CLI supports:
- Hot reload: WebSocket-based live code updates
- Multi-platform: iOS, macOS, Android with unified workflow
- Device management: Automatic device discovery and simulator launching
- Interactive creation: Guided project setup with prompts
- Playground mode: Auto-managed backends for quick prototyping
- Parallel builds: Device launch overlaps with compilation
- Log streaming: Real-time device logs with level filtering
- JSON output: Machine-readable output with
--jsonflag - Graceful cancellation: Ctrl+C cleanup without errors