Skip to content

Commit 5784bf8

Browse files
authored
Merge pull request #1538 from ahoppen/skip-wasm-test
Skip `testWasm` if the host toolchain can’t build for WASM
2 parents 1efb267 + ab67a7e commit 5784bf8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,35 @@ public actor SkipUnless {
462462
}
463463
}
464464
}
465+
466+
public static func canCompileForWasm(
467+
file: StaticString = #filePath,
468+
line: UInt = #line
469+
) async throws {
470+
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
471+
let swiftFrontend = try await unwrap(ToolchainRegistry.forTesting.default?.swift).parentDirectory
472+
.appending(component: "swift-frontend")
473+
return try await withTestScratchDir { scratchDirectory in
474+
let input = scratchDirectory.appending(component: "Input.swift")
475+
FileManager.default.createFile(atPath: input.pathString, contents: nil)
476+
// If we can't compile for wasm, this fails complaining that it can't find the stdlib for wasm.
477+
let process = Process(
478+
args: swiftFrontend.pathString,
479+
"-typecheck",
480+
input.pathString,
481+
"-triple",
482+
"wasm32-unknown-none-wasm",
483+
"-enable-experimental-feature",
484+
"Embedded",
485+
"-Xcc",
486+
"-fdeclspec"
487+
)
488+
try process.launch()
489+
let result = try await process.waitUntilExit()
490+
return result.exitStatus == .terminated(code: 0)
491+
}
492+
}
493+
}
465494
}
466495

467496
// MARK: - Parsing Swift compiler version

Tests/SourceKitLSPTests/SwiftPMIntegration.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ final class SwiftPMIntegrationTests: XCTestCase {
243243
}
244244

245245
func testWasm() async throws {
246+
try await SkipUnless.canCompileForWasm()
247+
246248
let project = try await SwiftPMTestProject(
247249
files: [
248250
"/.sourcekit-lsp/config.json": """

0 commit comments

Comments
 (0)