Skip to content

Commit 6b533b3

Browse files
committed
Add cross-compilation regression test
Feedback More cleanup Allow skipping canSwiftPMCompileForIOS on CI Format
1 parent b5a9769 commit 6b533b3

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,34 @@ package actor SkipUnless {
477477
}
478478
}
479479

480+
package static func canSwiftPMCompileForIOS(
481+
file: StaticString = #filePath,
482+
line: UInt = #line
483+
) async throws {
484+
return try await shared.skipUnlessSupported(allowSkippingInCI: true, file: file, line: line) {
485+
#if os(macOS)
486+
let project = try await SwiftPMTestProject(files: [
487+
"MyFile.swift": """
488+
public func foo() {}
489+
"""
490+
])
491+
do {
492+
try await SwiftPMTestProject.build(
493+
at: project.scratchDirectory,
494+
extraArguments: [
495+
"--swift-sdk", "arm64-apple-ios",
496+
]
497+
)
498+
return .featureSupported
499+
} catch {
500+
return .featureUnsupported(skipMessage: "Cannot build for iOS: \(error)")
501+
}
502+
#else
503+
return .featureUnsupported(skipMessage: "Cannot build for iOS outside macOS by default")
504+
#endif
505+
}
506+
}
507+
480508
package static func canCompileForWasm(
481509
file: StaticString = #filePath,
482510
line: UInt = #line

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)