     var arguments = ["-frontend", "-emit-syntax"]
     arguments.append(sourceFile.path)
     #if os(macOS)
-    guard let sdk = SwiftcRunner.macOSSDK else {
-      throw InvocationError.couldNotFindSDK
-    }
     arguments.append("-sdk")
-    arguments.append(sdk)
+    arguments.append(try SwiftcRunner.getMacOSSDK())
     #endif
     return run(swiftcURL, arguments: arguments)
   }


  #if os(macOS)
  /// The location of the macOS SDK, or `nil` if it could not be found.
  private static let macOSSDK: String? = {
    let url = URL(fileURLWithPath: "/usr/bin/env")
    let result = run(url, arguments: ["xcrun", "--show-sdk-path"])
    guard result.wasSuccessful else { return nil }
    let toolPath = result.stdout.trimmingCharacters(in: .whitespacesAndNewlines)
    if toolPath.isEmpty { return nil }
    return toolPath
  }()
  #endif

  /// Internal static cache of the Swiftc path.


enum InvocationError: Error, CustomStringConvertible {
  case couldNotFindSwiftc
  case couldNotFindSDK(message: String)

  var description: String {
    switch self {
    case .couldNotFindSwiftc:
      return "could not locate swift compiler binary"
    case .couldNotFindSDK(let message):
      return "could not locate macOS SDK: \(message)"
    }
  }
}
