From 87cbd1ee8a17eb2a4c9b07382c34f08d5eaa35a0 Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Fri, 11 Apr 2025 10:13:36 -0400 Subject: [PATCH 1/2] Add SDKROOT when proxying on macOS based on xcrun information --- Sources/SwiftlyCore/Platform.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index 2d06ee01..1d5d2963 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -200,6 +200,16 @@ extension Platform { for (key, value) in env { newEnv[key] = value } + +#if os(macOS) + // On macOS, we try to set SDKROOT if its empty for tools like clang++ that need it to + // find standard libraries that aren't in the toolchain, like libc++. Here we + // use xcrun to tell us what the default sdk root should be. + if newEnv["SDKROOT"] == nil { + newEnv["SDKROOT"] = (try? await self.runProgramOutput("/usr/bin/xcrun", "--show-sdk-path")) + } +#endif + try self.runProgram([command] + arguments, env: newEnv) } From 85c6ac9e8f525745fcf40bc6489b328698db555a Mon Sep 17 00:00:00 2001 From: Chris McGee Date: Tue, 15 Apr 2025 14:54:21 -0400 Subject: [PATCH 2/2] Strip newlines from xcrun output --- Sources/SwiftlyCore/Platform.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index e267345f..f3b62a58 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -215,7 +215,7 @@ extension Platform { // find standard libraries that aren't in the toolchain, like libc++. Here we // use xcrun to tell us what the default sdk root should be. if newEnv["SDKROOT"] == nil { - newEnv["SDKROOT"] = (try? await self.runProgramOutput("/usr/bin/xcrun", "--show-sdk-path")) + newEnv["SDKROOT"] = (try? await self.runProgramOutput("/usr/bin/xcrun", "--show-sdk-path"))?.replacingOccurrences(of: "\n", with: "") } #endif