From ec6efc260533dfe02f0634912048e1547193c5fd Mon Sep 17 00:00:00 2001 From: dawn <90008@klbr.net> Date: Wed, 16 Sep 2026 05:16:04 +0300 Subject: [PATCH] fix(swift): resolve libusage.a from this package, not from the builder's directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The manifest linked `../zig-out/lib/libusage.a`, which is only correct when this package is the root one being built: consumed as a dependency, SwiftPM resolves the relative path against the *consumer's* directory and the link fails with "no such file or directory". The tray is the first consumer, so the path is now absolute, computed in the manifest from `#filePath` — the manifest always knows where it lives, whatever is building it. Verified both ways: `swift run --package-path swift usage-smoke tests/fixtures` here, and a throwaway package that depends on `../usage-core/swift` and prints `abi=3 providers=8`. --- swift/Package.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/swift/Package.swift b/swift/Package.swift index 3430427..01ce9da 100644 --- a/swift/Package.swift +++ b/swift/Package.swift @@ -1,4 +1,5 @@ // swift-tools-version: 5.9 +import Foundation import PackageDescription // Wraps the Zig usage core for native hosts. Build the library first: @@ -9,6 +10,15 @@ import PackageDescription // 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)], @@ -22,13 +32,13 @@ let package = Package( name: "UsageCore", dependencies: ["CUsage"], path: "Sources/UsageCore", - linkerSettings: [.unsafeFlags(["../zig-out/lib/libusage.a"])] + linkerSettings: [.unsafeFlags([staticLibrary])] ), .executableTarget( name: "UsageSmoke", dependencies: ["UsageCore"], path: "Sources/UsageSmoke", - linkerSettings: [.unsafeFlags(["../zig-out/lib/libusage.a"])] + linkerSettings: [.unsafeFlags([staticLibrary])] ), ] ) -- 2.51.2