The SwiftUI API, implemented in pure Swift, for Linux and macOS.
Cacao evaluates your views, lays them out with SwiftUI's layout rules, and renders them with a GPU layer compositor: content is drawn with Silica (Cairo on Linux, CoreGraphics on macOS) only when it changes, and composited every frame by the SDL3 renderer (Metal, Vulkan or OpenGL), so scrolling and animation never repaint.
Status: early development (Phase 9: views, layout, controls, text input, lazy lists, forms, grids, navigation, tabs, presentations, animations, transitions, gestures,
TimelineView,Canvas, geometry readers,ObservableObjectand storage, accessibility, multiple windows, gradients, blur, shadows and color effects, phase and keyframe animators, date and color pickers, gauges and@Entry, drawn by a GPU compositor on Linux and macOS). See API coverage for what's implemented. See the plan for the architecture and roadmap. The previous UIKit implementation is preserved at theuikit-legacytag.
| Module | |
|---|---|
CacaoRender |
The display list and the values it's made of: paths, colors, text, images, effects. No SwiftUI. |
Cacao |
The SwiftUI API: views, state, environment and layout, which build display lists. Platform-neutral, builds headless. |
CacaoMacros |
The @Entry macro. |
CacaoCompositor |
Draws display lists with Silica and composites them on the GPU. |
CacaoSDLRenderer |
The SDL3 GPU compositor backend, and HostRenderer, which draws display lists with an SDL renderer a UI framework already has. No windows. |
CacaoHost |
SDL3 windows, the main loop and input, for whatever implements HostScene, drawn with CacaoSDLRenderer. No SwiftUI. |
CacaoSDL |
SwiftUI on the host: a view graph as each window's scene. |
CacaoScrollPhysics |
Velocity tracking, deceleration, rubber band and spring-back. |
SwiftUI (Linux only) |
Re-exports Cacao, so sources that import SwiftUI compile unchanged. |
import CacaoSDL // or `import SwiftUI` on Linux
@main
struct HelloApp: App {
var body: some Scene {
WindowGroup("Hello") {
ContentView()
}
}
}
struct ContentView: View {
@State private var count = 0
var body: some View {
VStack(spacing: 12) {
Text("Count: \(count)")
.font(.title)
Button("Increment") { count += 1 }
.buttonStyle(.borderedProminent)
}
}
}Run the demo with swift run CacaoDemo. Press F12 (or set
CACAO_SHOW_STATISTICS=1) for frame times and compositor counts, and set
CACAO_SCREENSHOT=path.png to save the first frame and quit;
CACAO_SCREENSHOT_DELAY=seconds waits that long first.
Windows follow the system's light or dark appearance. On Linux that is the
desktop's color scheme, from the freedesktop settings portal or GNOME's
settings; CACAO_APPEARANCE=dark or light overrides it.
Requires Swift 6.4 or later and SDL3.
brew install sdl3 cairo fontconfigswift buildInstall Cairo and fontconfig, and SDL3 (3.2 or later), which isn't packaged on Ubuntu 24.04 and earlier, so build it from source:
sudo apt-get install cmake ninja-build pkg-config fonts-dejavu-core libcairo2-dev libfontconfig-dev libfreetype-dev libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev libxtst-dev libxkbcommon-dev libwayland-dev wayland-protocols libdecor-0-dev libdrm-dev libgbm-dev libegl-dev libgl-dev libgles-dev libvulkan-dev libdbus-1-dev libudev-dev libpulse-dev libasound2-devgit clone --depth 1 --branch release-3.4.8 https://github.com/libsdl-org/SDL.gitcmake -S SDL -B SDL/build -G Ninja -DCMAKE_BUILD_TYPE=Releasecmake --build SDL/build && sudo cmake --install SDL/buildswift buildFor a system image (Buildroot and the like), CMake builds Cacao as shared
libraries with library evolution, and installs them and their modules into
the Swift resource directory (lib/swift/<system>), where apps find them
like the OS's own frameworks:
cmake -B build -G Ninja -DCMAKE_INSTALL_PREFIX=/usrcmake --build buildcmake --install buildSilica's modules and the CSDL3 module from PureSwift/SDL
must be in the resource directory, or on search paths in CMAKE_Swift_FLAGS.
The @Entry macro's compiler plugin runs on the machine that compiles: when
cross compiling, build Sources/CacaoMacros on its own with the host's
toolchain. SwiftPM stays the way to develop and test.
SDL_VIDEO_DRIVER=offscreen swift testMIT. See LICENSE.
Image(systemName:) draws symbols from Phosphor Icons
(MIT), generated into Swift by Scripts/GenerateSymbols.py from the names
in Scripts/SymbolNames.txt. See ThirdPartyLicenses.md.