Skip to content

Commit

Permalink
Spilit OG logic to OpenGraph (#11)
Browse files Browse the repository at this point in the history
* Spilit OG logic to OpenGraph

* Update Package.swift

* Refactor macOS workflow and update dependencies

* Fix CI issue
  • Loading branch information
Kyle-Ye authored Dec 29, 2023
1 parent cb8da29 commit 3ea3e37
Show file tree
Hide file tree
Showing 68 changed files with 151 additions and 2,823 deletions.
41 changes: 23 additions & 18 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
include:
- os: macos-13
xcode-version: "15.0" # Swift 5.9.0
xcode-version: "15.1" # Swift 5.9.2
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -28,20 +28,25 @@ jobs:
run: |
xcodebuild build \
-scheme OpenSwiftUI \
-configuration Release \
-sdk iphonesimulator \
-destination "platform=iOS Simulator" \
-derivedDataPath .build-release-iOS
# OTHER_SWIFT_FLAGS="-warnings-as-errors" \ OpenCombine will emit warning in xcodebuild

# Test is currently not supported due to the link issue to PrivateFramework
# - name: Build and run tests in release mode
# run: |
# xcodebuild build \
# -scheme OpenSwiftUI \
# -configuration Release \
# -sdk iphonesimulator \
# -destination "platform=iOS Simulator" \
# -enableCodeCoverage YES \
# OTHER_SWIFT_FLAGS="-warnings-as-errors" \
# -derivedDataPath .build-test-debug
-configuration Debug \
-destination "platform=iOS-Simulator" \
-derivedDataPath .build-test-debug
# OpenSwiftUI-Package is not listed currently
# OTHER_SWIFT_FLAGS="-warnings-as-errors" \ AccessLevelOnImport will cause build warning via xcodebuild
env:
OPENSWIFTUI_ATTRIBUTEGRAPH: 0
# Test is currently not supported due to the link issue to PrivateFramework
# - name: Build and run tests in debug mode with coverage
# run: |
# xcodebuild test \
# -scheme OpenSwiftUI-Package \
# -configuration Debug \
# -destination "platform=iOS-Simulator" \
# -enableCodeCoverage=YES \
# -derivedDataPath .build-test-debug
# # OTHER_SWIFT_FLAGS="-warnings-as-errors"
# profdata_file_path=$(find . -path "*.build-test-debug/Build/ProfileData*Coverage.profdata" -type f)
# xcrun llvm-cov show \
# -instr-profile=$profdata_file_path \
# .build-test-debug/Build/Products/Debug/OpenSwiftUITests.xctest/Contents/MacOS/OpenSwiftUITests \
# > coverage.txt
10 changes: 2 additions & 8 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
include:
- os: macos-13
xcode-version: "15.0" # Swift 5.9.0
xcode-version: "15.1" # Swift 5.9.2
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -35,13 +35,6 @@ jobs:
-instr-profile=.build-test-debug/debug/codecov/default.profdata \
.build-test-debug/debug/OpenSwiftUIPackageTests.xctest/Contents/MacOS/OpenSwiftUIPackageTests \
> coverage.txt
- name: Build and run tests in debug mode with TSan
run: |
swift test \
-c debug \
--sanitize thread \
-Xswiftc -warnings-as-errors \
--build-path .build-test-debug-sanitize-thread
- name: Build and run tests in release mode
run: |
swift test \
Expand All @@ -51,4 +44,5 @@ jobs:
--build-path .build-test-release
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
9 changes: 2 additions & 7 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
swift_version: ["5.9.1"]
swift_version: ["5.9.2"]
runs-on: ubuntu-22.04
container: swift:${{ matrix.swift_version }}-jammy
steps:
Expand All @@ -28,12 +28,6 @@ jobs:
-instr-profile=.build-test-debug/debug/codecov/default.profdata \
.build-test-debug/debug/OpenSwiftUIPackageTests.xctest \
> coverage.txt
- name: Building and running tests in debug mode with TSan
run: |
swift test \
-c debug \
--sanitize thread \
--build-path .build-test-debug-sanitize-thread
- name: Building and running tests in release mode
run: |
swift test \
Expand All @@ -42,4 +36,5 @@ jobs:
--build-path .build-test-release
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
/.build-test-debug
/.build-test-release
/.build-test-debug-sanitize-thread
/.build-*
5 changes: 0 additions & 5 deletions .spi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@ builder:
configs:
- swift_version: 5.9
documentation_targets: [OpenSwiftUI]
customDocumentationParameters: [
--source-service, github,
--source-service-base-url, https://github.com/Kyle-Ye/OpenSwiftUI/blob/main,
--checkout-path, .
]
23 changes: 7 additions & 16 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
{
"pins" : [
{
"identity" : "opencombine",
"kind" : "remoteSourceControl",
"location" : "https://github.com/OpenCombine/OpenCombine.git",
"state" : {
"revision" : "8576f0d579b27020beccbccc3ea6844f3ddfc2c2",
"version" : "0.14.0"
}
},
{
"identity" : "openfoundation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Kyle-Ye/OpenFoundation",
"location" : "https://github.com/OpenSwiftUIProject/OpenFoundation",
"state" : {
"revision" : "72404a9e51d314af915b13430cf9b928a1654714",
"version" : "0.0.1"
"revision" : "cd2cdb300d53e3e68fda8b690a703a7c5096d9d0",
"version" : "0.0.2"
}
},
{
"identity" : "swift-log",
"identity" : "opengraph",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log",
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
"state" : {
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
"branch" : "main",
"revision" : "6835ce0972f40ef76f1214dc0efc75ec19082631"
}
}
],
Expand Down
170 changes: 67 additions & 103 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ let isXcodeEnv = ProcessInfo.processInfo.environment["__CFBundleIdentifier"] ==
// Xcode use clang as linker which supports "-iframework" while SwiftPM use swiftc as linker which supports "-Fsystem"
let systemFrameworkSearchFlag = isXcodeEnv ? "-iframework" : "-Fsystem"

// https://github.com/llvm/llvm-project/issues/48757
let clangEnumFixSetting = CSetting.unsafeFlags(["-Wno-elaborated-enum-base"], .when(platforms: [.linux]))

let openSwiftUITarget = Target.target(
name: "OpenSwiftUI",
dependencies: [
Expand Down Expand Up @@ -42,20 +39,26 @@ let openSwiftUITestTarget = Target.testTarget(
)
let openSwiftUICompatibilityTestTarget = Target.testTarget(
name: "OpenSwiftUICompatibilityTests",
dependencies: [
"OpenSwiftUI",
],
exclude: ["README.md"]
)

let package = Package(
name: "OpenSwiftUI",
platforms: [.iOS(.v13), .macOS(.v10_15), .macCatalyst(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)],
platforms: [
.iOS(.v13),
.macOS(.v10_15),
.macCatalyst(.v13),
.tvOS(.v13),
.watchOS(.v6),
.visionOS(.v1),
],
products: [
.library(name: "OpenSwiftUI", targets: ["OpenSwiftUI"]),
],
dependencies: [
.package(url: "https://github.com/Kyle-Ye/OpenFoundation", from: "0.0.1"),
.package(url: "https://github.com/OpenSwiftUIProject/OpenFoundation", from: "0.0.1"),
// FIXME: on Linux platform: OG contains unsafe build flags which prevents us using version dependency
.package(url: "https://github.com/OpenSwiftUIProject/OpenGraph", branch: "main"),
],
targets: [
// TODO: Add SwiftGTK as an backend alternative for UIKit/AppKit on Linux and macOS
Expand All @@ -80,133 +83,94 @@ let package = Package(
]
)

// 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
let graphCompatibilityTest = ProcessInfo.processInfo.environment["OPENGRAPH_COMPATIBILITY_TEST"] != nil
let openGraphCompatibilityTestTarget = Target.testTarget(
name: "OpenGraphCompatibilityTests",
dependencies: [
graphCompatibilityTest ? "AttributeGraph" : "OpenGraph",
],
exclude: ["README.md"],
swiftSettings: graphCompatibilityTest ? [
.define("OPENGRAPH_COMPATIBILITY_TEST")
] : []
)
package.targets.append(openGraphCompatibilityTestTarget)

let useAG = ProcessInfo.processInfo.environment["OPENSWIFTUI_USE_AG"] != nil
if useAG {
if !graphCompatibilityTest {
let targets: [Target] = [
// FIXME: Merge into one target
// OpenGraph is a C++ & Swift mix target.
// The SwiftPM support for such usage is still in progress.
.target(
name: "_OpenGraph",
dependencies: [.product(name: "OpenFoundation", package: "OpenFoundation")],
cSettings: [clangEnumFixSetting]
),
.target(
name: "OpenGraph",
dependencies: ["_OpenGraph"],
cSettings: [clangEnumFixSetting]
),
]
package.targets.append(contentsOf: targets)
func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
guard let value = ProcessInfo.processInfo.environment[key] else {
return defaultValue
}
let targets: [Target] = [
.binaryTarget(name: "AttributeGraph", path: "Sources/AttributeGraph.xcframework"),
]
package.targets.append(contentsOf: targets)
if value == "1" {
return true
} else if value == "0" {
return false
} else {
return defaultValue
}
}

#if os(macOS)
let attributeGraphCondition = envEnable("OPENSWIFTUI_ATTRIBUTEGRAPH", default: true)
#else
let attributeGraphCondition = envEnable("OPENSWIFTUI_ATTRIBUTEGRAPH")
#endif
if attributeGraphCondition {
openSwiftUITarget.dependencies.append(
"AttributeGraph"
.product(name: "AttributeGraph", package: "OpenGraph")
)
var swiftSettings: [SwiftSetting] = (openSwiftUITarget.swiftSettings ?? [])
swiftSettings.append(.define("OPENSWIFTUI_USE_AG"))
var swiftSettings = openSwiftUITarget.swiftSettings ?? []
swiftSettings.append(.define("OPENSWIFTUI_ATTRIBUTEGRAPH"))
openSwiftUITarget.swiftSettings = swiftSettings
var linkerSettings = openSwiftUITarget.linkerSettings ?? []
linkerSettings.append(.unsafeFlags([systemFrameworkSearchFlag, "/System/Library/PrivateFrameworks/"], .when(platforms: [.macOS])))
linkerSettings.append(.linkedFramework("AttributeGraph", .when(platforms: [.macOS])))
openSwiftUITarget.linkerSettings = linkerSettings
} else {
if graphCompatibilityTest {
let targets: [Target] = [
.binaryTarget(name: "AttributeGraph", path: "Sources/AttributeGraph.xcframework"),
]
package.targets.append(contentsOf: targets)
}
package.products.append(
.library(name: "OpenGraph", targets: ["OpenGraph", "_OpenGraph"])
)
let targets: [Target] = [
// FIXME: Merge into one target
// OpenGraph is a C++ & Swift mix target.
// The SwiftPM support for such usage is still in progress.
.target(
name: "_OpenGraph",
dependencies: [.product(name: "OpenFoundation", package: "OpenFoundation")],
cSettings: [clangEnumFixSetting]
),
.target(
name: "OpenGraph",
dependencies: ["_OpenGraph"],
cSettings: [clangEnumFixSetting]
),
.testTarget(
name: "OpenGraphTests",
dependencies: [
"OpenGraph",
]
),
]
package.targets.append(contentsOf: targets)
openSwiftUITarget.dependencies.append(
"OpenGraph"
.product(name: "OpenGraph", package: "OpenGraph")
)
}

let useCombine = ProcessInfo.processInfo.environment["OPENSWIFTUI_USE_COMBINE"] != nil
if useCombine {
var swiftSettings: [SwiftSetting] = (openSwiftUITarget.swiftSettings ?? [])
swiftSettings.append(.define("OPENSWIFTUI_USE_COMBINE"))
openSwiftUITarget.swiftSettings = swiftSettings
} else {
#if os(macOS)
let openCombineCondition = envEnable("OPENSWIFTUI_OPENCOMBINE")
#else
let openCombineCondition = envEnable("OPENSWIFTUI_OPENCOMBINE", default: true)
#endif
if openCombineCondition {
package.dependencies.append(
.package(url: "https://github.com/OpenCombine/OpenCombine.git", from: "0.14.0")
.package(url: "https://github.com/OpenSwiftUIProject/OpenCombine.git", from: "0.15.0")
)
openSwiftUITarget.dependencies.append(
.product(name: "OpenCombine", package: "OpenCombine")
)
}

let useOSLog = ProcessInfo.processInfo.environment["OPENSWIFTUI_USE_OS_LOG"] != nil
if useOSLog {
var swiftSettings: [SwiftSetting] = (openSwiftUITarget.swiftSettings ?? [])
swiftSettings.append(.define("OPENSWIFTUI_USE_OS_LOG"))
swiftSettings.append(.define("OPENSWIFTUI_OPENCOMBINE"))
openSwiftUITarget.swiftSettings = swiftSettings
} else {
}

#if os(macOS)
let swiftLogCondition = envEnable("OPENSWIFTUI_SWIFT_LOG")
#else
let swiftLogCondition = envEnable("OPENSWIFTUI_SWIFT_LOG", default: true)
#endif
if swiftLogCondition {
package.dependencies.append(
.package(url: "https://github.com/apple/swift-log", from: "1.5.3")
)
openSwiftUITarget.dependencies.append(
.product(name: "Logging", package: "swift-log")
)
var swiftSettings: [SwiftSetting] = (openSwiftUITarget.swiftSettings ?? [])
swiftSettings.append(.define("OPENSWIFTUI_SWIFT_LOG"))
openSwiftUITarget.swiftSettings = swiftSettings
}

// Remove this when swift-testing is 1.0.0
let useSwiftTesting = ProcessInfo.processInfo.environment["OPENSWIFTUI_USE_SWIFT_TESTING"] != nil
if useSwiftTesting {
var swiftSettings: [SwiftSetting] = (openSwiftUITestTarget.swiftSettings ?? [])
swiftSettings.append(.define("OPENSWIFTUI_USE_SWIFT_TESTING"))
openSwiftUITestTarget.swiftSettings = swiftSettings
// Remove the check when swift-testing reaches 1.0.0
let swiftTestingCondition = envEnable("OPENSWIFTUI_SWIFT_TESTING")
if swiftTestingCondition {
package.dependencies.append(
// TODO: use `from` when a new version beside 0.1.0 is released
.package(url: "https://github.com/apple/swift-testing", branch: "main")
.package(url: "https://github.com/apple/swift-testing", from: "0.2.0")
)
openSwiftUITestTarget.dependencies.append(
.product(name: "Testing", package: "swift-testing")
)
var swiftSettings: [SwiftSetting] = (openSwiftUITestTarget.swiftSettings ?? [])
swiftSettings.append(.define("OPENSWIFTUI_SWIFT_TESTING"))
openSwiftUITestTarget.swiftSettings = swiftSettings
}

let compatibilityTest = ProcessInfo.processInfo.environment["OPENSWIFTUI_COMPATIBILITY_TEST"] != nil
if compatibilityTest {
let compatibilityTestCondition = envEnable("OPENSWIFTUI_COMPATIBILITY_TEST")
if compatibilityTestCondition {
var swiftSettings: [SwiftSetting] = (openSwiftUICompatibilityTestTarget.swiftSettings ?? [])
swiftSettings.append(.define("OPENSWIFTUI_COMPATIBILITY_TEST"))
openSwiftUICompatibilityTestTarget.swiftSettings = swiftSettings
} else {
openSwiftUICompatibilityTestTarget.dependencies.append("OpenSwiftUI")
}
Loading

0 comments on commit 3ea3e37

Please sign in to comment.