// swift-tools-version: 5.9
import Foundation
import PackageDescription
// Wraps the Zig usage core for native hosts. Build the library first:
// zig build (repo root, produces zig-out/lib/libusage.a)
// then:
// swift build --package-path swift
//
// The core does no I/O: it builds the requests and parses the responses, and UsageDriver feeds it
// through URLSession. That is the whole point of the split — TLS, proxies and HTTP/2 stay with the
// host, and the rules stay in one place shared with the CLI.
//
// The path to libusage.a is absolute because this package is also consumed as a dependency: a
// relative path would be resolved against whoever is building, not against this directory.
let packageRoot = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent() // the manifest
.deletingLastPathComponent() // swift/
.path
let staticLibrary = "\(packageRoot)/zig-out/lib/libusage.a"
let package = Package(
name: "UsageCore",
platforms: [.macOS(.v13)],
products: [
.library(name: "UsageCore", targets: ["UsageCore"]),
.executable(name: "usage-smoke", targets: ["UsageSmoke"]),
],
targets: [
.systemLibrary(name: "CUsage", path: "Sources/CUsage"),
.target(
name: "UsageCore",
dependencies: ["CUsage"],
path: "Sources/UsageCore",
linkerSettings: [.unsafeFlags([staticLibrary])]
),
.executableTarget(
name: "UsageSmoke",
dependencies: ["UsageCore"],
path: "Sources/UsageSmoke",
linkerSettings: [.unsafeFlags([staticLibrary])]
),
]
)