Skip to content

Commit 3ea3e37

Browse files
authored
Spilit OG logic to OpenGraph (#11)
* Spilit OG logic to OpenGraph * Update Package.swift * Refactor macOS workflow and update dependencies * Fix CI issue
1 parent cb8da29 commit 3ea3e37

File tree

68 files changed

+151
-2823
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+151
-2823
lines changed

.github/workflows/ios.yml

+23-18
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
matrix:
1515
include:
1616
- os: macos-13
17-
xcode-version: "15.0" # Swift 5.9.0
17+
xcode-version: "15.1" # Swift 5.9.2
1818
runs-on: ${{ matrix.os }}
1919
steps:
2020
- uses: actions/checkout@v4
@@ -28,20 +28,25 @@ jobs:
2828
run: |
2929
xcodebuild build \
3030
-scheme OpenSwiftUI \
31-
-configuration Release \
32-
-sdk iphonesimulator \
33-
-destination "platform=iOS Simulator" \
34-
-derivedDataPath .build-release-iOS
35-
# OTHER_SWIFT_FLAGS="-warnings-as-errors" \ OpenCombine will emit warning in xcodebuild
36-
37-
# Test is currently not supported due to the link issue to PrivateFramework
38-
# - name: Build and run tests in release mode
39-
# run: |
40-
# xcodebuild build \
41-
# -scheme OpenSwiftUI \
42-
# -configuration Release \
43-
# -sdk iphonesimulator \
44-
# -destination "platform=iOS Simulator" \
45-
# -enableCodeCoverage YES \
46-
# OTHER_SWIFT_FLAGS="-warnings-as-errors" \
47-
# -derivedDataPath .build-test-debug
31+
-configuration Debug \
32+
-destination "platform=iOS-Simulator" \
33+
-derivedDataPath .build-test-debug
34+
# OpenSwiftUI-Package is not listed currently
35+
# OTHER_SWIFT_FLAGS="-warnings-as-errors" \ AccessLevelOnImport will cause build warning via xcodebuild
36+
env:
37+
OPENSWIFTUI_ATTRIBUTEGRAPH: 0
38+
# Test is currently not supported due to the link issue to PrivateFramework
39+
# - name: Build and run tests in debug mode with coverage
40+
# run: |
41+
# xcodebuild test \
42+
# -scheme OpenSwiftUI-Package \
43+
# -configuration Debug \
44+
# -destination "platform=iOS-Simulator" \
45+
# -enableCodeCoverage=YES \
46+
# -derivedDataPath .build-test-debug
47+
# # OTHER_SWIFT_FLAGS="-warnings-as-errors"
48+
# profdata_file_path=$(find . -path "*.build-test-debug/Build/ProfileData*Coverage.profdata" -type f)
49+
# xcrun llvm-cov show \
50+
# -instr-profile=$profdata_file_path \
51+
# .build-test-debug/Build/Products/Debug/OpenSwiftUITests.xctest/Contents/MacOS/OpenSwiftUITests \
52+
# > coverage.txt

.github/workflows/macos.yml

+2-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
matrix:
1515
include:
1616
- os: macos-13
17-
xcode-version: "15.0" # Swift 5.9.0
17+
xcode-version: "15.1" # Swift 5.9.2
1818
runs-on: ${{ matrix.os }}
1919
steps:
2020
- uses: actions/checkout@v4
@@ -35,13 +35,6 @@ jobs:
3535
-instr-profile=.build-test-debug/debug/codecov/default.profdata \
3636
.build-test-debug/debug/OpenSwiftUIPackageTests.xctest/Contents/MacOS/OpenSwiftUIPackageTests \
3737
> coverage.txt
38-
- name: Build and run tests in debug mode with TSan
39-
run: |
40-
swift test \
41-
-c debug \
42-
--sanitize thread \
43-
-Xswiftc -warnings-as-errors \
44-
--build-path .build-test-debug-sanitize-thread
4538
- name: Build and run tests in release mode
4639
run: |
4740
swift test \
@@ -51,4 +44,5 @@ jobs:
5144
--build-path .build-test-release
5245
- uses: codecov/codecov-action@v3
5346
with:
47+
token: ${{ secrets.CODECOV_TOKEN }}
5448
verbose: true

.github/workflows/ubuntu.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
swift_version: ["5.9.1"]
15+
swift_version: ["5.9.2"]
1616
runs-on: ubuntu-22.04
1717
container: swift:${{ matrix.swift_version }}-jammy
1818
steps:
@@ -28,12 +28,6 @@ jobs:
2828
-instr-profile=.build-test-debug/debug/codecov/default.profdata \
2929
.build-test-debug/debug/OpenSwiftUIPackageTests.xctest \
3030
> coverage.txt
31-
- name: Building and running tests in debug mode with TSan
32-
run: |
33-
swift test \
34-
-c debug \
35-
--sanitize thread \
36-
--build-path .build-test-debug-sanitize-thread
3731
- name: Building and running tests in release mode
3832
run: |
3933
swift test \
@@ -42,4 +36,5 @@ jobs:
4236
--build-path .build-test-release
4337
- uses: codecov/codecov-action@v3
4438
with:
39+
token: ${{ secrets.CODECOV_TOKEN }}
4540
verbose: true

.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ DerivedData/
66
.swiftpm/configuration/registries.json
77
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
88
.netrc
9-
/.build-test-debug
10-
/.build-test-release
11-
/.build-test-debug-sanitize-thread
9+
/.build-*

.spi.yml

-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,3 @@ builder:
33
configs:
44
- swift_version: 5.9
55
documentation_targets: [OpenSwiftUI]
6-
customDocumentationParameters: [
7-
--source-service, github,
8-
--source-service-base-url, https://github.com/Kyle-Ye/OpenSwiftUI/blob/main,
9-
--checkout-path, .
10-
]

Package.resolved

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
{
22
"pins" : [
3-
{
4-
"identity" : "opencombine",
5-
"kind" : "remoteSourceControl",
6-
"location" : "https://github.com/OpenCombine/OpenCombine.git",
7-
"state" : {
8-
"revision" : "8576f0d579b27020beccbccc3ea6844f3ddfc2c2",
9-
"version" : "0.14.0"
10-
}
11-
},
123
{
134
"identity" : "openfoundation",
145
"kind" : "remoteSourceControl",
15-
"location" : "https://github.com/Kyle-Ye/OpenFoundation",
6+
"location" : "https://github.com/OpenSwiftUIProject/OpenFoundation",
167
"state" : {
17-
"revision" : "72404a9e51d314af915b13430cf9b928a1654714",
18-
"version" : "0.0.1"
8+
"revision" : "cd2cdb300d53e3e68fda8b690a703a7c5096d9d0",
9+
"version" : "0.0.2"
1910
}
2011
},
2112
{
22-
"identity" : "swift-log",
13+
"identity" : "opengraph",
2314
"kind" : "remoteSourceControl",
24-
"location" : "https://github.com/apple/swift-log",
15+
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
2516
"state" : {
26-
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
27-
"version" : "1.5.3"
17+
"branch" : "main",
18+
"revision" : "6835ce0972f40ef76f1214dc0efc75ec19082631"
2819
}
2920
}
3021
],

Package.swift

+67-103
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ let isXcodeEnv = ProcessInfo.processInfo.environment["__CFBundleIdentifier"] ==
88
// Xcode use clang as linker which supports "-iframework" while SwiftPM use swiftc as linker which supports "-Fsystem"
99
let systemFrameworkSearchFlag = isXcodeEnv ? "-iframework" : "-Fsystem"
1010

11-
// https://github.com/llvm/llvm-project/issues/48757
12-
let clangEnumFixSetting = CSetting.unsafeFlags(["-Wno-elaborated-enum-base"], .when(platforms: [.linux]))
13-
1411
let openSwiftUITarget = Target.target(
1512
name: "OpenSwiftUI",
1613
dependencies: [
@@ -42,20 +39,26 @@ let openSwiftUITestTarget = Target.testTarget(
4239
)
4340
let openSwiftUICompatibilityTestTarget = Target.testTarget(
4441
name: "OpenSwiftUICompatibilityTests",
45-
dependencies: [
46-
"OpenSwiftUI",
47-
],
4842
exclude: ["README.md"]
4943
)
5044

5145
let package = Package(
5246
name: "OpenSwiftUI",
53-
platforms: [.iOS(.v13), .macOS(.v10_15), .macCatalyst(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)],
47+
platforms: [
48+
.iOS(.v13),
49+
.macOS(.v10_15),
50+
.macCatalyst(.v13),
51+
.tvOS(.v13),
52+
.watchOS(.v6),
53+
.visionOS(.v1),
54+
],
5455
products: [
5556
.library(name: "OpenSwiftUI", targets: ["OpenSwiftUI"]),
5657
],
5758
dependencies: [
58-
.package(url: "https://github.com/Kyle-Ye/OpenFoundation", from: "0.0.1"),
59+
.package(url: "https://github.com/OpenSwiftUIProject/OpenFoundation", from: "0.0.1"),
60+
// FIXME: on Linux platform: OG contains unsafe build flags which prevents us using version dependency
61+
.package(url: "https://github.com/OpenSwiftUIProject/OpenGraph", branch: "main"),
5962
],
6063
targets: [
6164
// TODO: Add SwiftGTK as an backend alternative for UIKit/AppKit on Linux and macOS
@@ -80,133 +83,94 @@ let package = Package(
8083
]
8184
)
8285

83-
// FIXME: The binary of AG for macOS is copied from dyld shared cache and it will cause a link error when running. Use iOS Simulator to run this target as a temporary workaround
84-
let graphCompatibilityTest = ProcessInfo.processInfo.environment["OPENGRAPH_COMPATIBILITY_TEST"] != nil
85-
let openGraphCompatibilityTestTarget = Target.testTarget(
86-
name: "OpenGraphCompatibilityTests",
87-
dependencies: [
88-
graphCompatibilityTest ? "AttributeGraph" : "OpenGraph",
89-
],
90-
exclude: ["README.md"],
91-
swiftSettings: graphCompatibilityTest ? [
92-
.define("OPENGRAPH_COMPATIBILITY_TEST")
93-
] : []
94-
)
95-
package.targets.append(openGraphCompatibilityTestTarget)
96-
97-
let useAG = ProcessInfo.processInfo.environment["OPENSWIFTUI_USE_AG"] != nil
98-
if useAG {
99-
if !graphCompatibilityTest {
100-
let targets: [Target] = [
101-
// FIXME: Merge into one target
102-
// OpenGraph is a C++ & Swift mix target.
103-
// The SwiftPM support for such usage is still in progress.
104-
.target(
105-
name: "_OpenGraph",
106-
dependencies: [.product(name: "OpenFoundation", package: "OpenFoundation")],
107-
cSettings: [clangEnumFixSetting]
108-
),
109-
.target(
110-
name: "OpenGraph",
111-
dependencies: ["_OpenGraph"],
112-
cSettings: [clangEnumFixSetting]
113-
),
114-
]
115-
package.targets.append(contentsOf: targets)
86+
func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
87+
guard let value = ProcessInfo.processInfo.environment[key] else {
88+
return defaultValue
11689
}
117-
let targets: [Target] = [
118-
.binaryTarget(name: "AttributeGraph", path: "Sources/AttributeGraph.xcframework"),
119-
]
120-
package.targets.append(contentsOf: targets)
90+
if value == "1" {
91+
return true
92+
} else if value == "0" {
93+
return false
94+
} else {
95+
return defaultValue
96+
}
97+
}
98+
99+
#if os(macOS)
100+
let attributeGraphCondition = envEnable("OPENSWIFTUI_ATTRIBUTEGRAPH", default: true)
101+
#else
102+
let attributeGraphCondition = envEnable("OPENSWIFTUI_ATTRIBUTEGRAPH")
103+
#endif
104+
if attributeGraphCondition {
121105
openSwiftUITarget.dependencies.append(
122-
"AttributeGraph"
106+
.product(name: "AttributeGraph", package: "OpenGraph")
123107
)
124-
var swiftSettings: [SwiftSetting] = (openSwiftUITarget.swiftSettings ?? [])
125-
swiftSettings.append(.define("OPENSWIFTUI_USE_AG"))
108+
var swiftSettings = openSwiftUITarget.swiftSettings ?? []
109+
swiftSettings.append(.define("OPENSWIFTUI_ATTRIBUTEGRAPH"))
126110
openSwiftUITarget.swiftSettings = swiftSettings
111+
var linkerSettings = openSwiftUITarget.linkerSettings ?? []
112+
linkerSettings.append(.unsafeFlags([systemFrameworkSearchFlag, "/System/Library/PrivateFrameworks/"], .when(platforms: [.macOS])))
113+
linkerSettings.append(.linkedFramework("AttributeGraph", .when(platforms: [.macOS])))
114+
openSwiftUITarget.linkerSettings = linkerSettings
127115
} else {
128-
if graphCompatibilityTest {
129-
let targets: [Target] = [
130-
.binaryTarget(name: "AttributeGraph", path: "Sources/AttributeGraph.xcframework"),
131-
]
132-
package.targets.append(contentsOf: targets)
133-
}
134-
package.products.append(
135-
.library(name: "OpenGraph", targets: ["OpenGraph", "_OpenGraph"])
136-
)
137-
let targets: [Target] = [
138-
// FIXME: Merge into one target
139-
// OpenGraph is a C++ & Swift mix target.
140-
// The SwiftPM support for such usage is still in progress.
141-
.target(
142-
name: "_OpenGraph",
143-
dependencies: [.product(name: "OpenFoundation", package: "OpenFoundation")],
144-
cSettings: [clangEnumFixSetting]
145-
),
146-
.target(
147-
name: "OpenGraph",
148-
dependencies: ["_OpenGraph"],
149-
cSettings: [clangEnumFixSetting]
150-
),
151-
.testTarget(
152-
name: "OpenGraphTests",
153-
dependencies: [
154-
"OpenGraph",
155-
]
156-
),
157-
]
158-
package.targets.append(contentsOf: targets)
159116
openSwiftUITarget.dependencies.append(
160-
"OpenGraph"
117+
.product(name: "OpenGraph", package: "OpenGraph")
161118
)
162119
}
163120

164-
let useCombine = ProcessInfo.processInfo.environment["OPENSWIFTUI_USE_COMBINE"] != nil
165-
if useCombine {
166-
var swiftSettings: [SwiftSetting] = (openSwiftUITarget.swiftSettings ?? [])
167-
swiftSettings.append(.define("OPENSWIFTUI_USE_COMBINE"))
168-
openSwiftUITarget.swiftSettings = swiftSettings
169-
} else {
121+
#if os(macOS)
122+
let openCombineCondition = envEnable("OPENSWIFTUI_OPENCOMBINE")
123+
#else
124+
let openCombineCondition = envEnable("OPENSWIFTUI_OPENCOMBINE", default: true)
125+
#endif
126+
if openCombineCondition {
170127
package.dependencies.append(
171-
.package(url: "https://github.com/OpenCombine/OpenCombine.git", from: "0.14.0")
128+
.package(url: "https://github.com/OpenSwiftUIProject/OpenCombine.git", from: "0.15.0")
172129
)
173130
openSwiftUITarget.dependencies.append(
174131
.product(name: "OpenCombine", package: "OpenCombine")
175132
)
176-
}
177-
178-
let useOSLog = ProcessInfo.processInfo.environment["OPENSWIFTUI_USE_OS_LOG"] != nil
179-
if useOSLog {
180133
var swiftSettings: [SwiftSetting] = (openSwiftUITarget.swiftSettings ?? [])
181-
swiftSettings.append(.define("OPENSWIFTUI_USE_OS_LOG"))
134+
swiftSettings.append(.define("OPENSWIFTUI_OPENCOMBINE"))
182135
openSwiftUITarget.swiftSettings = swiftSettings
183-
} else {
136+
}
137+
138+
#if os(macOS)
139+
let swiftLogCondition = envEnable("OPENSWIFTUI_SWIFT_LOG")
140+
#else
141+
let swiftLogCondition = envEnable("OPENSWIFTUI_SWIFT_LOG", default: true)
142+
#endif
143+
if swiftLogCondition {
184144
package.dependencies.append(
185145
.package(url: "https://github.com/apple/swift-log", from: "1.5.3")
186146
)
187147
openSwiftUITarget.dependencies.append(
188148
.product(name: "Logging", package: "swift-log")
189149
)
150+
var swiftSettings: [SwiftSetting] = (openSwiftUITarget.swiftSettings ?? [])
151+
swiftSettings.append(.define("OPENSWIFTUI_SWIFT_LOG"))
152+
openSwiftUITarget.swiftSettings = swiftSettings
190153
}
191154

192-
// Remove this when swift-testing is 1.0.0
193-
let useSwiftTesting = ProcessInfo.processInfo.environment["OPENSWIFTUI_USE_SWIFT_TESTING"] != nil
194-
if useSwiftTesting {
195-
var swiftSettings: [SwiftSetting] = (openSwiftUITestTarget.swiftSettings ?? [])
196-
swiftSettings.append(.define("OPENSWIFTUI_USE_SWIFT_TESTING"))
197-
openSwiftUITestTarget.swiftSettings = swiftSettings
155+
// Remove the check when swift-testing reaches 1.0.0
156+
let swiftTestingCondition = envEnable("OPENSWIFTUI_SWIFT_TESTING")
157+
if swiftTestingCondition {
198158
package.dependencies.append(
199-
// TODO: use `from` when a new version beside 0.1.0 is released
200-
.package(url: "https://github.com/apple/swift-testing", branch: "main")
159+
.package(url: "https://github.com/apple/swift-testing", from: "0.2.0")
201160
)
202161
openSwiftUITestTarget.dependencies.append(
203162
.product(name: "Testing", package: "swift-testing")
204163
)
164+
var swiftSettings: [SwiftSetting] = (openSwiftUITestTarget.swiftSettings ?? [])
165+
swiftSettings.append(.define("OPENSWIFTUI_SWIFT_TESTING"))
166+
openSwiftUITestTarget.swiftSettings = swiftSettings
205167
}
206168

207-
let compatibilityTest = ProcessInfo.processInfo.environment["OPENSWIFTUI_COMPATIBILITY_TEST"] != nil
208-
if compatibilityTest {
169+
let compatibilityTestCondition = envEnable("OPENSWIFTUI_COMPATIBILITY_TEST")
170+
if compatibilityTestCondition {
209171
var swiftSettings: [SwiftSetting] = (openSwiftUICompatibilityTestTarget.swiftSettings ?? [])
210172
swiftSettings.append(.define("OPENSWIFTUI_COMPATIBILITY_TEST"))
211173
openSwiftUICompatibilityTestTarget.swiftSettings = swiftSettings
174+
} else {
175+
openSwiftUICompatibilityTestTarget.dependencies.append("OpenSwiftUI")
212176
}

0 commit comments

Comments
 (0)