Swan is a Swift WebGPU binding library that provides Swift APIs for using WebGPU across multiple platforms. The initial implementation is a Swift binding to Google's Dawn library. This is currently a work-in-progress project not ready for production use.
- WebGPU: Cross-platform facade that clients import. Conditionally re-exports
WebGPUDawn(native) orWebGPUWasm(WASM) - WebGPUDawn: Native backend wrapping Dawn (macOS, Windows)
- WebGPUWasm: WASM backend bridging to the browser's WebGPU API (WASI)
- Dawn: Swift wrapper around Google's Dawn WebGPU implementation
- CDawn: C bindings layer for Dawn
- DawnData: Data structures and utilities for Dawn integration
- GameOfLife: Demo/example application
The project uses Swift Package Manager plugins for code generation:
- GenerateDawnBindingsPlugin: Generates Swift bindings from Dawn's C API
- GenerateDawnAPINotesPlugin: Generates API notes for better Swift integration
Both plugins depend on executable targets that process dawn.json to generate appropriate Swift code.
The project uses a binary target DawnLib that contains pre-built Dawn WebGPU libraries for multiple platforms (macOS, iOS, Linux, Windows). These are built via GitHub Actions and distributed as releases.
You need to use the swift version that is defined in .swift-version. Please do so by ensuring that swiftly is first in the PATH variable:
export PATH="$HOME/.swiftly/bin:$PATH"and let swiftly install and use the defined version:
swiftly install
swiftly useIt might be useful to clean up old artifacts when the version was changed. In that case run:
swift package cleanbefore finally running a build with:
swift buildThe WASM SDK version is defined in .wasm-sdk-version. WASM builds need to set the swift-sdk and specify the WebGPU target in the build command:
BUILD_WASM=1 swift build --target WebGPU --swift-sdk $(cat .wasm-sdk-version)swift test# Generate Dawn API notes
swift package generate-dawn-apinotes
# Bindings are generated automatically during build via GenerateDawnBindingsPluginThe project uses swift-format with configuration in .swift-format:
- Line length: 140 characters
- Uses tabs for indentation
- Ordered imports enabled
- macOS 15+
- iOS 18+
- Swift 6.3+
- Uses development snapshot toolchain (6.3-snapshot-2026-01-29)
- swift-testing (for tests)
- swift-log (for logging)
- swift-syntax (for code generation)
- swift-argument-parser (for CLI argument parsing)
- swift-format (for code formatting)
Package.swift: Swift Package Manager configurationDawn/ci_build_dawn.py: Python script for building dawn in CI.wasm-sdk-version: WASM SDK version for cross-compilation to WebAssembly.swift-format: Code formatting configuration.vscode/settings.json: VS Code configuration with specific Swift toolchain path
The project maintains its own Dawn builds through GitHub Actions workflows that:
- Fetch specific Chromium/Dawn versions
- Build Dawn for multiple platforms
- Package as binary releases
- Update Package.swift with new binary target URLs
The Dawn source management and building is handled by Python scripts in the Dawn/ directory.