Skip to content

Commit 0313a7c

Browse files
authored
Update WASM CI to run for wasi target (#37)
* Update WASM CI to run for wasi target * Fix swift-testing version * Add test helper target * Update warning as errors config * Fix os(WASI) build issue
1 parent ce294c1 commit 0313a7c

File tree

28 files changed

+99
-46
lines changed

28 files changed

+99
-46
lines changed

.github/workflows/wasm.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ jobs:
2525
swift-version: ${{ matrix.swift_version }}
2626
- name: build
2727
run: |
28-
swift build ${{ matrix.extra_params }}
28+
swift build --triple wasm32-unknown-wasi ${{ matrix.extra_params }}
29+
# Blocked by upstream support for WASM. See https://github.com/apple/swift-testing/issues/228
2930
# - name: test
3031
# run: |
31-
# swift test
32+
# swift test --triple wasm32-unknown-wasi ${{ matrix.extra_params }}

Package.resolved

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
77
"state" : {
88
"branch" : "main",
9-
"revision" : "8f0376278186b6e24e8d7a07a560f3efaa2fef1d"
9+
"revision" : "8cc89abc1fff74b387a083eab8ffa91f1b9fdca7"
1010
}
1111
},
1212
{

Package.swift

+47-21
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,63 @@
44
import Foundation
55
import PackageDescription
66

7-
let isXcodeEnv = ProcessInfo.processInfo.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"
7+
func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
8+
guard let value = Context.environment[key] else {
9+
return defaultValue
10+
}
11+
if value == "1" {
12+
return true
13+
} else if value == "0" {
14+
return false
15+
} else {
16+
return defaultValue
17+
}
18+
}
19+
20+
let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"
21+
822
// Xcode use clang as linker which supports "-iframework" while SwiftPM use swiftc as linker which supports "-Fsystem"
923
let systemFrameworkSearchFlag = isXcodeEnv ? "-iframework" : "-Fsystem"
1024

25+
var sharedSwiftSettings: [SwiftSetting] = [
26+
.enableExperimentalFeature("AccessLevelOnImport"),
27+
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
28+
]
29+
30+
let warningsAsErrorsCondition = envEnable("OPENSWIFTUI_WERROR", default: isXcodeEnv)
31+
if warningsAsErrorsCondition {
32+
sharedSwiftSettings.append(.unsafeFlags(["-warnings-as-errors"]))
33+
}
34+
1135
let openSwiftUITarget = Target.target(
1236
name: "OpenSwiftUI",
1337
dependencies: [
1438
"OpenSwiftUIShims",
1539
.target(name: "CoreServices", condition: .when(platforms: [.iOS])),
1640
.product(name: "OpenGraphShims", package: "OpenGraph"),
1741
],
18-
swiftSettings: [
19-
.enableExperimentalFeature("AccessLevelOnImport"),
20-
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
21-
]
42+
swiftSettings: sharedSwiftSettings
2243
)
2344
let openSwiftUITestTarget = Target.testTarget(
2445
name: "OpenSwiftUITests",
2546
dependencies: [
2647
"OpenSwiftUI",
2748
],
28-
exclude: ["README.md"]
49+
exclude: ["README.md"],
50+
swiftSettings: sharedSwiftSettings
51+
)
52+
let openSwiftUITempTestTarget = Target.testTarget(
53+
name: "OpenSwiftUITempTests",
54+
dependencies: [
55+
"OpenSwiftUI",
56+
],
57+
exclude: ["README.md"],
58+
swiftSettings: sharedSwiftSettings
2959
)
3060
let openSwiftUICompatibilityTestTarget = Target.testTarget(
3161
name: "OpenSwiftUICompatibilityTests",
32-
exclude: ["README.md"]
62+
exclude: ["README.md"],
63+
swiftSettings: sharedSwiftSettings
3364
)
3465

3566
let package = Package(
@@ -64,19 +95,6 @@ let package = Package(
6495
]
6596
)
6697

67-
func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
68-
guard let value = ProcessInfo.processInfo.environment[key] else {
69-
return defaultValue
70-
}
71-
if value == "1" {
72-
return true
73-
} else if value == "0" {
74-
return false
75-
} else {
76-
return defaultValue
77-
}
78-
}
79-
8098
#if os(macOS)
8199
let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH", default: true)
82100
#else
@@ -98,6 +116,7 @@ extension Target {
98116
if attributeGraphCondition {
99117
openSwiftUITarget.addAGSettings()
100118
openSwiftUITestTarget.addAGSettings()
119+
openSwiftUITempTestTarget.addAGSettings()
101120
openSwiftUICompatibilityTestTarget.addAGSettings()
102121
}
103122

@@ -139,12 +158,19 @@ if swiftLogCondition {
139158
let swiftTestingCondition = envEnable("OPENSWIFTUI_SWIFT_TESTING", default: true)
140159
if swiftTestingCondition {
141160
package.dependencies.append(
142-
.package(url: "https://github.com/apple/swift-testing", from: "0.3.0")
161+
// Fix it to be 0.3.0 before we bump to Swift 5.10
162+
.package(url: "https://github.com/apple/swift-testing", exact: "0.3.0")
143163
)
144164
openSwiftUITestTarget.dependencies.append(
145165
.product(name: "Testing", package: "swift-testing")
146166
)
147167
package.targets.append(openSwiftUITestTarget)
168+
169+
openSwiftUITempTestTarget.dependencies.append(
170+
.product(name: "Testing", package: "swift-testing")
171+
)
172+
package.targets.append(openSwiftUITempTestTarget)
173+
148174
openSwiftUICompatibilityTestTarget.dependencies.append(
149175
.product(name: "Testing", package: "swift-testing")
150176
)

Sources/OpenSwiftUI/AppStructure/AppOrganization/TODO/OpenSwiftUIApplication.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ private func KitRendererCommon() -> Never {
6161
#elseif os(macOS)
6262
// FIXME
6363
let code = NSApplicationMain(argc, argv)
64-
#elseif os(Linux)
64+
#else
6565
let code: Int32 = 1
6666
#endif
6767
exit(code)
6868
}
6969

70+
#if canImport(Darwin)
7071
func currentAppName() -> String {
7172
if let name = Bundle.main.localizedValue(for: "CFBundleDisplayName") {
7273
return name
@@ -90,3 +91,4 @@ extension Bundle {
9091
}
9192
}
9293
}
94+
#endif

Sources/OpenSwiftUI/Internal/Graph/TODO/_GraphInputs.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public struct _GraphInputs {
99
var changedDebugProperties: _ViewDebug.Properties
1010
var options: _GraphInputs.Options
1111
// FIXME: Compile crash on Linux
12-
#if !os(Linux)
12+
#if canImport(Darwin)
1313
var mergedInputs: Set<OGAttribute>
1414
#endif
1515
}

Sources/OpenSwiftUI/Internal/Other/EnvironmentHelper.swift

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import Darwin
33
#elseif canImport(Glibc)
44
import Glibc
5+
#elseif os(WASI)
6+
import WASILibc
57
#else
68
#error("Unsupported Platform")
79
#endif

Sources/OpenSwiftUI/Layout/LayoutAdjustments/Alignment/AlignmentID.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#if canImport(Darwin)
1010
import CoreGraphics
11-
#elseif os(Linux)
11+
#else
1212
import Foundation
1313
#endif
1414

Sources/OpenSwiftUI/Layout/LayoutAdjustments/Alignment/HorizontalAlignment.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#if canImport(Darwin)
1111
import CoreGraphics
12-
#elseif os(Linux)
12+
#else
1313
import Foundation
1414
#endif
1515

Sources/OpenSwiftUI/Layout/LayoutAdjustments/Alignment/VerticalAlignment.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#if canImport(Darwin)
1111
import CoreGraphics
12-
#elseif os(Linux)
12+
#else
1313
import Foundation
1414
#endif
1515

Sources/OpenSwiftUI/Layout/LayoutAdjustments/Alignment/ViewDimensions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#if canImport(Darwin)
1010
import CoreGraphics
11-
#elseif os(Linux)
11+
#else
1212
import Foundation
1313
#endif
1414

Sources/OpenSwiftUI/Layout/LayoutAdjustments/Edge/EdgeInsets.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#if canImport(Darwin)
1010
import CoreGraphics
11-
#elseif os(Linux)
11+
#else
1212
import Foundation
1313
#endif
1414

Sources/OpenSwiftUI/Layout/LayoutFundamentals/Stack/HStack.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#if canImport(Darwin)
22
import CoreGraphics
3-
#elseif os(Linux)
3+
#else
44
import Foundation
55
#endif
66

Sources/OpenSwiftUI/Layout/LayoutFundamentals/Stack/_HStackLayout.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#if canImport(Darwin)
22
import CoreGraphics
3-
#elseif os(Linux)
3+
#else
44
import Foundation
55
#endif
66

Sources/OpenSwiftUI/Layout/LayoutFundamentals/internal/LayoutComputer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#if canImport(Darwin)
1010
import CoreGraphics
11-
#elseif os(Linux)
11+
#else
1212
import Foundation
1313
#endif
1414

Sources/OpenSwiftUI/Layout/LayoutFundamentals/internal/Spacing.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#if canImport(Darwin)
1111
import CoreGraphics
12-
#elseif os(Linux)
12+
#else
1313
import Foundation
1414
#endif
1515

Sources/OpenSwiftUI/Layout/LayoutFundamentals/internal/_ProposedSize.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#if canImport(Darwin)
1010
import CoreGraphics
11-
#elseif os(Linux)
11+
#else
1212
import Foundation
1313
#endif
1414

Sources/OpenSwiftUI/Test/_BenchmarkHost.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#if canImport(Darwin)
1111
import CoreGraphics
12-
#elseif os(Linux)
12+
#else
1313
import Foundation
1414
#endif
1515

Sources/OpenSwiftUI/UIElements/Font/TODO/Font.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#if canImport(Darwin)
22
import CoreGraphics
3-
#elseif os(Linux)
3+
#else
44
import Foundation
55
#endif
66

Sources/OpenSwiftUI/UIElements/Text/TODO/Text.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#if canImport(Darwin)
1010
import CoreGraphics
11-
#elseif os(Linux)
11+
#else
1212
import Foundation
1313
#endif
1414

Sources/OpenSwiftUI/Views/Animations/TODO/Animatable.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ extension Animatable where AnimatableData == EmptyAnimatableData {
4444

4545
#if canImport(Darwin)
4646
import CoreGraphics
47-
#elseif os(Linux)
47+
#else
4848
import Foundation
4949
#endif
5050

Sources/OpenSwiftUI/Views/Animations/VectorArithmetic.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extension Double: VectorArithmetic {
5959

6060
#if canImport(Darwin)
6161
import CoreGraphics
62-
#elseif os(Linux)
62+
#else
6363
import Foundation
6464
#endif
6565

Sources/OpenSwiftUI/Views/View/ViewTransform.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#if canImport(Darwin)
44
import CoreGraphics
5-
#elseif os(Linux)
5+
#else
66
import Foundation
77
#endif
88

Sources/OpenSwiftUI/Views/View/_IdentifiedViewProxy.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#if canImport(Darwin)
22
import CoreGraphics
3-
#elseif os(Linux)
3+
#else
44
import Foundation
55
#endif
66

Sources/OpenSwiftUIShims/include/LockedPointer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define OPENSWIFTUI_LOCK_INIT OS_UNFAIR_LOCK_INIT
1717
#define OPENSWIFTUI_LOCK_LOCK(lock) os_unfair_lock_lock(lock)
1818
#define OPENSWIFTUI_LOCK_UNLOCK(lock) os_unfair_lock_unlock(lock)
19-
#elif OPENSWIFTUI_TARGET_OS_LINUX
19+
#else
2020
#define OPENSWIFTUI_LOCK_T int32_t
2121
#include <stdint.h>
2222
#include <unistd.h>

Tests/OpenSwiftUITempTests/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## OpenSwiftUITempTests
2+
3+
A temporary test target to iterate new test case.
4+
5+
Remove this once the IDE support for swift-testing is provided.
6+
7+
Please do not commit any new files to this folder.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Scaffolding.swift
3+
//
4+
//
5+
// Created by Kyle on 2023/11/8.
6+
//
7+
8+
import Testing
9+
import XCTest
10+
11+
final class AllTests: XCTestCase {
12+
func testAll() async {
13+
await XCTestScaffold.runAllTests(hostedBy: self)
14+
}
15+
}

Tests/OpenSwiftUITests/Layout/LayoutAdjustments/Alignment/AlignmentIDTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Testing
1010
#if canImport(Darwin)
1111
import CoreGraphics
12-
#elseif os(Linux)
12+
#else
1313
import Foundation
1414
#endif
1515

Tests/OpenSwiftUITests/_ViewDebugTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Testing
1010
#if canImport(Darwin)
1111
import CoreGraphics
12-
#elseif os(Linux)
12+
#else
1313
import Foundation
1414
#endif
1515

0 commit comments

Comments
 (0)