diff --git a/.bsp/xtool.json b/.bsp/xtool.json
new file mode 100644
index 00000000..2ca811e8
--- /dev/null
+++ b/.bsp/xtool.json
@@ -0,0 +1,7 @@
+{
+ "name": "xtool",
+ "version": "1.0",
+ "bspVersion": "2.2.0",
+ "languages": ["c", "cpp", "objective-c", "objective-cpp", "swift"],
+ "argv": ["/usr/bin/env", "xtool", "dev", "build-server", "--triple", "arm64-apple-macosx"]
+}
diff --git a/.swiftlint.yml b/.swiftlint.yml
index 70833bc1..aa4d1556 100644
--- a/.swiftlint.yml
+++ b/.swiftlint.yml
@@ -51,6 +51,15 @@ custom_rules:
- identifier
message: "Use d.out.print instead of print or Swift.print."
severity: error
+ prefer_xtool_subprocess_output:
+ name: "Subprocess Dependency Output"
+ included: '/Sources/'
+ excluded: '/(Tests|Examples)/'
+ regex: '(?<=\.)\s*currentStandard(?:Output|Error)\b'
+ match_kinds:
+ - identifier
+ message: "Use .xtoolOutput() or .xtoolError() instead of .currentStandardOutput or .currentStandardError, respectively."
+ severity: error
spaces_not_tabs:
name: "Spaces not Tabs"
regex: ^\t
@@ -73,3 +82,4 @@ included:
- macOS/XToolMac
excluded:
- Sources/DeveloperAPI/Generated
+ - Sources/XPIF
diff --git a/Dockerfile b/Dockerfile
index 561ee77e..793dc4dc 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -20,6 +20,7 @@ RUN apt-get update \
curl libcurl4-openssl-dev \
zip unzip \
liblzma-dev zlib1g-dev \
+ libsqlite3-dev libncurses-dev \
&& rm -rf /var/lib/apt/lists/*
diff --git a/Examples/DemoAudioUnit/Package.swift b/Examples/DemoAudioUnit/Package.swift
new file mode 100644
index 00000000..74dcb13b
--- /dev/null
+++ b/Examples/DemoAudioUnit/Package.swift
@@ -0,0 +1,22 @@
+// swift-tools-version: 6.0
+
+import PackageDescription
+
+let package = Package(
+ name: "DemoAudioUnit",
+ platforms: [
+ .iOS(.v17),
+ .macOS(.v14),
+ ],
+ products: [
+ .library(name: "DemoAudioUnit", targets: ["DemoAudioUnit"]),
+ .library(name: "DemoAudioUnitExtension", targets: ["DemoAudioUnitExtension"]),
+ ],
+ dependencies: [
+ .package(path: "../ExampleSupport"),
+ ],
+ targets: [
+ .target(name: "DemoAudioUnit", dependencies: ["ExampleSupport"]),
+ .target(name: "DemoAudioUnitExtension"),
+ ]
+)
diff --git a/Examples/DemoAudioUnit/README.md b/Examples/DemoAudioUnit/README.md
new file mode 100644
index 00000000..1fc7b7aa
--- /dev/null
+++ b/Examples/DemoAudioUnit/README.md
@@ -0,0 +1,5 @@
+# DemoAudioUnit
+
+This is an end-to-end test of building and running an app with an app extension (AudioUnit Extension).
+
+We verify that the app can communicate back and forth with the extension, and that they can use a shared app group.
diff --git a/Examples/DemoAudioUnit/Sources/DemoAudioUnit/App.swift b/Examples/DemoAudioUnit/Sources/DemoAudioUnit/App.swift
new file mode 100644
index 00000000..4f6968ef
--- /dev/null
+++ b/Examples/DemoAudioUnit/Sources/DemoAudioUnit/App.swift
@@ -0,0 +1,78 @@
+import AudioToolbox
+import AVFAudio
+import ExampleSupport
+import SwiftUI
+
+@main struct DemoApp: App {
+ var body: some Scene {
+ WindowGroup {
+ Text("Testing Audio Unit extension...")
+ .padding()
+ .task {
+ let watchdog = Task { @MainActor in
+ try await Task.sleep(for: .seconds(15))
+ print("Test failed: Audio Unit extension timed out")
+ exit(1)
+ }
+ defer { watchdog.cancel() }
+ do {
+ try await Task { @concurrent in try await runTest() }.value
+ Example.pass()
+ } catch {
+ print("Test failed: \(error)")
+ exit(1)
+ }
+ }
+ }
+ }
+}
+
+private func runTest() async throws {
+ let description = AudioComponentDescription(
+ componentType: kAudioUnitType_Generator,
+ componentSubType: 0x70696E67, // ping
+ componentManufacturer: 0x58746F6F, // Xtoo
+ componentFlags: 0,
+ componentFlagsMask: 0
+ )
+ let audioUnit = try await AUAudioUnit.instantiate(with: description, options: .loadOutOfProcess)
+ let channel = audioUnit.messageChannel(for: "xtool.test")
+ guard let reply = channel.callAudioUnit?(["message": "ping"]),
+ reply["message"] as? String == "pong" else {
+ throw StringError("Audio Unit extension did not reply with pong")
+ }
+ guard let pid = reply["pid"] as? Int,
+ pid > 0, pid != Int(ProcessInfo.processInfo.processIdentifier) else {
+ throw StringError("Audio Unit did not execute in a separate process")
+ }
+ print("Audio Unit extension replied pong from PID \(pid)")
+ try testAppGroup(channel: channel)
+}
+
+private func testAppGroup(channel: any AUMessageChannel) throws {
+ // xtool prefixes both the bundle ID and App Group when signing for a device.
+ let groupID = "group.\(Bundle.main.bundleIdentifier!).data"
+ guard FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupID) != nil,
+ let defaults = UserDefaults(suiteName: groupID) else {
+ throw StringError("Host could not access the App Group")
+ }
+ // fresh keys ensure a previous run cannot satisfy this test.
+ let token = UUID().uuidString
+ let requestKey = "request.\(token)"
+ let responseKey = "response.\(token)"
+ defer {
+ defaults.removeObject(forKey: requestKey)
+ defaults.removeObject(forKey: responseKey)
+ }
+ defaults.set("ping", forKey: requestKey)
+ let reply = channel.callAudioUnit?([
+ "message": "test-app-group", "groupID": groupID, "token": token,
+ ])
+ guard reply?["message"] as? String == "ok" else {
+ throw StringError("App Group extension test failed: \(reply, default: "nil")")
+ }
+ guard defaults.string(forKey: responseKey) == "pong" else {
+ throw StringError("Host did not read pong from App Group defaults")
+ }
+ print("App Group defaults exchanged ping/pong between host and extension")
+}
diff --git a/Examples/DemoAudioUnit/Sources/DemoAudioUnitExtension/AudioUnit.swift b/Examples/DemoAudioUnit/Sources/DemoAudioUnitExtension/AudioUnit.swift
new file mode 100644
index 00000000..885e030f
--- /dev/null
+++ b/Examples/DemoAudioUnit/Sources/DemoAudioUnitExtension/AudioUnit.swift
@@ -0,0 +1,75 @@
+import AudioToolbox
+import AVFAudio
+import Foundation
+
+@objc(DemoAudioUnitFactory)
+final class AudioUnitFactory: NSObject, AUAudioUnitFactory {
+ func beginRequest(with context: NSExtensionContext) {}
+
+ func createAudioUnit(with description: AudioComponentDescription) throws -> AUAudioUnit {
+ try DemoAudioUnit(componentDescription: description)
+ }
+}
+
+private final class DemoAudioUnit: AUAudioUnit {
+ private var outputs: AUAudioUnitBusArray!
+
+ override init(
+ componentDescription: AudioComponentDescription,
+ options: AudioComponentInstantiationOptions = []
+ ) throws {
+ try super.init(componentDescription: componentDescription, options: options)
+ let format = AVAudioFormat(standardFormatWithSampleRate: 44_100, channels: 2)!
+ let bus = try AUAudioUnitBus(format: format)
+ self.outputs = AUAudioUnitBusArray(audioUnit: self, busType: .output, busses: [bus])
+ }
+
+ override var outputBusses: AUAudioUnitBusArray { outputs }
+
+ // A silent generator keeps this a valid Audio Unit, although the execution
+ // test only instantiates it and exchanges messages; it never starts audio.
+ override var internalRenderBlock: AUInternalRenderBlock {
+ { _, _, _, _, output, _, _ in
+ for buffer in UnsafeMutableAudioBufferListPointer(output) {
+ if let data = buffer.mData {
+ memset(data, 0, Int(buffer.mDataByteSize))
+ }
+ }
+ return noErr
+ }
+ }
+
+ override func messageChannel(for channelName: String) -> any AUMessageChannel {
+ TestMessageChannel()
+ }
+}
+
+private final class TestMessageChannel: NSObject, AUMessageChannel {
+ // AudioToolbox installs this callback when connecting the remote channel,
+ // even though this test only sends requests from the host.
+ var callHostBlock: CallHostBlock?
+
+ func callAudioUnit(_ message: [AnyHashable: Any]) -> [AnyHashable: Any] {
+ if message["message"] as? String == "test-app-group" {
+ return ["message": testAppGroup(message)]
+ }
+ return [
+ "message": message["message"] as? String == "ping" ? "pong" : "unknown message",
+ "pid": Int(ProcessInfo.processInfo.processIdentifier),
+ ]
+ }
+
+ private func testAppGroup(_ message: [AnyHashable: Any]) -> String {
+ guard let groupID = message["groupID"] as? String,
+ let token = message["token"] as? String,
+ FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupID) != nil,
+ let defaults = UserDefaults(suiteName: groupID) else {
+ return "Extension could not access the App Group"
+ }
+ guard defaults.string(forKey: "request.\(token)") == "ping" else {
+ return "Extension did not read ping from App Group defaults"
+ }
+ defaults.set("pong", forKey: "response.\(token)")
+ return "ok"
+ }
+}
diff --git a/Examples/DemoAudioUnit/Support/DemoAudioUnit.entitlements b/Examples/DemoAudioUnit/Support/DemoAudioUnit.entitlements
new file mode 100644
index 00000000..446d84dd
--- /dev/null
+++ b/Examples/DemoAudioUnit/Support/DemoAudioUnit.entitlements
@@ -0,0 +1,12 @@
+
+
+
+
+ com.apple.security.application-groups
+
+ group.sh.xtool.examples.DemoAudioUnit.data
+
+ inter-app-audio
+
+
+
diff --git a/Examples/DemoAudioUnit/Support/DemoAudioUnitExtension-Info.plist b/Examples/DemoAudioUnit/Support/DemoAudioUnitExtension-Info.plist
new file mode 100644
index 00000000..a823d064
--- /dev/null
+++ b/Examples/DemoAudioUnit/Support/DemoAudioUnitExtension-Info.plist
@@ -0,0 +1,39 @@
+
+
+
+
+ NSExtension
+
+ NSExtensionPointIdentifier
+ com.apple.AudioUnit
+ NSExtensionPrincipalClass
+ DemoAudioUnitFactory
+ NSExtensionAttributes
+
+ AudioComponents
+
+
+ name
+ xtool: DemoAudioUnit
+ description
+ xtool extension execution test
+ manufacturer
+ Xtoo
+ type
+ augn
+ subtype
+ ping
+ version
+ 1
+ sandboxSafe
+
+ tags
+
+ Generator
+
+
+
+
+
+
+
diff --git a/Examples/DemoAudioUnit/Support/DemoAudioUnitExtension.entitlements b/Examples/DemoAudioUnit/Support/DemoAudioUnitExtension.entitlements
new file mode 100644
index 00000000..607cdfe7
--- /dev/null
+++ b/Examples/DemoAudioUnit/Support/DemoAudioUnitExtension.entitlements
@@ -0,0 +1,10 @@
+
+
+
+
+ com.apple.security.application-groups
+
+ group.sh.xtool.examples.DemoAudioUnit.data
+
+
+
diff --git a/Examples/DemoAudioUnit/xtool.yml b/Examples/DemoAudioUnit/xtool.yml
new file mode 100644
index 00000000..3e669100
--- /dev/null
+++ b/Examples/DemoAudioUnit/xtool.yml
@@ -0,0 +1,8 @@
+version: 1
+bundleID: sh.xtool.examples.DemoAudioUnit
+product: DemoAudioUnit
+entitlementsPath: Support/DemoAudioUnit.entitlements
+extensions:
+- product: DemoAudioUnitExtension
+ infoPath: Support/DemoAudioUnitExtension-Info.plist
+ entitlementsPath: Support/DemoAudioUnitExtension.entitlements
diff --git a/Examples/DemoBinary/Package.resolved b/Examples/DemoBinary/Package.resolved
new file mode 100644
index 00000000..fc5e45ae
--- /dev/null
+++ b/Examples/DemoBinary/Package.resolved
@@ -0,0 +1,15 @@
+{
+ "originHash" : "631b6bc3d92a4afe204994d83c6c1aa97d9dd251c57696eb4f5dcdf1999eb3e9",
+ "pins" : [
+ {
+ "identity" : "openssl",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/krzyzanowskim/OpenSSL",
+ "state" : {
+ "revision" : "0a6149bff4fb00921ce0ec1811f726b166638095",
+ "version" : "3.6.5000"
+ }
+ }
+ ],
+ "version" : 3
+}
diff --git a/Examples/DemoBinary/Package.swift b/Examples/DemoBinary/Package.swift
new file mode 100644
index 00000000..e245c3dd
--- /dev/null
+++ b/Examples/DemoBinary/Package.swift
@@ -0,0 +1,30 @@
+// swift-tools-version: 6.0
+
+import PackageDescription
+
+let package = Package(
+ name: "DemoBinary",
+ platforms: [
+ .iOS(.v17),
+ .macOS(.v14),
+ ],
+ products: [
+ .library(
+ name: "DemoBinary",
+ targets: ["DemoBinary"]
+ ),
+ ],
+ dependencies: [
+ .package(path: "../ExampleSupport"),
+ .package(url: "https://github.com/krzyzanowskim/OpenSSL", from: "3.0.0"),
+ ],
+ targets: [
+ .target(
+ name: "DemoBinary",
+ dependencies: [
+ "ExampleSupport",
+ "OpenSSL",
+ ]
+ ),
+ ]
+)
diff --git a/Examples/DemoBinary/README.md b/Examples/DemoBinary/README.md
new file mode 100644
index 00000000..269d5c89
--- /dev/null
+++ b/Examples/DemoBinary/README.md
@@ -0,0 +1,5 @@
+# DemoBinary
+
+This test validates that we can link and embed a binary xcframework, and then use it at runtime.
+
+We perform the test with [krzyzanowskim/OpenSSL](https://github.com/krzyzanowskim/OpenSSL).
diff --git a/Examples/DemoBinary/Sources/DemoBinary/App.swift b/Examples/DemoBinary/Sources/DemoBinary/App.swift
new file mode 100644
index 00000000..473bfaaf
--- /dev/null
+++ b/Examples/DemoBinary/Sources/DemoBinary/App.swift
@@ -0,0 +1,36 @@
+import ExampleSupport
+import SwiftUI
+import OpenSSL
+
+@main struct DemoApp: App {
+ public var body: some Scene {
+ WindowGroup {
+ ContentView()
+ }
+ }
+}
+
+private struct ContentView: View {
+ @State var counter = 0
+
+ var body: some View {
+ Text("Hello, world!")
+ .padding()
+ .task {
+ do {
+ try await verify()
+ Example.pass()
+ } catch {
+ print("Test failed: \(error)")
+ exit(1)
+ }
+ }
+ }
+}
+
+private func verify() async throws {
+ let shaSize = EVP_MD_get_size(EVP_sha256()) * 8
+ guard shaSize == 256 else {
+ throw StringError("OpenSSL sanity check failed: it claims that SHA-256 is \(shaSize) bits (!= 256)")
+ }
+}
diff --git a/Examples/DemoBinary/xtool.yml b/Examples/DemoBinary/xtool.yml
new file mode 100644
index 00000000..fe559928
--- /dev/null
+++ b/Examples/DemoBinary/xtool.yml
@@ -0,0 +1,2 @@
+version: 1
+bundleID: sh.xtool.examples.DemoBinary
diff --git a/Examples/DemoMetal/Package.swift b/Examples/DemoMetal/Package.swift
new file mode 100644
index 00000000..7fb04f84
--- /dev/null
+++ b/Examples/DemoMetal/Package.swift
@@ -0,0 +1,31 @@
+// swift-tools-version: 6.0
+
+import PackageDescription
+
+let package = Package(
+ name: "DemoMetal",
+ platforms: [
+ .iOS(.v17),
+ .macOS(.v14),
+ ],
+ products: [
+ .library(
+ name: "DemoMetal",
+ targets: ["DemoMetal"]
+ ),
+ ],
+ dependencies: [
+ .package(path: "../ExampleSupport"),
+ ],
+ targets: [
+ .target(
+ name: "DemoMetal",
+ dependencies: [
+ "ExampleSupport",
+ ],
+ resources: [
+ .process("shaders.metal")
+ ],
+ ),
+ ]
+)
diff --git a/Examples/DemoMetal/README.md b/Examples/DemoMetal/README.md
new file mode 100644
index 00000000..69631182
--- /dev/null
+++ b/Examples/DemoMetal/README.md
@@ -0,0 +1,5 @@
+# DemoMetal
+
+Validates that we can compile and use a Metal kernel.
+
+This test only runs on macOS for now.
diff --git a/Examples/DemoMetal/Sources/DemoMetal/App.swift b/Examples/DemoMetal/Sources/DemoMetal/App.swift
new file mode 100644
index 00000000..86b8ed5f
--- /dev/null
+++ b/Examples/DemoMetal/Sources/DemoMetal/App.swift
@@ -0,0 +1,73 @@
+import ExampleSupport
+import Metal
+import SwiftUI
+
+@main struct DemoApp: App {
+ public var body: some Scene {
+ WindowGroup {
+ ContentView()
+ }
+ }
+}
+
+private struct ContentView: View {
+ var body: some View {
+ Text("Hello, world!")
+ .padding()
+ .task {
+ do {
+ try await verify()
+ Example.pass()
+ } catch {
+ print("Test failed: \(error)")
+ exit(1)
+ }
+ }
+ }
+}
+
+private func verify() async throws {
+ guard let device = MTLCreateSystemDefaultDevice() else {
+ throw StringError("No Metal device available")
+ }
+ let library = try device.makeDefaultLibrary(bundle: #bundle)
+
+ let functionName = "xtool_verify"
+ guard let function = library.makeFunction(name: functionName) else {
+ throw StringError("Metal library is missing \(functionName). Found: \(library.functionNames)")
+ }
+ let pipeline = try await device.makeComputePipelineState(function: function)
+
+ let input = (0..<64).map { UInt32($0) }
+ let expected = input.map { $0 * $0 + 0x5854 }
+ let length = input.count * MemoryLayout.stride
+ guard let inputBuffer = device.makeBuffer(bytes: input, length: length),
+ let outputBuffer = device.makeBuffer(length: length),
+ let queue = device.makeCommandQueue(),
+ let commandBuffer = queue.makeCommandBuffer(),
+ let encoder = commandBuffer.makeComputeCommandEncoder()
+ else { throw StringError("Failed to set up Metal compute pass") }
+
+ encoder.setComputePipelineState(pipeline)
+ encoder.setBuffer(inputBuffer, offset: 0, index: 0)
+ encoder.setBuffer(outputBuffer, offset: 0, index: 1)
+ encoder.dispatchThreadgroups(
+ MTLSize(width: 1, height: 1, depth: 1),
+ threadsPerThreadgroup: MTLSize(width: input.count, height: 1, depth: 1)
+ )
+ encoder.endEncoding()
+ commandBuffer.commit()
+ await commandBuffer.completed()
+
+ if let error = commandBuffer.error {
+ throw StringError("Metal command buffer failed: \(error)")
+ }
+
+ let output = Array(UnsafeBufferPointer(
+ start: outputBuffer.contents().assumingMemoryBound(to: UInt32.self),
+ count: input.count
+ ))
+ guard output == expected else {
+ throw StringError("Metal kernel produced unexpected output: \(output)")
+ }
+}
diff --git a/Examples/DemoMetal/Sources/DemoMetal/shaders.metal b/Examples/DemoMetal/Sources/DemoMetal/shaders.metal
new file mode 100644
index 00000000..368692ad
--- /dev/null
+++ b/Examples/DemoMetal/Sources/DemoMetal/shaders.metal
@@ -0,0 +1,10 @@
+#include
+using namespace metal;
+
+kernel void xtool_verify(
+ device const uint *input [[buffer(0)]],
+ device uint *output [[buffer(1)]],
+ uint id [[thread_position_in_grid]]
+) {
+ output[id] = input[id] * input[id] + 0x5854; // "XT"
+}
diff --git a/Examples/DemoMetal/xtool.yml b/Examples/DemoMetal/xtool.yml
new file mode 100644
index 00000000..f4c1f3b5
--- /dev/null
+++ b/Examples/DemoMetal/xtool.yml
@@ -0,0 +1,2 @@
+version: 1
+orgID: sh.xtool.examples
diff --git a/Examples/DemoPlugin/Package.swift b/Examples/DemoPlugin/Package.swift
new file mode 100644
index 00000000..6298ee10
--- /dev/null
+++ b/Examples/DemoPlugin/Package.swift
@@ -0,0 +1,41 @@
+// swift-tools-version: 6.0
+
+import PackageDescription
+
+let package = Package(
+ name: "DemoPlugin",
+ platforms: [
+ .iOS(.v17),
+ .macOS(.v14),
+ ],
+ products: [
+ .library(
+ name: "DemoPlugin",
+ targets: ["DemoPlugin"]
+ ),
+ ],
+ dependencies: [
+ .package(path: "../ExampleSupport"),
+ ],
+ targets: [
+ .executableTarget(
+ name: "GreetingGenerator"
+ ),
+ .plugin(
+ name: "GreetingPlugin",
+ capability: .buildTool(),
+ dependencies: [
+ "GreetingGenerator",
+ ]
+ ),
+ .target(
+ name: "DemoPlugin",
+ dependencies: [
+ "ExampleSupport",
+ ],
+ plugins: [
+ "GreetingPlugin",
+ ]
+ ),
+ ]
+)
diff --git a/Examples/DemoPlugin/Plugins/GreetingPlugin/GreetingPlugin.swift b/Examples/DemoPlugin/Plugins/GreetingPlugin/GreetingPlugin.swift
new file mode 100644
index 00000000..cabfeef4
--- /dev/null
+++ b/Examples/DemoPlugin/Plugins/GreetingPlugin/GreetingPlugin.swift
@@ -0,0 +1,26 @@
+import PackagePlugin
+
+@main struct GreetingPlugin: BuildToolPlugin {
+ func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
+ guard let target = target.sourceModule else { return [] }
+ let inputs = target.sourceFiles.map(\.url).filter { $0.lastPathComponent == "Greeting.txt" }
+ guard let input = inputs.first else {
+ throw PluginError("\(target.name) has no Greeting.txt")
+ }
+ let output = context.pluginWorkDirectoryURL.appending(path: "Greeting.swift")
+ return [
+ .buildCommand(
+ displayName: "Generating Greeting.swift",
+ executable: try context.tool(named: "GreetingGenerator").url,
+ arguments: [input.path(), output.path()],
+ inputFiles: [input],
+ outputFiles: [output]
+ ),
+ ]
+ }
+}
+
+struct PluginError: Error, CustomStringConvertible {
+ let description: String
+ init(_ description: String) { self.description = description }
+}
diff --git a/Examples/DemoPlugin/README.md b/Examples/DemoPlugin/README.md
new file mode 100644
index 00000000..985d577b
--- /dev/null
+++ b/Examples/DemoPlugin/README.md
@@ -0,0 +1,5 @@
+# DemoPlugin
+
+Validates that build tool plugins work.
+
+`GreetingPlugin` runs `GreetingGenerator` to turn `Greeting.txt` into Swift source, which the app checks at runtime.
diff --git a/Examples/DemoPlugin/Sources/DemoPlugin/App.swift b/Examples/DemoPlugin/Sources/DemoPlugin/App.swift
new file mode 100644
index 00000000..b675d4f1
--- /dev/null
+++ b/Examples/DemoPlugin/Sources/DemoPlugin/App.swift
@@ -0,0 +1,34 @@
+import ExampleSupport
+import SwiftUI
+
+@main struct DemoApp: App {
+ public var body: some Scene {
+ WindowGroup {
+ ContentView()
+ }
+ }
+}
+
+private struct ContentView: View {
+ var body: some View {
+ Text(generatedGreeting)
+ .padding()
+ .task {
+ do {
+ try verify()
+ Example.pass()
+ } catch {
+ print("Test failed: \(error)")
+ exit(1)
+ }
+ }
+ }
+}
+
+private func verify() throws {
+ // generated by GreetingPlugin from Greeting.txt
+ let expected = "Hello from a build tool plugin"
+ guard generatedGreeting == expected else {
+ throw StringError("Expected greeting \(String(reflecting: expected)), got \(String(reflecting: generatedGreeting))")
+ }
+}
diff --git a/Examples/DemoPlugin/Sources/DemoPlugin/Greeting.txt b/Examples/DemoPlugin/Sources/DemoPlugin/Greeting.txt
new file mode 100644
index 00000000..26d37912
--- /dev/null
+++ b/Examples/DemoPlugin/Sources/DemoPlugin/Greeting.txt
@@ -0,0 +1 @@
+Hello from a build tool plugin
diff --git a/Examples/DemoPlugin/Sources/GreetingGenerator/main.swift b/Examples/DemoPlugin/Sources/GreetingGenerator/main.swift
new file mode 100644
index 00000000..7f18be57
--- /dev/null
+++ b/Examples/DemoPlugin/Sources/GreetingGenerator/main.swift
@@ -0,0 +1,11 @@
+import Foundation
+
+let arguments = CommandLine.arguments
+guard arguments.count == 3 else {
+ FileHandle.standardError.write(Data("usage: \(arguments[0])