Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions Sources/MacOSPlatform/MacOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,35 @@ public struct MacOS: Platform {
}

public func verifySystemPrerequisitesForInstall(
_: SwiftlyCoreContext, platformName _: String, version _: ToolchainVersion,
_ ctx: SwiftlyCoreContext, platformName _: String, version _: ToolchainVersion,
requireSignatureValidation _: Bool
) async throws -> String? {
// All system prerequisites should be there for macOS
nil
// Ensure that there is in fact a macOS SDK installed so the toolchain is usable.
let result = try await run(
.path(SystemPackage.FilePath("/usr/bin/xcrun")),
arguments: ["--show-sdk-path", "--sdk", "macosx"],
output: .string(limit: 1024 * 10)
)

// Simply print warnings to the user stdout rather than returning a shell script, as there is not a simple
// shell script for installing developer tools on macOS.
if !result.terminationStatus.isSuccess {
await ctx.print("""
\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:
xcode-select --install

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:
sudo xcode-select --switch path/to/Xcode.app\n
""")
}

let sdkPath = result.standardOutput?.replacingOccurrences(of: "\n", with: "")

if sdkPath == nil {
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.")
}

return nil
}

public func install(
Expand Down