Triple
Build static Linux binaries on your Mac.
Use the Swift library, CLI, or native app.
Triple 0.2.0. Apple silicon. macOS 26.5 or later.
import Foundation
import Triple
let result = try await Triple.build(
URL(filePath: "./MyServer"),
for: .linux(.arm64)
)
print(result.executable.path)
MyServer
- Target
- Linux ARM64
- Build
- Release
- Linking
- Static · Musl
- Executable
- Unstripped
- Output
- .build/
Swift library
One line of Swift.
Add Linux builds to your own Swift tools.
Add the package.
In Package.swift, add Triple to your dependencies,
then add its library product to your target.
.package(
url: "https://github.com/mottzi/Triple.git",
from: "0.7.0"
)
.product(
name: "Triple",
package: "Triple"
)
Build a verified Linux executable from your package directory.
import Foundation
import Triple
let package = URL(filePath: ".")
let result = try await Triple.build(package)
print(result.executable.path)Defaults to x86-64 Linux and release mode. Installs missing build tools and resolves dependencies.
Add an output destination to get a runnable directory containing the executable and its resource bundles.
let result = try await Triple.build(
URL(filePath: "/path/to/MyServer"),
output: .export(to: URL(filePath: "/path/to/output/Server"))
)
print(result.directory.path)You can also export the result returned by an earlier build:
let exported = try await result.export(to: URL(filePath: "/path/to/output/Server"))Use a new destination whose parent directory exists. To replace an existing directory and its contents, pass policy: .replaceIfPresent.
Choose an executable and Linux architecture. Export the result and strip symbols for a smaller binary.
let result = try await Triple.build(
URL(filePath: "./MyServer"),
product: "MyServer",
for: .linux(.arm64),
output: .export(to: URL(filePath: "./MyServer-linux")),
strip: true
)
print(result.directory.path)Builds an ARM64 release and exports the stripped executable with its resources.
For tools that need approval before installing components, assess first. Inspect the package before enabling a build.
import Foundation
import Triple
let kit = Triple()
let package = URL(filePath: "/path/to/MyServer")
let assessment = try await kit.assess(package, for: .linux(.arm64))
// assessment.requiredComponents lists what prepare must install or update.
// Ask the user to approve those changes before calling prepare.
let prepared = try await kit.prepare(assessment)
// Inspection needs resolved dependencies to read the full package graph.
// .resolveIfNeeded lets SwiftPM download dependencies when needed.
let inspection = try await kit.inspectPackage(
using: prepared,
dependencies: .resolveIfNeeded
)
let product = try inspection.products.select("MyServer")
let request = BuildRequest(product)
let result = try await kit.build(request, using: inspection.environment)Assessment installs nothing. Preparation and dependency resolution are explicit steps.
Before you build
On your Mac
Apple silicon, macOS 13+, and Xcode or Command Line Tools with Swift 6.3+. Run library callers outside the App Sandbox.
In your package
Your executable and dependencies must support Linux Musl. Build packages you trust; SwiftPM can run manifests and plugins.
TripleCLI For your terminal.
Build and export from your terminal. Get JSON results for scripts and CI.
Install from source.
For Apple silicon Macs with macOS 13+ and Swift 6.3+.
git clone https://github.com/mottzi/TripleCLI.git
cd TripleCLI
git checkout 0.3.0
./install.sh
Installs triple in ~/.local/bin and adds it to your shell's PATH.
Build and export.
Choose ARM64 Linux and an output directory.
triple build ./MyServer \
--architecture aarch64 \
--output-path ./MyServer-linux \
--install-environment \
--resolve-dependencies
Example output
MyServer-linux/
Verified static ARM64 executable and required resources.
The flags permit installing build tools and resolving dependencies. Add --json for one machine-readable result.
TripleApp Simple and native.
Build static Linux executables from your Swift packages. Choose the settings. Triple handles the build.
Drop it in.
Build it here.
Drop in a Swift package. Triple finds its products and installed Swift tools.
Pick your Linux target. Follow the build as it happens.
One export.
Ready for Linux.
Your executable and its resource bundles, together. Export the finished build or open it in Finder.
For Apple silicon Macs with macOS 26.5 or later.