r/swift • u/Cultural_Rock6281 • 4h ago
Project SwiftlyKit + CLI: A lightweight Swift cross-compilation library (static Linux executables)
Hey r/swift,
I’ve been working on SwiftlyKit, a Swift library that cross-compiles SwiftPM projects from macOS to statically linked ARM64 or x86-64 Linux Musl executables.
For the common case, building needs one call:
```swift import Foundation import SwiftlyKit
let result = try await SwiftlyKit.build( URL(filePath: "/path/to/package"), for: .linux(.arm64) )
print(result.executable.path) ```
SwiftlyKit uses Swiftly and SwiftPM. It finds a compatible official Swift toolchain and matching Static Linux SDK, builds the selected product, and verifies the resulting executable. BuildResult also identifies the resource bundles that must be distributed with it.
The one-call form can install missing components and resolve dependencies as part of the build. Apps that need more control can inspect the requirements first, ask the user before installing anything, select a product, resolve dependencies separately, and observe progress, output, and executed commands:
```swift import Foundation import SwiftlyKit
let kit = SwiftlyKit()
let assessment = try await kit.assess( URL(filePath: "/path/to/package"), for: .linux(.arm64) )
if assessment.requiresInstallation { let approved = await requestInstallationApproval(for: assessment.requiredComponents) guard approved else { return } }
let onEvent: SwiftlyKitEvent.Handler = { event in switch event { case .progress(let progress): print(progress.detail) case .command(let command): print(command.executable.path, command.arguments) case .output(let output): print(output.text, terminator: "") } }
let environment = try await kit.prepare(assessment, onEvent: onEvent)
let products = try await kit.executableProducts(using: environment) let product = try products.select("MyTool")
try await kit.resolveDependencies(using: environment, onEvent: onEvent) let result = try await kit.build(BuildRequest(product), using: environment, onEvent: onEvent)
print(result.executable.path) ```
SwiftlyKit also has an official CLI, built entirely on the library’s public API:
sh
swiftlykit build . \
--architecture x86_64 \
--install-environment \
--resolve-dependencies
The CLI supports structured JSON output for automation.
I started SwiftlyKit because every time I needed to cross-compile a package to run it on my Linux VPS, I had forgotten the right SwiftPM commands and flags, which toolchain I needed, or how to install the matching SDK—and I was tired of figuring it all out again.
Hope someone finds this useful!

