Skip to content

Commit d341579

Browse files
authored
Merge pull request #2640 from kateinoigakukun/katei/wasm-support
WebAssembly Support
2 parents 6422633 + 9ed7dee commit d341579

File tree

7 files changed

+27
-5
lines changed

7 files changed

+27
-5
lines changed

Sources/Build/ManifestBuilder.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,12 @@ extension LLBuildManifestBuilder {
339339
private func addModuleWrapCmd(_ target: SwiftTargetBuildDescription) {
340340
// Add commands to perform the module wrapping Swift modules when debugging statergy is `modulewrap`.
341341
guard buildParameters.debuggingStrategy == .modulewrap else { return }
342-
let moduleWrapArgs = [
342+
var moduleWrapArgs = [
343343
target.buildParameters.toolchain.swiftCompiler.pathString,
344344
"-modulewrap", target.moduleOutputPath.pathString,
345345
"-o", target.wrappedModuleOutputPath.pathString
346346
]
347+
moduleWrapArgs += buildParameters.targetTripleArgs(for: target.target)
347348
manifest.addShellCmd(
348349
name: target.wrappedModuleOutputPath.pathString,
349350
description: "Wrapping AST for \(target.target.name) for debugging",

Sources/PackageDescription/SupportedPlatforms.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public struct Platform: Encodable {
4141
/// The Android platform
4242
@available(_PackageDescription, introduced: 5.2)
4343
public static let android: Platform = Platform(name: "android")
44+
45+
/// The WASI platform
46+
@available(_PackageDescription, introduced: 999.0)
47+
public static let wasi: Platform = Platform(name: "wasi")
4448
}
4549

4650
/// A platform that the Swift package supports.

Sources/PackageModel/Platform.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public final class PlatformRegistry {
2929

3030
/// The static list of known platforms.
3131
private static var _knownPlatforms: [Platform] {
32-
return [.macOS, .iOS, .tvOS, .watchOS, .linux, .android]
32+
return [.macOS, .iOS, .tvOS, .watchOS, .linux, .android, .wasi]
3333
}
3434
}
3535

@@ -57,6 +57,8 @@ public struct Platform: Equatable, Hashable {
5757
public static let linux: Platform = Platform(name: "linux", oldestSupportedVersion: .unknown)
5858
public static let android: Platform = Platform(name: "android", oldestSupportedVersion: .unknown)
5959
public static let windows: Platform = Platform(name: "windows", oldestSupportedVersion: .unknown)
60+
public static let wasi: Platform = Platform(name: "wasi", oldestSupportedVersion: .unknown)
61+
6062
}
6163

6264
/// Represents a platform version.

Sources/SPMBuildCore/BuildParameters.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public struct BuildParameters: Encodable {
9999
return .macOS
100100
} else if self.triple.isAndroid() {
101101
return .android
102+
} else if self.triple.isWASI() {
103+
return .wasi
102104
} else {
103105
return .linux
104106
}

Sources/SPMBuildCore/Triple.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public struct Triple: Encodable, Equatable {
4040
case aarch64
4141
case armv7
4242
case arm
43+
case wasm32
4344
}
4445

4546
public enum Vendor: String, Encodable {
@@ -52,12 +53,14 @@ public struct Triple: Encodable, Equatable {
5253
case macOS = "macosx"
5354
case linux
5455
case windows
56+
case wasi
5557

5658
fileprivate static let allKnown:[OS] = [
5759
.darwin,
5860
.macOS,
5961
.linux,
60-
.windows
62+
.windows,
63+
.wasi,
6164
]
6265
}
6366

@@ -125,6 +128,10 @@ public struct Triple: Encodable, Equatable {
125128
return os == .windows
126129
}
127130

131+
public func isWASI() -> Bool {
132+
return os == .wasi
133+
}
134+
128135
/// Returns the triple string for the given platform version.
129136
///
130137
/// This is currently meant for Apple platforms only.
@@ -165,6 +172,8 @@ extension Triple {
165172
return ".so"
166173
case .windows:
167174
return ".dll"
175+
case .wasi:
176+
fatalError("WebAssembly/WASI doesn't support dynamic library yet")
168177
}
169178
}
170179

@@ -174,6 +183,8 @@ extension Triple {
174183
return ""
175184
case .linux:
176185
return ""
186+
case .wasi:
187+
return ""
177188
case .windows:
178189
return ".exe"
179190
}

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,14 +2130,14 @@ final class BuildPlanTests: XCTestCase {
21302130
inputs: ["/path/to/build/debug/exe.swiftmodule"]
21312131
outputs: ["/path/to/build/debug/exe.build/exe.swiftmodule.o"]
21322132
description: "Wrapping AST for exe for debugging"
2133-
args: ["/fake/path/to/swiftc","-modulewrap","/path/to/build/debug/exe.swiftmodule","-o","/path/to/build/debug/exe.build/exe.swiftmodule.o"]
2133+
args: ["/fake/path/to/swiftc","-modulewrap","/path/to/build/debug/exe.swiftmodule","-o","/path/to/build/debug/exe.build/exe.swiftmodule.o","-target","x86_64-unknown-linux-gnu"]
21342134
21352135
"/path/to/build/debug/lib.build/lib.swiftmodule.o":
21362136
tool: shell
21372137
inputs: ["/path/to/build/debug/lib.swiftmodule"]
21382138
outputs: ["/path/to/build/debug/lib.build/lib.swiftmodule.o"]
21392139
description: "Wrapping AST for lib for debugging"
2140-
args: ["/fake/path/to/swiftc","-modulewrap","/path/to/build/debug/lib.swiftmodule","-o","/path/to/build/debug/lib.build/lib.swiftmodule.o"]
2140+
args: ["/fake/path/to/swiftc","-modulewrap","/path/to/build/debug/lib.swiftmodule","-o","/path/to/build/debug/lib.build/lib.swiftmodule.o","-target","x86_64-unknown-linux-gnu"]
21412141
"""))
21422142
}
21432143
}

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,7 @@ class PackageBuilderTests: XCTestCase {
15241524
"tvos": "9.0",
15251525
"watchos": "2.0",
15261526
"android": "0.0",
1527+
"wasi": "0.0",
15271528
]
15281529

15291530
PackageBuilderTester(manifest, in: fs) { package, _ in
@@ -1568,6 +1569,7 @@ class PackageBuilderTests: XCTestCase {
15681569
"ios": "8.0",
15691570
"watchos": "2.0",
15701571
"android": "0.0",
1572+
"wasi": "0.0",
15711573
]
15721574

15731575
PackageBuilderTester(manifest, in: fs) { package, _ in

0 commit comments

Comments
 (0)