Skip to content

Commit 20ceb47

Browse files
Ensure the macOS SDK exists at install time (#480)
* Ensure the macOS SDK exists at install time * update warning messaging * remove backticks
1 parent 41fedd2 commit 20ceb47

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

Sources/MacOSPlatform/MacOS.swift

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,35 @@ public struct MacOS: Platform {
4848
}
4949

5050
public func verifySystemPrerequisitesForInstall(
51-
_: SwiftlyCoreContext, platformName _: String, version _: ToolchainVersion,
51+
_ ctx: SwiftlyCoreContext, platformName _: String, version _: ToolchainVersion,
5252
requireSignatureValidation _: Bool
5353
) async throws -> String? {
54-
// All system prerequisites should be there for macOS
55-
nil
54+
// Ensure that there is in fact a macOS SDK installed so the toolchain is usable.
55+
let result = try await run(
56+
.path(SystemPackage.FilePath("/usr/bin/xcrun")),
57+
arguments: ["--show-sdk-path", "--sdk", "macosx"],
58+
output: .string(limit: 1024 * 10)
59+
)
60+
61+
// Simply print warnings to the user stdout rather than returning a shell script, as there is not a simple
62+
// shell script for installing developer tools on macOS.
63+
if !result.terminationStatus.isSuccess {
64+
await ctx.print("""
65+
\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:
66+
xcode-select --install
67+
68+
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:
69+
sudo xcode-select --switch path/to/Xcode.app\n
70+
""")
71+
}
72+
73+
let sdkPath = result.standardOutput?.replacingOccurrences(of: "\n", with: "")
74+
75+
if sdkPath == nil {
76+
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.")
77+
}
78+
79+
return nil
5680
}
5781

5882
public func install(

0 commit comments

Comments
 (0)