Updates ·

Proof of concept: one package, four targets

A single SwiftPM package, built, tested and run on macOS, Linux, Windows and WebAssembly (WASI) with stock Swift 6.4.1 tools, pinned toolchains and a checksummed SDK.

By Teodor Walter Vido

The first milestone for Xwift was deliberately modest: take one ordinary SwiftPM package and get it building, testing and running on as many targets as possible, using only stock tools from swift.org. Here is what that looks like.

The package

The package, Xwift, has three targets:

  • XwiftCore, a library exposing PlatformInfo.current (operating system, architecture, pointer width) and a greeting() helper.
  • xwift-hello, an executable that prints a greeting for the platform it was compiled for.
  • XwiftCoreTests, tests written with both XCTest and swift-testing.
Sources/xwift-hello/main.swift
import XwiftCore

print(greeting())

PlatformInfo is resolved entirely at compile time with #if os(…) and #if arch(…), so the same source produces a different answer per target:

Sources/XwiftCore/PlatformInfo.swift (excerpt)
public var description: String {
    "\(os.rawValue)-\(architecture.rawValue) (\(pointerBitWidth)-bit)"
}

The pinned toolchain

The proof of concept uses stock swift.org releases. The Xwift toolchain is separate and has not been released.

ComponentVersion
Swift toolchain6.4.1 (.swift-version)
Swift SDK for WebAssemblyswift-6.4.1-RELEASE_wasm
wasmtime38.0.1

The build matrix

The proof of concept was built in one GitHub Actions workflow with four jobs:

JobRunnerHow Swift is installedSteps
Linux (Ubuntu 24.04)ubuntu-24.04swift:6.4.1-noble containerbuild, test, run
macOSmacos-15swiftlybuild, test, run
Windowswindows-2022compnerd/gha-setup-swiftbuild, test, run
WebAssembly (WASI)ubuntu-24.04swift:6.4.1-noble + Swift SDK for WebAssemblybuild, run with wasmtime

The WebAssembly job installed the SDK with a pinned checksum, built xwift-hello for wasm32, ran it with wasmtime and checked that the output contained wasi-wasm32:

swift sdk install https://download.swift.org/swift-6.4.1-release/wasm-sdk/swift-6.4.1-RELEASE/swift-6.4.1-RELEASE_wasm.artifactbundle.tar.gz \
  --checksum 783e6128d174d9f975b4eda68be02a5960681b723ef372e6876a7c2543a365d8
swift build -c release --swift-sdk swift-6.4.1-RELEASE_wasm --product xwift-hello
wasmtime .build/release/xwift-hello.wasm

Each job passed when this was written. That workflow no longer runs.

What this does not prove

It is worth being precise. This milestone shows that one small, dependency-free package compiles and runs on four targets with stock swift.org tools. It says nothing yet about:

  • the Xwift toolchain, which is in progress and has not been released;
  • Android or iOS, which were not in the matrix;
  • the planned xwift CLI, UI framework or system APIs;
  • performance, binary size or larger real-world packages;
  • running in a browser (the WebAssembly target today is WASI, run with wasmtime).

Those are the next chapters. You can reproduce everything above by following Getting started.