Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/compatibility_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ${{ matrix.os }}
env:
OPENATTRIBUTEGRAPH_WERROR: 1
OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH: 1
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH: 1
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 1
OPENATTRIBUTEGRAPH_USE_LOCAL_DEPS: 1
OPENATTRIBUTEGRAPH_TARGET_RELEASE: 2024
Expand Down
87 changes: 87 additions & 0 deletions .github/workflows/compute.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Compute

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
# TODO: Enable once Compute binary is available for Linux or source integration is supported
# compute_ubuntu_build:
# name: Build with Compute on Ubuntu
# strategy:
# fail-fast: false
# matrix:
# swift_version: ["6.1.3"]
# runs-on: ubuntu-22.04
# env:
# OPENATTRIBUTEGRAPH_WERROR: 1
# OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE: 1
# OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
# container: swift:${{ matrix.swift_version }}-jammy
# steps:
# - uses: actions/checkout@v4
# - name: Checkout Swift headers
# uses: ./.github/actions/checkout-swift-headers
# - name: Build in debug mode
# run: swift build -c debug

compute_macos_build:
name: Build with Compute on macOS
strategy:
fail-fast: false
matrix:
os: [macos-15]
xcode-version: ["16.4"]
runs-on: ${{ matrix.os }}
env:
OPENATTRIBUTEGRAPH_WERROR: 1
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE: 1
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
steps:
- uses: actions/checkout@v4
- name: Setup Xcode
uses: OpenSwiftUIProject/OpenSwiftUI/.github/actions/setup-xcode@main
with:
xcode-version: ${{ matrix.xcode-version }}
- name: Checkout Swift headers
uses: ./.github/actions/checkout-swift-headers
- name: Build in debug mode
run: swift build -c debug

compute_ios_build:
name: Build with Compute on iOS
strategy:
fail-fast: false
matrix:
os: [macos-15]
xcode-version: ["16.4"]
ios-version: ["18.5"]
include:
- ios-version: "18.5"
ios-simulator-name: "iPhone 16 Pro"
runs-on: ${{ matrix.os }}
env:
OPENATTRIBUTEGRAPH_WERROR: 1
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_COMPUTE: 1
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
steps:
- uses: actions/checkout@v4
- name: Setup Xcode
uses: OpenSwiftUIProject/OpenSwiftUI/.github/actions/setup-xcode@main
with:
xcode-version: ${{ matrix.xcode-version }}
- name: Checkout Swift headers
uses: ./.github/actions/checkout-swift-headers
- name: Build in debug mode on iOS Simulator
run: |
xcodebuild build \
-workspace .swiftpm/xcode/package.xcworkspace \
-scheme OpenAttributeGraph-Package \
-configuration Debug \
-destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \
-derivedDataPath .build-debug \
-skipMacroValidation \
-skipPackagePluginValidation \
OTHER_SWIFT_FLAGS="-warnings-as-errors"
2 changes: 1 addition & 1 deletion .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ${{ matrix.os }}
env:
OPENATTRIBUTEGRAPH_WERROR: 1
OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH: 0
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH: 0
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
OPENATTRIBUTEGRAPH_USE_LOCAL_DEPS: 1
OPENATTRIBUTEGRAPH_TARGET_RELEASE: 2024
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ${{ matrix.os }}
env:
OPENATTRIBUTEGRAPH_WERROR: 1
OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH: 0
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH: 0
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
OPENATTRIBUTEGRAPH_USE_LOCAL_DEPS: 1
OPENATTRIBUTEGRAPH_TARGET_RELEASE: 2024
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-22.04
env:
OPENATTRIBUTEGRAPH_WERROR: 1
OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH: 0
OPENATTRIBUTEGRAPH_OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH: 0
OPENATTRIBUTEGRAPH_COMPATIBILITY_TEST: 0
container: swift:${{ matrix.swift_version }}-jammy
steps:
Expand Down
2 changes: 1 addition & 1 deletion Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 54 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ let libraryEvolutionCondition = envBoolValue("LIBRARY_EVOLUTION", default: build
let compatibilityTestCondition = envBoolValue("COMPATIBILITY_TEST", default: false)

let useLocalDeps = envBoolValue("USE_LOCAL_DEPS")
let attributeGraphCondition = envBoolValue("ATTRIBUTEGRAPH", default: buildForDarwinPlatform && !isSPIBuild)
let computeCondition = envBoolValue("OPENATTRIBUTESHIMS_COMPUTE", default: false)
let attributeGraphCondition = envBoolValue("OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH", default: buildForDarwinPlatform && !isSPIBuild)

// MARK: - Shared Settings

Expand Down Expand Up @@ -228,6 +229,15 @@ extension Target {
swiftSettings.append(.define("OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH"))
self.swiftSettings = swiftSettings
}

func addComputeBinarySettings() {
dependencies.append(
"Compute",
)
var swiftSettings = swiftSettings ?? []
swiftSettings.append(.define("OPENATTRIBUTEGRAPH_COMPUTE"))
self.swiftSettings = swiftSettings
}
}

extension [Platform] {
Expand Down Expand Up @@ -371,29 +381,19 @@ let package = Package(
cxxLanguageStandard: .cxx20
)

if compatibilityTestCondition {
openAttributeGraphCompatibilityTestsTarget.addAGSettings()
} else {
package.targets += [
utilitiesTestsTarget,
openAttributeGraphCxxTestsTarget,
openAttributeGraphShimsTestsTarget,
]
}

if buildForDarwinPlatform {
package.targets.append(openAttributeGraphCompatibilityTestsTarget)
}
private var hasSetupDPFDependency = false

if attributeGraphCondition {
@MainActor
func setupDPFDependency() {
guard !hasSetupDPFDependency else { return }
hasSetupDPFDependency = true
let privateFrameworkRepo: Package.Dependency
if useLocalDeps {
privateFrameworkRepo = Package.Dependency.package(path: "../DarwinPrivateFrameworks")
} else {
privateFrameworkRepo = Package.Dependency.package(url: "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", branch: "main")
}
package.dependencies.append(privateFrameworkRepo)
openAttributeGraphShimsTarget.addAGSettings()

let agVersion = EnvManager.shared.withDomain("DarwinPrivateFrameworks") {
envIntValue("TARGET_RELEASE", default: 2024)
Expand All @@ -403,6 +403,44 @@ if attributeGraphCondition {
case 2021: [.iOS(.v15), .macOS(.v12), .macCatalyst(.v15), .tvOS(.v15), .watchOS(.v7)]
default: nil
}
}

if compatibilityTestCondition {
setupDPFDependency()
openAttributeGraphCompatibilityTestsTarget.addAGSettings()
} else {
package.targets += [
utilitiesTestsTarget,
openAttributeGraphCxxTestsTarget,
openAttributeGraphShimsTestsTarget,
]
}

if buildForDarwinPlatform {
package.targets.append(openAttributeGraphCompatibilityTestsTarget)
}

if computeCondition {
let computeBinary = envBoolValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY", default: true)
if computeBinary {
let computeVersion = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY_VERSION", default: "0.0.1")
let computeURL = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY_URL", default: "https://github.com/Kyle-Ye/Compute/releases/download/\(computeVersion)/Compute.xcframework.zip")
let computeChecksum = envStringValue("OPENATTRIBUTESHIMS_COMPUTE_BINARY_CHECKSUM", default: "95a256da2055d7c73184aeb9be088ba7019f7ea79b8a31e2dd930526c5ccbe8f")
package.targets.append(
.binaryTarget(
name: "Compute",
url: computeURL,
checksum: computeChecksum
),
)
openAttributeGraphShimsTarget.addComputeBinarySettings()
} else {
// TODO
}
package.platforms = [.iOS(.v18), .macOS(.v15), .macCatalyst(.v18), .tvOS(.v18), .watchOS(.v10), .visionOS(.v2)]
} else if attributeGraphCondition {
setupDPFDependency()
openAttributeGraphShimsTarget.addAGSettings()
} else {
openAttributeGraphShimsTarget.dependencies.append(.target(name: openAttributeGraphTarget.name))
package.platforms = [.iOS(.v13), .macOS(.v10_15), .macCatalyst(.v13), .tvOS(.v13), .watchOS(.v5)]
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenAttributeGraphShims/Graph+Debug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Graph+Debug.swift
// OpenAttributeGraphShims

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

import Foundation

Expand Down
77 changes: 75 additions & 2 deletions Sources/OpenAttributeGraphShims/GraphShims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,71 @@
// GraphShims.swift
// OpenAttributeGraphShims

#if OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH
public enum AttributeGraphVendor: String {
case oag = "org.OpenSwiftUIProject.OpenAttributeGraph"
case ag = "com.apple.AttributeGraph"
case compute = "dev.incrematic.compute"
}

#if OPENATTRIBUTEGRAPH_COMPUTE

@_exported public import Compute
public typealias OAGAttributeInfo = AGAttributeInfo
public typealias OAGCachedValueOptions = CachedValueOptions
public typealias OAGChangedValueFlags = AGChangedValueFlags
public typealias OAGInputOptions = AGInputOptions
public typealias OAGValue = AGChangedValue
public typealias OAGValueOptions = AGValueOptions

extension AnyAttribute {
public typealias Flags = Subgraph.Flags
}

extension AnyAttribute {
public var subgraph2: Subgraph? { nil }
}


extension Subgraph {
public typealias ChildFlags = AnyAttribute.Flags
}

extension Graph {
public static func startProfiling() {
startProfiling(nil)
}

public static func stopProfiling() {
stopProfiling(nil)
}

public func startProfiling() {
Self.startProfiling(self)
}

public func stopProfiling() {
Self.stopProfiling(self)
}

public func resetProfile() {
// TODO: placeholder
}
}

extension _AttributeBody {
public typealias Flags = _AttributeType.Flags
}

extension CachedValueOptions {
public static var _1: CachedValueOptions = .unprefetched
}

@available(*, deprecated, renamed: "attributeGraphVendor")
public let attributeGraphEnabled = true
public let attributeGraphVendor = AttributeGraphVendor.compute

#elseif OPENATTRIBUTEGRAPH_ATTRIBUTEGRAPH

@_exported public import AttributeGraph
#if os(iOS) && !targetEnvironment(simulator)
@_exported public import _AttributeGraphDeviceSwiftShims
Expand All @@ -13,9 +77,18 @@ public typealias OAGChangedValueFlags = AGChangedValueFlags
public typealias OAGInputOptions = AGInputOptions
public typealias OAGValue = AGValue
public typealias OAGValueOptions = AGValueOptions

@available(*, deprecated, renamed: "attributeGraphVendor")
public let attributeGraphEnabled = true
public let attributeGraphVendor = AttributeGraphVendor.ag

#else
@_exported import OpenAttributeGraph

@_exported import OpenAttributeGraph
@available(*, deprecated, renamed: "attributeGraphVendor")
public let attributeGraphEnabled = false
public let attributeGraphVendor = AttributeGraphVendor.oag
#endif

@available(*, deprecated, message: "swiftToolchainSupported is always true")
public let swiftToolchainSupported = true
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#if OPENATTRIBUTEGRAPH
@_exported import OpenAttributeGraph

let compatibilityTestEnabled = false
#else
@_exported public import AttributeGraph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import OpenAttributeGraphShims
import Testing

@MainActor
@Suite(.disabled(if: !attributeGraphEnabled, "Subgraph is not implemented on OAG"), .graphScope)
@Suite(.disabled(if: attributeGraphVendor == .oag, "Subgraph is not implemented on OAG"), .graphScope)
struct Attribute_DebugTests {
@Test
func directAttribute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import AppKit
private typealias PlatformView = NSView
#endif

@Suite(.disabled(if: !attributeGraphEnabled, "forEachField is not implemented for OAG"))
@Suite(.disabled(if: attributeGraphVendor == .oag, "forEachField is not implemented for OAG"))
struct MetadataDebugTests {
struct Demo1 {
var a: Int = .zero
Expand Down