Skip to content

Commit

Permalink
Add wasm32 and wasi variant
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Mar 5, 2020
1 parent d9fe1d1 commit 2548c5e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
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: 5.2)
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

0 comments on commit 2548c5e

Please sign in to comment.