Skip to content

Commit bd9e230

Browse files
committed
Update package traits
This prevents HTML5 dependencies from being checked out and compiled when using Xcode. Xcode selectively ignores Swift Package Manager target conditionals, including traits. But since Xcode ignores traits, we get the expected behavior if the trait is not present which is true for HTML5 when using Xcode.
1 parent a2bbb65 commit bd9e230

File tree

1 file changed

+56
-48
lines changed

1 file changed

+56
-48
lines changed

Package.swift

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,51 @@ let package = Package(
1515
.default(enabledTraits: ["SIMD"]),
1616

1717
.trait(
18-
name: "SIMD",
19-
description: "Enables SIMD acceleration when available. Note: Debug builds may skip SIMD, as without optimization SIMD hardware won't be used."
18+
name: "SIMD",
19+
description: "Enables SIMD acceleration when available."
2020
),
2121
.trait(
22-
name: "HTML5",
23-
description: "Configures GateEngine for WebAssembly builds using the SwiftWASM project. Note: Building works in IDE, for cenvenince. But running requires building for WASI."
22+
name: "HTML5",
23+
description: "Configures GateEngine for WebAssembly builds using the SwiftWASM project."
2424
),
2525
],
2626
dependencies: {
2727
var packageDependencies: [Package.Dependency] = []
2828

2929
// Official
30-
packageDependencies.append(contentsOf: {
31-
var official: [Package.Dependency] = []
32-
#if os(Windows)
33-
// Windows requires 1.2.0+
34-
official.append(.package(url: "https://github.com/apple/swift-atomics.git", .upToNextMajor(from: "1.2.0")))
35-
#else
36-
// swift-atomics must use extact 1.1.0 pending https://github.com/apple/swift/issues/69264
37-
official.append(.package(url: "https://github.com/apple/swift-atomics.git", exact: "1.1.0"))
38-
#endif
39-
official.append(.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0"))
40-
return official
41-
}())
42-
43-
44-
packageDependencies.append(
45-
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.0"))
46-
)
47-
48-
// SwiftWASM
4930
packageDependencies.append(contentsOf: [
50-
.package(url: "https://github.com/swiftwasm/WebAPIKit.git", .upToNextMajor(from: "0.1.0")),
51-
.package(url: "https://github.com/swiftwasm/JavaScriptKit.git", .upToNextMajor(from: "0.16.0")),
31+
.package(url: "https://github.com/apple/swift-atomics.git", .upToNextMajor(from: "1.2.0")),
32+
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.2.0")),
33+
.package(url: "https://github.com/apple/swift-syntax", from: "601.0.0"),
5234
])
5335

54-
// Linting / Formating
36+
#if false // Linting / Formating
5537
packageDependencies.append(contentsOf: [
56-
//.package(url: "https://github.com/apple/swift-format", .upToNextMajor(from: "509.0.0")),
57-
//.package(url: "https://github.com/realm/SwiftLint.git", .upToNextMajor(from: "0.52.0")),
38+
.package(url: "https://github.com/apple/swift-format", from: "601.0.0"),
5839
])
40+
#endif
41+
42+
#if HTML5 // SwiftWASM
43+
// Replace swift-atomics with an explicit version pending:
44+
// https://github.com/apple/swift/issues/69264
45+
packageDependencies.removeAll(where: {
46+
if case .sourceControl(name: let name, location: "https://github.com/apple/swift-atomics.git", requirement: _) = $0.kind {
47+
return true
48+
}
49+
return false
50+
})
51+
packageDependencies.append(
52+
.package(url: "https://github.com/apple/swift-atomics.git", exact: "1.1.0"),
53+
)
54+
packageDependencies.append(contentsOf: [
55+
.package(url: "https://github.com/swiftwasm/WebAPIKit.git", .upToNextMajor(from: "0.1.0"), traits: [
56+
.trait(name: "HTML5", condition: .when(traits: ["HTML5"]))
57+
]),
58+
.package(url: "https://github.com/swiftwasm/JavaScriptKit.git", .upToNextMajor(from: "0.16.0"), traits: [
59+
.trait(name: "HTML5", condition: .when(traits: ["HTML5"]))
60+
]),
61+
])
62+
#endif
5963

6064
return packageDependencies
6165
}(),
@@ -115,26 +119,28 @@ let package = Package(
115119
package: "swift-collections")
116120
])
117121

122+
#if HTML5
118123
dependencies.append(contentsOf: [
119124
.product(name: "JavaScriptEventLoop",
120125
package: "JavaScriptKit",
121-
condition: .when(traits: ["HTML5"])),
126+
condition: .whenHTML5),
122127
.product(name: "DOM",
123128
package: "WebAPIKit",
124-
condition: .when(traits: ["HTML5"])),
129+
condition: .whenHTML5),
125130
.product(name: "FileSystem",
126131
package: "WebAPIKit",
127-
condition: .when(traits: ["HTML5"])),
132+
condition: .whenHTML5),
128133
.product(name: "WebAudio",
129134
package: "WebAPIKit",
130-
condition: .when(traits: ["HTML5"])),
135+
condition: .whenHTML5),
131136
.product(name: "Gamepad",
132137
package: "WebAPIKit",
133-
condition: .when(traits: ["HTML5"])),
138+
condition: .whenHTML5),
134139
.product(name: "WebGL2",
135140
package: "WebAPIKit",
136-
condition: .when(traits: ["HTML5"])),
141+
condition: .whenHTML5),
137142
])
143+
#endif
138144

139145
return dependencies
140146
}(),
@@ -188,12 +194,10 @@ let package = Package(
188194
.when(platforms: .any(except: .wasi))),
189195
])
190196

191-
#if HTML5
192197
// Options for development of WASI platform
193198
settings.append(contentsOf: [
194-
.define("GATEENGINE_PLATFORM_EVENT_DRIVEN", .when(platforms: [.macOS, .linux, .wasi])),
199+
.define("GATEENGINE_PLATFORM_EVENT_DRIVEN", .when(traits: ["HTML5"])),
195200
])
196-
#endif
197201

198202
#if false // Options for development of GateEngine. These should be disabled for tagged version releases.
199203
#warning("GateEngine development options are enabled. These can cause strange build errors on some platforms.")
@@ -217,14 +221,16 @@ let package = Package(
217221
//.plugin(name: "SwiftLintPlugin", package: "SwiftLint"),
218222
]),
219223

220-
.target(name: "Shaders",
221-
dependencies: [
222-
"GameMath",
223-
.product(name: "Collections", package: "swift-collections")
224-
],
225-
swiftSettings: .default(withCustomization: { settings in
226-
settings.append(.define("GATEENGINE_DEBUG_SHADERS", .when(configuration: .debug)))
227-
})),
224+
.target(
225+
name: "Shaders",
226+
dependencies: [
227+
"GameMath",
228+
.product(name: "Collections", package: "swift-collections")
229+
],
230+
swiftSettings: .default(withCustomization: { settings in
231+
settings.append(.define("GATEENGINE_DEBUG_SHADERS", .when(configuration: .debug)))
232+
})
233+
),
228234

229235
.target(name: "GameMath", swiftSettings: .default(withCustomization: { settings in
230236
#if false
@@ -234,10 +240,8 @@ let package = Package(
234240
#endif
235241

236242
// These settings are faster only with optimization.
237-
#if true
238243
settings.append(.define("GameMathUseSIMD", .when(configuration: .release, traits: ["SIMD"])))
239-
settings.append(.define("GameMathUseLoopVectorization", .when(configuration: .release)))
240-
#endif
244+
settings.append(.define("GameMathUseLoopVectorization", .when(configuration: .release, traits: ["SIMD"])))
241245
})),
242246
])
243247

@@ -762,3 +766,7 @@ extension Array where Element == SwiftSetting {
762766
return settings.isEmpty ? nil : settings
763767
}
764768
}
769+
770+
extension PackageDescription.TargetDependencyCondition {
771+
static var whenHTML5: Self? {.when(platforms: [.wasi], traits: ["HTML5"])}
772+
}

0 commit comments

Comments
 (0)