From 29e43c4baf9354e6b428a7927f1f04af916b412f Mon Sep 17 00:00:00 2001 From: Chris McGee <87777443+cmcgee1024@users.noreply.github.com> Date: Wed, 16 Apr 2025 12:04:34 -0400 Subject: [PATCH] Add SDKROOT when proxying on macOS based on xcrun information (#316) * Strip newlines from xcrun output --- Sources/SwiftlyCore/Platform.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index 4b7291f9..0b7084e1 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -166,6 +166,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"))?.replacingOccurrences(of: "\n", with: "") + } +#endif + try self.runProgram([command] + arguments, env: newEnv) }