diff --git a/.github/workflows/compatibility_tests.yml b/.github/workflows/compatibility_tests.yml index 37dd4cd7..3cddb456 100644 --- a/.github/workflows/compatibility_tests.yml +++ b/.github/workflows/compatibility_tests.yml @@ -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 diff --git a/.github/workflows/compute.yml b/.github/workflows/compute.yml new file mode 100644 index 00000000..9eaa6d0c --- /dev/null +++ b/.github/workflows/compute.yml @@ -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" diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 96e1d1f4..28711e0a 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -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 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 415b00fa..073d1289 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -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 diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 837a2aa5..b2b2ee0f 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -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: diff --git a/Package.resolved b/Package.resolved index f1292358..1d57a55c 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "7cadfd6a4a6cf485f04ff5aa897337517fef87f64481cddaec20bd780bb6477b", + "originHash" : "c701311871fbdd16aa96ae8f8d658ebd97d689e34d15195d51d8f60598d9ea59", "pins" : [ { "identity" : "darwinprivateframeworks", diff --git a/Package.swift b/Package.swift index 55755a2f..155135f6 100644 --- a/Package.swift +++ b/Package.swift @@ -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 @@ -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] { @@ -371,21 +381,12 @@ 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") @@ -393,7 +394,6 @@ if attributeGraphCondition { 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) @@ -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)] diff --git a/Sources/OpenAttributeGraphShims/Graph+Debug.swift b/Sources/OpenAttributeGraphShims/Graph+Debug.swift index bce0044c..ce0ae5e8 100644 --- a/Sources/OpenAttributeGraphShims/Graph+Debug.swift +++ b/Sources/OpenAttributeGraphShims/Graph+Debug.swift @@ -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 diff --git a/Sources/OpenAttributeGraphShims/GraphShims.swift b/Sources/OpenAttributeGraphShims/GraphShims.swift index 58dc10e7..a0b994ae 100644 --- a/Sources/OpenAttributeGraphShims/GraphShims.swift +++ b/Sources/OpenAttributeGraphShims/GraphShims.swift @@ -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 @@ -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 diff --git a/Tests/OpenAttributeGraphCompatibilityTests/GraphShims.swift b/Tests/OpenAttributeGraphCompatibilityTests/GraphShims.swift index 69608225..aa40545e 100644 --- a/Tests/OpenAttributeGraphCompatibilityTests/GraphShims.swift +++ b/Tests/OpenAttributeGraphCompatibilityTests/GraphShims.swift @@ -4,7 +4,6 @@ #if OPENATTRIBUTEGRAPH @_exported import OpenAttributeGraph - let compatibilityTestEnabled = false #else @_exported public import AttributeGraph diff --git a/Tests/OpenAttributeGraphShimsTests/Attribute+DebugTests.swift b/Tests/OpenAttributeGraphShimsTests/Attribute+DebugTests.swift index edc0e7e5..8a5e6b50 100644 --- a/Tests/OpenAttributeGraphShimsTests/Attribute+DebugTests.swift +++ b/Tests/OpenAttributeGraphShimsTests/Attribute+DebugTests.swift @@ -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() { diff --git a/Tests/OpenAttributeGraphShimsTests/MetadataDebugTests.swift b/Tests/OpenAttributeGraphShimsTests/MetadataDebugTests.swift index fd245b4e..2da05cd7 100644 --- a/Tests/OpenAttributeGraphShimsTests/MetadataDebugTests.swift +++ b/Tests/OpenAttributeGraphShimsTests/MetadataDebugTests.swift @@ -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