// swift-tools-version:5.9 // The native sink for the platforms whose native player is reached from Swift // (wai/extensions/native-sink.md): the C interface of libwai (feature `native_sink`), wrapped, // and integrated with the platform's player through a loopback relay. import Foundation import PackageDescription // `WaiFFI`, the C interface, is a binary target: a release's WaiFFI.xcframework, named by URL and // checksum. scripts/package-release.sh writes the two into the copy of this package a release // attaches (wai-sink-swift-.zip), and SwiftPM refuses an archive whose checksum is not // the one named. While scripts/build-xcframework.sh has built the framework here // (build/WaiFFI.xcframework), the target is that build instead: the repository's own tests run // against the libwai of their checkout. let release: (url: String, checksum: String)? = nil let localBuild = Context.packageDirectory + "/build/WaiFFI.xcframework" let ffi: Target if let release, !FileManager.default.fileExists(atPath: localBuild) { ffi = .binaryTarget(name: "WaiFFI", url: release.url, checksum: release.checksum) } else { ffi = .binaryTarget(name: "WaiFFI", path: "build/WaiFFI.xcframework") } let package = Package( name: "WaiSink", platforms: [.iOS(.v16), .tvOS(.v16), .macOS(.v13)], products: [ .library(name: "WaiSink", targets: ["WaiSink"]), ], targets: [ ffi, // libwai's integer decode drives the device's GPU through Metal (native-sink §13); on the // desktop its measured choice reads the GPU's energy rail through the system's IOReport // library (native-sink §13.2). .target(name: "WaiSink", dependencies: ["WaiFFI"], path: "Sources/WaiSink", linkerSettings: [.linkedFramework("Metal"), .linkedFramework("QuartzCore"), .linkedFramework("CoreGraphics"), .linkedFramework("Foundation"), .linkedLibrary("IOReport", .when(platforms: [.macOS]))]), // Resources/ holds the native sink corpus, staged by scripts/build-xcframework.sh, so the // tests read it on a device as on the desktop. .testTarget(name: "WaiSinkTests", dependencies: ["WaiSink"], path: "Tests/WaiSinkTests", resources: [.copy("Resources")]), ] )