Skip to content

Commit 714cc4e

Browse files
[Cherry-pick] Ensure the macOS SDK exists at install time (#481)
* Ensure the macOS SDK exists at install time (#480) * Ensure the macOS SDK exists at install time * update warning messaging * remove backticks (cherry picked from commit 20ceb47) * Fix SDK logic for 1.1
1 parent 1843811 commit 714cc4e

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

Sources/MacOSPlatform/MacOS.swift

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,32 @@ public struct MacOS: Platform {
4747
}
4848

4949
public func verifySystemPrerequisitesForInstall(
50-
_: SwiftlyCoreContext, platformName _: String, version _: ToolchainVersion,
50+
_ ctx: SwiftlyCoreContext, platformName _: String, version _: ToolchainVersion,
5151
requireSignatureValidation _: Bool
5252
) async throws -> String? {
53-
// All system prerequisites should be there for macOS
54-
nil
53+
// Ensure that there is in fact a macOS SDK installed so the toolchain is usable.
54+
guard let result = try await self.runProgramOutput(
55+
"/usr/bin/xcrun", "--show-sdk-path", "--sdk", "macosx"
56+
) else {
57+
// Simply print warnings to the user stdout rather than returning a shell script, as there is not a simple
58+
// shell script for installing developer tools on macOS.
59+
await ctx.print("""
60+
\nWARNING: Could not find a macOS SDK on the system. A macOS SDK is required for the toolchain to work correctly. Please install one via Xcode (https://developer.apple.com/xcode) or run the following command on your machine to install the Command Line Tools for Xcode:
61+
xcode-select --install
62+
63+
More information on installing the Command Line Tools can be found here: https://developer.apple.com/documentation/xcode/installing-the-command-line-tools/#Install-the-Command-Line-Tools-package-in-Terminal. If developer tools are located at a non-default location on disk, use the following command to specify the Xcode that you wish to use for Command Line Tools for Xcode:
64+
sudo xcode-select --switch path/to/Xcode.app\n
65+
""")
66+
return nil
67+
}
68+
69+
let sdkPath = result.replacingOccurrences(of: "\n", with: "")
70+
71+
if sdkPath == nil {
72+
await ctx.print("WARNING: Could not read output of '/usr/bin/xcrun --show-sdk-path --sdk macosx'. Ensure your macOS SDK is installed properly for the swift toolchain to work.")
73+
}
74+
75+
return nil
5576
}
5677

5778
public func install(

0 commit comments

Comments
 (0)