Skip to content

Commit 4cfbe41

Browse files
gmittertaciidgh
authored andcommitted
Add Windows as a Supported Platform
Gated behind version 5.2. This will allow for example, Windows specific c/cxx flags to be passed to build indexstoredb and llbuild.
1 parent c43b137 commit 4cfbe41

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Sources/PackageDescription4/SupportedPlatforms.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public struct Platform: Encodable {
3333

3434
/// The Linux platform.
3535
public static let linux: Platform = Platform(name: "linux")
36+
37+
/// The Windows platform
38+
@available(_PackageDescription, introduced: 5.2)
39+
public static let windows: Platform = Platform(name: "windows")
3640
}
3741

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

Tests/PackageLoadingTests/PD5LoadingTests.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,49 @@ class PackageDescription5LoadingTests: XCTestCase {
454454
XCTAssertEqual(resources[1], TargetDescription.Resource(rule: .process, path: "bar.txt"))
455455
}
456456
}
457+
458+
func testWindowsPlatform() throws {
459+
let stream = BufferedOutputByteStream()
460+
stream <<< """
461+
import PackageDescription
462+
let package = Package(
463+
name: "Foo",
464+
targets: [
465+
.target(
466+
name: "foo",
467+
cSettings: [
468+
.define("LLVM_ON_WIN32", .when(platforms: [.windows])),
469+
]
470+
),
471+
]
472+
)
473+
"""
474+
475+
do {
476+
try loadManifestThrowing(stream.bytes) { _ in }
477+
XCTFail("Unexpected success")
478+
} catch {
479+
guard case let ManifestParseError.invalidManifestFormat(message, _) = error else {
480+
return XCTFail("\(error)")
481+
}
482+
483+
XCTAssertMatch(message, .contains("is unavailable"))
484+
XCTAssertMatch(message, .contains("was introduced in PackageDescription 5.2"))
485+
}
486+
487+
loadManifest(stream.bytes, toolsVersion: .v5_2) { manifest in
488+
XCTAssertEqual(manifest.name, "Foo")
489+
490+
// Check targets.
491+
let targets = Dictionary(items:
492+
manifest.targets.map({ ($0.name, $0 as TargetDescription ) }))
493+
let foo = targets["foo"]!
494+
XCTAssertEqual(foo.name, "foo")
495+
XCTAssertFalse(foo.isTest)
496+
XCTAssertEqual(foo.dependencies, [])
497+
498+
let settings = manifest.targets[0].settings
499+
XCTAssertEqual(settings[0], .init(tool: .c, name: .define, value: ["LLVM_ON_WIN32"], condition: .init(platformNames: ["windows"])))
500+
}
501+
}
457502
}

0 commit comments

Comments
 (0)