Skip to content

WebAssembly Support #2640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/Build/ManifestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,12 @@ extension LLBuildManifestBuilder {
private func addModuleWrapCmd(_ target: SwiftTargetBuildDescription) {
// Add commands to perform the module wrapping Swift modules when debugging statergy is `modulewrap`.
guard buildParameters.debuggingStrategy == .modulewrap else { return }
let moduleWrapArgs = [
var moduleWrapArgs = [
target.buildParameters.toolchain.swiftCompiler.pathString,
"-modulewrap", target.moduleOutputPath.pathString,
"-o", target.wrappedModuleOutputPath.pathString
]
moduleWrapArgs += buildParameters.targetTripleArgs(for: target.target)
manifest.addShellCmd(
name: target.wrappedModuleOutputPath.pathString,
description: "Wrapping AST for \(target.target.name) for debugging",
Expand Down
4 changes: 4 additions & 0 deletions Sources/PackageDescription/SupportedPlatforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public struct Platform: Encodable {
/// The Android platform
@available(_PackageDescription, introduced: 5.2)
public static let android: Platform = Platform(name: "android")

/// The WASI platform
@available(_PackageDescription, introduced: 999.0)
public static let wasi: Platform = Platform(name: "wasi")
}

/// A platform that the Swift package supports.
Expand Down
4 changes: 3 additions & 1 deletion Sources/PackageModel/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class PlatformRegistry {

/// The static list of known platforms.
private static var _knownPlatforms: [Platform] {
return [.macOS, .iOS, .tvOS, .watchOS, .linux, .android]
return [.macOS, .iOS, .tvOS, .watchOS, .linux, .android, .wasi]
}
}

Expand Down Expand Up @@ -57,6 +57,8 @@ public struct Platform: Equatable, Hashable {
public static let linux: Platform = Platform(name: "linux", oldestSupportedVersion: .unknown)
public static let android: Platform = Platform(name: "android", oldestSupportedVersion: .unknown)
public static let windows: Platform = Platform(name: "windows", oldestSupportedVersion: .unknown)
public static let wasi: Platform = Platform(name: "wasi", oldestSupportedVersion: .unknown)

}

/// Represents a platform version.
Expand Down
2 changes: 2 additions & 0 deletions Sources/SPMBuildCore/BuildParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public struct BuildParameters: Encodable {
return .macOS
} else if self.triple.isAndroid() {
return .android
} else if self.triple.isWASI() {
return .wasi
} else {
return .linux
}
Expand Down
13 changes: 12 additions & 1 deletion Sources/SPMBuildCore/Triple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public struct Triple: Encodable, Equatable {
case aarch64
case armv7
case arm
case wasm32
}

public enum Vendor: String, Encodable {
Expand All @@ -52,12 +53,14 @@ public struct Triple: Encodable, Equatable {
case macOS = "macosx"
case linux
case windows
case wasi

fileprivate static let allKnown:[OS] = [
.darwin,
.macOS,
.linux,
.windows
.windows,
.wasi,
]
}

Expand Down Expand Up @@ -125,6 +128,10 @@ public struct Triple: Encodable, Equatable {
return os == .windows
}

public func isWASI() -> Bool {
return os == .wasi
}

/// Returns the triple string for the given platform version.
///
/// This is currently meant for Apple platforms only.
Expand Down Expand Up @@ -165,6 +172,8 @@ extension Triple {
return ".so"
case .windows:
return ".dll"
case .wasi:
fatalError("WebAssembly/WASI doesn't support dynamic library yet")
}
}

Expand All @@ -174,6 +183,8 @@ extension Triple {
return ""
case .linux:
return ""
case .wasi:
return ""
case .windows:
return ".exe"
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2130,14 +2130,14 @@ final class BuildPlanTests: XCTestCase {
inputs: ["/path/to/build/debug/exe.swiftmodule"]
outputs: ["/path/to/build/debug/exe.build/exe.swiftmodule.o"]
description: "Wrapping AST for exe for debugging"
args: ["/fake/path/to/swiftc","-modulewrap","/path/to/build/debug/exe.swiftmodule","-o","/path/to/build/debug/exe.build/exe.swiftmodule.o"]
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"]

"/path/to/build/debug/lib.build/lib.swiftmodule.o":
tool: shell
inputs: ["/path/to/build/debug/lib.swiftmodule"]
outputs: ["/path/to/build/debug/lib.build/lib.swiftmodule.o"]
description: "Wrapping AST for lib for debugging"
args: ["/fake/path/to/swiftc","-modulewrap","/path/to/build/debug/lib.swiftmodule","-o","/path/to/build/debug/lib.build/lib.swiftmodule.o"]
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"]
"""))
}
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/PackageLoadingTests/PackageBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,7 @@ class PackageBuilderTests: XCTestCase {
"tvos": "9.0",
"watchos": "2.0",
"android": "0.0",
"wasi": "0.0",
]

PackageBuilderTester(manifest, in: fs) { package, _ in
Expand Down Expand Up @@ -1560,6 +1561,7 @@ class PackageBuilderTests: XCTestCase {
"ios": "8.0",
"watchos": "2.0",
"android": "0.0",
"wasi": "0.0",
]

PackageBuilderTester(manifest, in: fs) { package, _ in
Expand Down