Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

sdk: get clang resources from swift toolchain (#274)

Kabir Oberaidf1b6fa5e972
diff --git a/Sources/PackLib/DarwinSDK.swift b/Sources/PackLib/DarwinSDK.swift
index 9d59675..cadd72d 100644
--- a/Sources/PackLib/DarwinSDK.swift
+++ b/Sources/PackLib/DarwinSDK.swift
@@ -98,14 +98,23 @@ public struct DarwinSDK {
}
private static func addHostClangResourceDir(to sdk: URL) async throws {
- let clangURL = try await ToolRegistry.locate("clang")
+ struct SwiftTargetInfo: Decodable {
+ struct Paths: Decodable {
+ let runtimeResourcePath: String
+ }
+ let paths: Paths
+ }
+
let process = try await Subprocess.run(
- .path(FilePath(clangURL.path)),
- arguments: ["-print-resource-dir"],
- output: .string(limit: .max)
+ .path(try await BuildSettings.swiftcURL()),
+ arguments: ["-print-target-info"],
+ output: .data(limit: .max)
).checkSuccess()
- let output = process.standardOutput ?? ""
- let hostClangResources = URL(filePath: output.trimmingCharacters(in: .whitespacesAndNewlines))
+ let targetInfo = try JSONDecoder().decode(
+ SwiftTargetInfo.self,
+ from: process.standardOutput
+ )
+ let hostClangResources = URL(filePath: targetInfo.paths.runtimeResourcePath).appending(path: "clang")
let hostInclude = hostClangResources.appending(path: "include")
let sdkInclude = sdk.appending(path: "Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include")
try await FileManager.default.copyItem(at: hostInclude, to: sdkInclude, preserveOwner: false)