Skip to content

Commit 370c3ac

Browse files
authored
Add initial Compute binary support (#197)
* Add Compute dependency * Fix compile issue * Add missing API * Add AttributeGraphVendor * Add Compute CI workflow * Fix CI failures for deprecated attributeGraphEnabled and duplicate DPF dependency * Disable ubuntu compute CI * Fix compute iOS CI * Rename ATTRIBUTEGRAPH env var to OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH in CI workflows
1 parent abc2484 commit 370c3ac

12 files changed

Lines changed: 224 additions & 27 deletions

File tree

‎.github/workflows/compatibility_tests.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ${{ matrix.os }}
1919
env:
2020
OPENATTRIBUTEGRAPH_WERROR: 1
21-
OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH: 1
21+
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH: 1
2222
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 1
2323
OPENATTRIBUTEGRAPH_USE_LOCAL_DEPS: 1
2424
OPENATTRIBUTEGRAPH_TARGET_RELEASE: 2024

‎.github/workflows/compute.yml‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Compute
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
# TODO: Enable once Compute binary is available for Linux or source integration is supported
11+
# compute_ubuntu_build:
12+
# name: Build with Compute on Ubuntu
13+
# strategy:
14+
# fail-fast: false
15+
# matrix:
16+
# swift_version: ["6.1.3"]
17+
# runs-on: ubuntu-22.04
18+
# env:
19+
# OPENATTRIBUTEGRAPH_WERROR: 1
20+
# OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE: 1
21+
# OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
22+
# container: swift:${{ matrix.swift_version }}-jammy
23+
# steps:
24+
# - uses: actions/checkout@v4
25+
# - name: Checkout Swift headers
26+
# uses: ./.github/actions/checkout-swift-headers
27+
# - name: Build in debug mode
28+
# run: swift build -c debug
29+
30+
compute_macos_build:
31+
name: Build with Compute on macOS
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
os: [macos-15]
36+
xcode-version: ["16.4"]
37+
runs-on: ${{ matrix.os }}
38+
env:
39+
OPENATTRIBUTEGRAPH_WERROR: 1
40+
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE: 1
41+
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
42+
steps:
43+
- uses: actions/checkout@v4
44+
- name: Setup Xcode
45+
uses: OpenSwiftUIProject/OpenSwiftUI/.github/actions/setup-xcode@main
46+
with:
47+
xcode-version: ${{ matrix.xcode-version }}
48+
- name: Checkout Swift headers
49+
uses: ./.github/actions/checkout-swift-headers
50+
- name: Build in debug mode
51+
run: swift build -c debug
52+
53+
compute_ios_build:
54+
name: Build with Compute on iOS
55+
strategy:
56+
fail-fast: false
57+
matrix:
58+
os: [macos-15]
59+
xcode-version: ["16.4"]
60+
ios-version: ["18.5"]
61+
include:
62+
- ios-version: "18.5"
63+
ios-simulator-name: "iPhone 16 Pro"
64+
runs-on: ${{ matrix.os }}
65+
env:
66+
OPENATTRIBUTEGRAPH_WERROR: 1
67+
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE: 1
68+
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
69+
steps:
70+
- uses: actions/checkout@v4
71+
- name: Setup Xcode
72+
uses: OpenSwiftUIProject/OpenSwiftUI/.github/actions/setup-xcode@main
73+
with:
74+
xcode-version: ${{ matrix.xcode-version }}
75+
- name: Checkout Swift headers
76+
uses: ./.github/actions/checkout-swift-headers
77+
- name: Build in debug mode on iOS Simulator
78+
run: |
79+
xcodebuild build \
80+
-workspace .swiftpm/xcode/package.xcworkspace \
81+
-scheme OpenAttributeGraph-Package \
82+
-configuration Debug \
83+
-destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \
84+
-derivedDataPath .build-debug \
85+
-skipMacroValidation \
86+
-skipPackagePluginValidation \
87+
OTHER_SWIFT_FLAGS="-warnings-as-errors"

‎.github/workflows/ios.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ${{ matrix.os }}
2222
env:
2323
OPENATTRIBUTEGRAPH_WERROR: 1
24-
OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH: 0
24+
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH: 0
2525
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
2626
OPENATTRIBUTEGRAPH_USE_LOCAL_DEPS: 1
2727
OPENATTRIBUTEGRAPH_TARGET_RELEASE: 2024

‎.github/workflows/macos.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ${{ matrix.os }}
1818
env:
1919
OPENATTRIBUTEGRAPH_WERROR: 1
20-
OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH: 0
20+
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH: 0
2121
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
2222
OPENATTRIBUTEGRAPH_USE_LOCAL_DEPS: 1
2323
OPENATTRIBUTEGRAPH_TARGET_RELEASE: 2024

‎.github/workflows/ubuntu.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-22.04
1717
env:
1818
OPENATTRIBUTEGRAPH_WERROR: 1
19-
OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH: 0
19+
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH: 0
2020
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
2121
container: swift:${{ matrix.swift_version }}-jammy
2222
steps:

‎Package.resolved‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Package.swift‎

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ let libraryEvolutionCondition = envBoolValue("LIBRARY_EVOLUTION", default: build
145145
let compatibilityTestCondition = envBoolValue("COMPATIBILITY_TEST", default: false)
146146

147147
let useLocalDeps = envBoolValue("USE_LOCAL_DEPS")
148-
let attributeGraphCondition = envBoolValue("ATTRIBUTEGRAPH", default: buildForDarwinPlatform && !isSPIBuild)
148+
let computeCondition = envBoolValue("OPENATTRIBUTESHIMS_COMPUTE", default: false)
149+
let attributeGraphCondition = envBoolValue("OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH", default: buildForDarwinPlatform && !isSPIBuild)
149150

150151
// MARK: - Shared Settings
151152

@@ -228,6 +229,15 @@ extension Target {
228229
swiftSettings.append(.define("OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH"))
229230
self.swiftSettings = swiftSettings
230231
}
232+
233+
func addComputeBinarySettings() {
234+
dependencies.append(
235+
"Compute",
236+
)
237+
var swiftSettings = swiftSettings ?? []
238+
swiftSettings.append(.define("OPENATTRIBUTEGRAPH_COMPUTE"))
239+
self.swiftSettings = swiftSettings
240+
}
231241
}
232242

233243
extension [Platform] {
@@ -371,29 +381,19 @@ let package = Package(
371381
cxxLanguageStandard: .cxx20
372382
)
373383

374-
if compatibilityTestCondition {
375-
openAttributeGraphCompatibilityTestsTarget.addAGSettings()
376-
} else {
377-
package.targets += [
378-
utilitiesTestsTarget,
379-
openAttributeGraphCxxTestsTarget,
380-
openAttributeGraphShimsTestsTarget,
381-
]
382-
}
383-
384-
if buildForDarwinPlatform {
385-
package.targets.append(openAttributeGraphCompatibilityTestsTarget)
386-
}
384+
private var hasSetupDPFDependency = false
387385

388-
if attributeGraphCondition {
386+
@MainActor
387+
func setupDPFDependency() {
388+
guard !hasSetupDPFDependency else { return }
389+
hasSetupDPFDependency = true
389390
let privateFrameworkRepo: Package.Dependency
390391
if useLocalDeps {
391392
privateFrameworkRepo = Package.Dependency.package(path: "../DarwinPrivateFrameworks")
392393
} else {
393394
privateFrameworkRepo = Package.Dependency.package(url: "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", branch: "main")
394395
}
395396
package.dependencies.append(privateFrameworkRepo)
396-
openAttributeGraphShimsTarget.addAGSettings()
397397

398398
let agVersion = EnvManager.shared.withDomain("DarwinPrivateFrameworks") {
399399
envIntValue("TARGET_RELEASE", default: 2024)
@@ -403,6 +403,44 @@ if attributeGraphCondition {
403403
case 2021: [.iOS(.v15), .macOS(.v12), .macCatalyst(.v15), .tvOS(.v15), .watchOS(.v7)]
404404
default: nil
405405
}
406+
}
407+
408+
if compatibilityTestCondition {
409+
setupDPFDependency()
410+
openAttributeGraphCompatibilityTestsTarget.addAGSettings()
411+
} else {
412+
package.targets += [
413+
utilitiesTestsTarget,
414+
openAttributeGraphCxxTestsTarget,
415+
openAttributeGraphShimsTestsTarget,
416+
]
417+
}
418+
419+
if buildForDarwinPlatform {
420+
package.targets.append(openAttributeGraphCompatibilityTestsTarget)
421+
}
422+
423+
if computeCondition {
424+
let computeBinary = envBoolValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY", default: true)
425+
if computeBinary {
426+
let computeVersion = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY_VERSION", default: "0.0.1")
427+
let computeURL = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY_URL", default: "https://github.com/Kyle-Ye/Compute/releases/download/\(computeVersion)/Compute.xcframework.zip")
428+
let computeChecksum = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY_CHECKSUM", default: "95a256da2055d7c73184aeb9be088ba7019f7ea79b8a31e2dd930526c5ccbe8f")
429+
package.targets.append(
430+
.binaryTarget(
431+
name: "Compute",
432+
url: computeURL,
433+
checksum: computeChecksum
434+
),
435+
)
436+
openAttributeGraphShimsTarget.addComputeBinarySettings()
437+
} else {
438+
// TODO
439+
}
440+
package.platforms = [.iOS(.v18), .macOS(.v15), .macCatalyst(.v18), .tvOS(.v18), .watchOS(.v10), .visionOS(.v2)]
441+
} else if attributeGraphCondition {
442+
setupDPFDependency()
443+
openAttributeGraphShimsTarget.addAGSettings()
406444
} else {
407445
openAttributeGraphShimsTarget.dependencies.append(.target(name: openAttributeGraphTarget.name))
408446
package.platforms = [.iOS(.v13), .macOS(.v10_15), .macCatalyst(.v13), .tvOS(.v13), .watchOS(.v5)]

‎Sources/OpenAttributeGraphShims/Graph+Debug.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Graph+Debug.swift
33
// OpenAttributeGraphShims
44

5-
#if canImport(Darwin)
5+
#if canImport(Darwin) && !OPENATTRIBUTEGRAPH_COMPUTE // Compute's descriptionFormatDictionary API is not aligned with OAG yet.
66

77
import Foundation
88

‎Sources/OpenAttributeGraphShims/GraphShims.swift‎

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,71 @@
22
// GraphShims.swift
33
// OpenAttributeGraphShims
44

5-
#if OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH
5+
public enum AttributeGraphVendor: String {
6+
case oag = "org.OpenSwiftUIProject.OpenAttributeGraph"
7+
case ag = "com.apple.AttributeGraph"
8+
case compute = "dev.incrematic.compute"
9+
}
10+
11+
#if OPENATTRIBUTEGRAPH_COMPUTE
12+
13+
@_exported public import Compute
14+
public typealias OAGAttributeInfo = AGAttributeInfo
15+
public typealias OAGCachedValueOptions = CachedValueOptions
16+
public typealias OAGChangedValueFlags = AGChangedValueFlags
17+
public typealias OAGInputOptions = AGInputOptions
18+
public typealias OAGValue = AGChangedValue
19+
public typealias OAGValueOptions = AGValueOptions
20+
21+
extension AnyAttribute {
22+
public typealias Flags = Subgraph.Flags
23+
}
24+
25+
extension AnyAttribute {
26+
public var subgraph2: Subgraph? { nil }
27+
}
28+
29+
30+
extension Subgraph {
31+
public typealias ChildFlags = AnyAttribute.Flags
32+
}
33+
34+
extension Graph {
35+
public static func startProfiling() {
36+
startProfiling(nil)
37+
}
38+
39+
public static func stopProfiling() {
40+
stopProfiling(nil)
41+
}
42+
43+
public func startProfiling() {
44+
Self.startProfiling(self)
45+
}
46+
47+
public func stopProfiling() {
48+
Self.stopProfiling(self)
49+
}
50+
51+
public func resetProfile() {
52+
// TODO: placeholder
53+
}
54+
}
55+
56+
extension _AttributeBody {
57+
public typealias Flags = _AttributeType.Flags
58+
}
59+
60+
extension CachedValueOptions {
61+
public static var _1: CachedValueOptions = .unprefetched
62+
}
63+
64+
@available(*, deprecated, renamed: "attributeGraphVendor")
65+
public let attributeGraphEnabled = true
66+
public let attributeGraphVendor = AttributeGraphVendor.compute
67+
68+
#elseif OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH
69+
670
@_exported public import AttributeGraph
771
#if os(iOS) && !targetEnvironment(simulator)
872
@_exported public import _AttributeGraphDeviceSwiftShims
@@ -13,9 +77,18 @@ public typealias OAGChangedValueFlags = AGChangedValueFlags
1377
public typealias OAGInputOptions = AGInputOptions
1478
public typealias OAGValue = AGValue
1579
public typealias OAGValueOptions = AGValueOptions
80+
81+
@available(*, deprecated, renamed: "attributeGraphVendor")
1682
public let attributeGraphEnabled = true
83+
public let attributeGraphVendor = AttributeGraphVendor.ag
84+
1785
#else
18-
@_exported import OpenAttributeGraph
1986

87+
@_exported import OpenAttributeGraph
88+
@available(*, deprecated, renamed: "attributeGraphVendor")
2089
public let attributeGraphEnabled = false
90+
public let attributeGraphVendor = AttributeGraphVendor.oag
2191
#endif
92+
93+
@available(*, deprecated, message: "swiftToolchainSupported is always true")
94+
public let swiftToolchainSupported = true

‎Tests/OpenAttributeGraphCompatibilityTests/GraphShims.swift‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#if OPENATTRIBUTEGRAPH
66
@_exported import OpenAttributeGraph
7-
87
let compatibilityTestEnabled = false
98
#else
109
@_exported public import AttributeGraph

0 commit comments

Comments
 (0)