@@ -1018,6 +1018,53 @@ final class BackgroundIndexingTests: XCTestCase {
10181018 )
10191019 }
10201020
1021+ func testUseSwiftSDKFlagsDuringPreparation( ) async throws {
1022+ try await SkipUnless . canSwiftPMCompileForIOS ( )
1023+
1024+ var options = SourceKitLSPOptions . testDefault ( )
1025+ options. swiftPMOrDefault. swiftSDK = " arm64-apple-ios "
1026+ let project = try await SwiftPMTestProject (
1027+ files: [
1028+ " Lib/Lib.swift " : """
1029+ #if os(iOS)
1030+ public func foo() -> Int { 1 }
1031+ #endif
1032+ """ ,
1033+ " Client/Client.swift " : """
1034+ import Lib
1035+
1036+ func test() -> String {
1037+ return foo()
1038+ }
1039+ """ ,
1040+ ] ,
1041+ manifest: """
1042+ let package = Package(
1043+ name: " MyLibrary " ,
1044+ targets: [
1045+ .target(name: " Lib " ),
1046+ .target(name: " Client " , dependencies: [ " Lib " ]),
1047+ ]
1048+ )
1049+ """ ,
1050+ options: options,
1051+ enableBackgroundIndexing: true
1052+ )
1053+
1054+ // Check that we get an error about the return type of `foo` (`Int`) not being convertible to the return type of
1055+ // `test` (`String`), which indicates that `Lib` had `foo` and was thus compiled for iOS
1056+ let ( uri, _) = try project. openDocument ( " Client.swift " )
1057+ let diagnostics = try await project. testClient. send (
1058+ DocumentDiagnosticsRequest ( textDocument: TextDocumentIdentifier ( uri) )
1059+ )
1060+ XCTAssert (
1061+ ( diagnostics. fullReport? . items ?? [ ] ) . contains ( where: {
1062+ $0. message == " Cannot convert return expression of type 'Int' to return type 'String' "
1063+ } ) ,
1064+ " Did not get expected diagnostic: \( diagnostics) "
1065+ )
1066+ }
1067+
10211068 func testLibraryUsedByExecutableTargetAndPackagePlugin( ) async throws {
10221069 try await SkipUnless . swiftPMStoresModulesForTargetAndHostInSeparateFolders ( )
10231070 let project = try await SwiftPMTestProject (
0 commit comments