From f49def3197ff7c8824dad12253bf4375222fc403 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 15 Dec 2024 16:03:16 +0800 Subject: [PATCH 1/3] Add RenderBox support --- .github/workflows/compatibility_tests.yml | 4 ++ .github/workflows/ios.yml | 2 + .github/workflows/macos.yml | 2 + Package.resolved | 15 ++++-- Package.swift | 52 ++++++++++++++----- Scripts/CI/darwin_setup_build.sh | 3 +- Scripts/CI/ob_setup.sh | 25 +++++++++ Sources/OpenSwiftUICore/Data/StrongHash.swift | 15 ++++-- .../Data/StrongHashTests.swift | 27 ++++++++++ 9 files changed, 123 insertions(+), 22 deletions(-) create mode 100755 Scripts/CI/ob_setup.sh diff --git a/.github/workflows/compatibility_tests.yml b/.github/workflows/compatibility_tests.yml index 4e1b141e7..971e9217f 100644 --- a/.github/workflows/compatibility_tests.yml +++ b/.github/workflows/compatibility_tests.yml @@ -25,6 +25,8 @@ jobs: OPENSWIFTUI_USE_LOCAL_DEPS: 1 OPENGRAPH_USE_LOCAL_DEPS: 1 OPENGRAPH_TARGET_RELEASE: ${{ matrix.release }} + OPENBOX_USE_LOCAL_DEPS: 1 + OPENBOX_TARGET_RELEASE: ${{ matrix.release }} DARWIN_PRIVATE_FRAMEWORKS_TARGET_RELEASE: ${{ matrix.release }} GH_TOKEN: ${{ github.token }} steps: @@ -75,6 +77,8 @@ jobs: OPENSWIFTUI_USE_LOCAL_DEPS: 1 OPENGRAPH_USE_LOCAL_DEPS: 1 OPENGRAPH_TARGET_RELEASE: ${{ matrix.release }} + OPENBOX_USE_LOCAL_DEPS: 1 + OPENBOX_TARGET_RELEASE: ${{ matrix.release }} DARWIN_PRIVATE_FRAMEWORKS_TARGET_RELEASE: ${{ matrix.release }} GH_TOKEN: ${{ github.token }} steps: diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 9af05e52d..38f678940 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -31,6 +31,8 @@ jobs: OPENSWIFTUI_USE_LOCAL_DEPS: 1 OPENGRAPH_USE_LOCAL_DEPS: 1 OPENGRAPH_TARGET_RELEASE: ${{ matrix.release }} + OPENBOX_USE_LOCAL_DEPS: 1 + OPENBOX_TARGET_RELEASE: ${{ matrix.release }} DARWIN_PRIVATE_FRAMEWORKS_TARGET_RELEASE: ${{ matrix.release }} GH_TOKEN: ${{ github.token }} steps: diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 91494f249..0c5ab1d99 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -26,6 +26,8 @@ jobs: OPENSWIFTUI_USE_LOCAL_DEPS: 1 OPENGRAPH_USE_LOCAL_DEPS: 1 OPENGRAPH_TARGET_RELEASE: ${{ matrix.release }} + OPENBOX_USE_LOCAL_DEPS: 1 + OPENBOX_TARGET_RELEASE: ${{ matrix.release }} DARWIN_PRIVATE_FRAMEWORKS_TARGET_RELEASE: ${{ matrix.release }} GH_TOKEN: ${{ github.token }} steps: diff --git a/Package.resolved b/Package.resolved index 5ebe8ff28..48eac7606 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "0c4677673310eb1475283b96def29718c2f307825c2d136e0bfc40f4cd3d6920", + "originHash" : "3ec5ceae50a3ce95edc97ef8b27b3a65cb61320642aa5cc535bb5d4690cb4230", "pins" : [ { "identity" : "darwinprivateframeworks", @@ -7,7 +7,16 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "fc757950da6df4b1e30a3236549a27f21f82ab8a" + "revision" : "5627dacbbde44c8d3ea7b34f5d91b44839178e15" + } + }, + { + "identity" : "openbox", + "kind" : "remoteSourceControl", + "location" : "https://github.com/OpenSwiftUIProject/OpenBox", + "state" : { + "branch" : "main", + "revision" : "95fa6020e10c1d3b2f9e91be5ba53864ec854b17" } }, { @@ -16,7 +25,7 @@ "location" : "https://github.com/OpenSwiftUIProject/OpenGraph", "state" : { "branch" : "main", - "revision" : "5eccfe5e3149b3deb4bf5b76511d2ea7f5b39b94" + "revision" : "6b413687605b91fd3f49c86523ce57dff0bfa1d2" } }, { diff --git a/Package.swift b/Package.swift index b20cb1c89..8ae814135 100644 --- a/Package.swift +++ b/Package.swift @@ -85,6 +85,7 @@ let openSwiftUICoreTarget = Target.target( dependencies: [ "OpenSwiftUI_SPI", .product(name: "OpenGraphShims", package: "OpenGraph"), + .product(name: "OpenBoxShims", package: "OpenBox"), ], swiftSettings: sharedSwiftSettings ) @@ -95,6 +96,7 @@ let openSwiftUITarget = Target.target( "COpenSwiftUI", .target(name: "CoreServices", condition: .when(platforms: [.iOS])), .product(name: "OpenGraphShims", package: "OpenGraph"), + .product(name: "OpenBoxShims", package: "OpenBox"), ], swiftSettings: sharedSwiftSettings ) @@ -231,12 +233,6 @@ let package = Package( ] ) -#if os(macOS) -let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH", default: true) -#else -let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH") -#endif - extension Target { func addAGSettings() { // FIXME: Weird SwiftPM behavior for test Target. Otherwize we'll get the following error message @@ -246,6 +242,15 @@ extension Target { swiftSettings.append(.define("OPENGRAPH_ATTRIBUTEGRAPH")) self.swiftSettings = swiftSettings } + + func addRBSettings() { + // FIXME: Weird SwiftPM behavior for test Target. Otherwize we'll get the following error message + // "could not determine executable path for bundle 'RenderBox.framework'" + dependencies.append(.product(name: "RenderBox", package: "DarwinPrivateFrameworks")) + var swiftSettings = swiftSettings ?? [] + swiftSettings.append(.define("OPENBOX_RENDERBOX")) + self.swiftSettings = swiftSettings + } func addOpenCombineSettings() { dependencies.append(.product(name: "OpenCombine", package: "OpenCombine")) @@ -271,15 +276,13 @@ extension Target { let useLocalDeps = envEnable("OPENSWIFTUI_USE_LOCAL_DEPS") +#if os(macOS) +let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH", default: true) +#else +let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH") +#endif + if attributeGraphCondition { - 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) - openSwiftUICoreTarget.addAGSettings() openSwiftUITarget.addAGSettings() @@ -290,14 +293,35 @@ if attributeGraphCondition { openSwiftUIBridgeTestTarget.addAGSettings() } +#if os(macOS) +let renderBoxCondition = envEnable("OPENBOX_RENDERBOX", default: true) +#else +let renderBoxCondition = envEnable("OPENBOX_RENDERBOX") +#endif + +if renderBoxCondition { + openSwiftUICoreTarget.addRBSettings() + openSwiftUITarget.addRBSettings() + + OpenSwiftUI_SPITestTarget.addRBSettings() + openSwiftUICoreTestTarget.addRBSettings() + openSwiftUITestTarget.addRBSettings() + openSwiftUICompatibilityTestTarget.addRBSettings() + openSwiftUIBridgeTestTarget.addRBSettings() +} + if useLocalDeps { package.dependencies += [ .package(path: "../OpenGraph"), + .package(path: "../OpenBox"), + .package(path: "../DarwinPrivateFrameworks"), ] } else { package.dependencies += [ // FIXME: on Linux platform: OG contains unsafe build flags which prevents us using version dependency .package(url: "https://github.com/OpenSwiftUIProject/OpenGraph", branch: "main"), + .package(url: "https://github.com/OpenSwiftUIProject/OpenBox", branch: "main"), + .package(url: "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", branch: "main"), ] } diff --git a/Scripts/CI/darwin_setup_build.sh b/Scripts/CI/darwin_setup_build.sh index 58056187d..e87a397ac 100755 --- a/Scripts/CI/darwin_setup_build.sh +++ b/Scripts/CI/darwin_setup_build.sh @@ -8,4 +8,5 @@ filepath() { REPO_ROOT="$(dirname $(dirname $(dirname $(filepath $0))))" cd $REPO_ROOT -Scripts/CI/og_setup.sh \ No newline at end of file +Scripts/CI/og_setup.sh +Scripts/CI/ob_setup.sh diff --git a/Scripts/CI/ob_setup.sh b/Scripts/CI/ob_setup.sh new file mode 100755 index 000000000..78a66df1e --- /dev/null +++ b/Scripts/CI/ob_setup.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# A `realpath` alternative using the default C implementation. +filepath() { + [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" +} + +REPO_ROOT="$(dirname $(dirname $(dirname $(filepath $0))))" + +clone_checkout_og() { + cd $REPO_ROOT + revision=$(Scripts/CI/get_revision.sh openbox) + cd .. + gh repo clone OpenSwiftUIProject/OpenBox + cd OpenBox + git checkout --quiet $revision +} + +update_og() { + cd $REPO_ROOT/../OpenBox + ./Scripts/CI/darwin_setup_build.sh +} + +clone_checkout_og +update_og diff --git a/Sources/OpenSwiftUICore/Data/StrongHash.swift b/Sources/OpenSwiftUICore/Data/StrongHash.swift index 02d157659..cd46056d5 100644 --- a/Sources/OpenSwiftUICore/Data/StrongHash.swift +++ b/Sources/OpenSwiftUICore/Data/StrongHash.swift @@ -3,7 +3,7 @@ // OpenSwiftUICore // // Audited for iOS 18.0 -// Status: Blocked by OGTypeGetSignature and RBUUID +// Status: Blocked by OGTypeGetSignature #if OPENSWIFTUI_SWIFT_CRYPTO import Crypto @@ -12,6 +12,7 @@ import CommonCrypto #endif import Foundation +import OpenBoxShims package protocol StronglyHashable { func hash(into hasher: inout StrongHasher) @@ -212,9 +213,15 @@ extension Float: StronglyHashableByBitPattern {} extension Double: StronglyHashableByBitPattern {} extension UUID: StronglyHashableByBitPattern {} -//extension RenderBox.RBUUID { -// package init(hash: StrongHash) -//} +extension OBUUID { + package init(hash: StrongHash) { + self.init( + UInt64(hash.words.0) | (UInt64(hash.words.1) << 32), + UInt64(hash.words.2) | (UInt64(hash.words.3) << 32), + 5 + ) + } +} extension StrongHash: ProtobufMessage { package func encode(to encoder: inout ProtobufEncoder) { diff --git a/Tests/OpenSwiftUICoreTests/Data/StrongHashTests.swift b/Tests/OpenSwiftUICoreTests/Data/StrongHashTests.swift index eb69d8b23..a2e02cc69 100644 --- a/Tests/OpenSwiftUICoreTests/Data/StrongHashTests.swift +++ b/Tests/OpenSwiftUICoreTests/Data/StrongHashTests.swift @@ -5,6 +5,7 @@ import OpenSwiftUICore import Testing import Foundation +import OpenBoxShims struct StrongHashTests { @Test( @@ -101,6 +102,32 @@ struct StrongHashTests { #expect(s2 == s) } + @Test( + arguments: [ + (StrongHash(), OBUUID(uuid: UUID(uuidString: "00500000-0000-0000-0000-000000000080")!)), + (StrongHash(of: 1), OBUUID(uuid: UUID(uuidString: "3D589EE2-73BE-1343-7E7E-CF760F3FBD8D")!)), + ] + ) + func obUUID(hash: StrongHash, expectedUUID: OBUUID) { + let uuid = OBUUID(hash: hash) + #expect(uuid.bytes.0 == expectedUUID.bytes.0) + #expect(uuid.bytes.1 == expectedUUID.bytes.1) + #expect(uuid.bytes.2 == expectedUUID.bytes.2) + #expect(uuid.bytes.3 == expectedUUID.bytes.3) + #expect(uuid.bytes.4 == expectedUUID.bytes.4) + #expect(uuid.bytes.5 == expectedUUID.bytes.5) + #expect(uuid.bytes.6 == expectedUUID.bytes.6) + #expect(uuid.bytes.7 == expectedUUID.bytes.7) + #expect(uuid.bytes.8 == expectedUUID.bytes.8) + #expect(uuid.bytes.9 == expectedUUID.bytes.9) + #expect(uuid.bytes.10 == expectedUUID.bytes.10) + #expect(uuid.bytes.11 == expectedUUID.bytes.11) + #expect(uuid.bytes.12 == expectedUUID.bytes.12) + #expect(uuid.bytes.13 == expectedUUID.bytes.13) + #expect(uuid.bytes.14 == expectedUUID.bytes.14) + #expect(uuid.bytes.15 == expectedUUID.bytes.15) + } + @Test( arguments: [ (StrongHash(), "0a140000000000000000000000000000000000000000"), From 474d44d2ec7fe92a965ae3a0d7b500f4622738ea Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 15 Dec 2024 16:23:18 +0800 Subject: [PATCH 2/3] Fix clone issue --- Package.resolved | 4 ++-- Scripts/CI/darwin_setup_build.sh | 1 + Scripts/CI/framework_setup.sh | 27 +++++++++++++++++++++++++++ Scripts/CI/ob_setup.sh | 4 +++- Scripts/CI/og_setup.sh | 4 +++- 5 files changed, 36 insertions(+), 4 deletions(-) create mode 100755 Scripts/CI/framework_setup.sh diff --git a/Package.resolved b/Package.resolved index 48eac7606..10844b86c 100644 --- a/Package.resolved +++ b/Package.resolved @@ -16,7 +16,7 @@ "location" : "https://github.com/OpenSwiftUIProject/OpenBox", "state" : { "branch" : "main", - "revision" : "95fa6020e10c1d3b2f9e91be5ba53864ec854b17" + "revision" : "e1626f862c9c6da0813a9b8bb4172978054bc6b6" } }, { @@ -25,7 +25,7 @@ "location" : "https://github.com/OpenSwiftUIProject/OpenGraph", "state" : { "branch" : "main", - "revision" : "6b413687605b91fd3f49c86523ce57dff0bfa1d2" + "revision" : "c1be687dddce061a6895cf6f7b6c22f79ca5aec4" } }, { diff --git a/Scripts/CI/darwin_setup_build.sh b/Scripts/CI/darwin_setup_build.sh index e87a397ac..667eebc84 100755 --- a/Scripts/CI/darwin_setup_build.sh +++ b/Scripts/CI/darwin_setup_build.sh @@ -10,3 +10,4 @@ cd $REPO_ROOT Scripts/CI/og_setup.sh Scripts/CI/ob_setup.sh +Scripts/CI/framework_setup.sh diff --git a/Scripts/CI/framework_setup.sh b/Scripts/CI/framework_setup.sh new file mode 100755 index 000000000..70df324ba --- /dev/null +++ b/Scripts/CI/framework_setup.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# A `realpath` alternative using the default C implementation. +filepath() { + [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" +} + +REPO_ROOT="$(dirname $(dirname $(dirname $(filepath $0))))" + +clone_checkout_dpf() { + cd $REPO_ROOT + revision=$(Scripts/CI/get_revision.sh darwinprivateframeworks) + cd .. + if [ ! -d DarwinPrivateFrameworks ]; then + gh repo clone OpenSwiftUIProject/DarwinPrivateFrameworks + fi + cd DarwinPrivateFrameworks + git checkout --quiet $revision +} + +update_dpf() { + cd $REPO_ROOT/../DarwinPrivateFrameworks + swift package update-xcframeworks --allow-writing-to-package-directory +} + +clone_checkout_dpf +update_dpf diff --git a/Scripts/CI/ob_setup.sh b/Scripts/CI/ob_setup.sh index 78a66df1e..58175b1fa 100755 --- a/Scripts/CI/ob_setup.sh +++ b/Scripts/CI/ob_setup.sh @@ -11,7 +11,9 @@ clone_checkout_og() { cd $REPO_ROOT revision=$(Scripts/CI/get_revision.sh openbox) cd .. - gh repo clone OpenSwiftUIProject/OpenBox + if [ ! -d OpenBox ]; then + gh repo clone OpenSwiftUIProject/OpenBox + fi cd OpenBox git checkout --quiet $revision } diff --git a/Scripts/CI/og_setup.sh b/Scripts/CI/og_setup.sh index 2e530f66f..786bdcbed 100755 --- a/Scripts/CI/og_setup.sh +++ b/Scripts/CI/og_setup.sh @@ -11,7 +11,9 @@ clone_checkout_og() { cd $REPO_ROOT revision=$(Scripts/CI/get_revision.sh opengraph) cd .. - gh repo clone OpenSwiftUIProject/OpenGraph + if [ ! -d OpenGraph ]; then + gh repo clone OpenSwiftUIProject/OpenGraph + fi cd OpenGraph git checkout --quiet $revision } From bea77a3a1a963cd8d29b0843f750670c0728f321 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 15 Dec 2024 16:32:21 +0800 Subject: [PATCH 3/3] Fix non-Darwin platform uuid API issue --- .../Data/StrongHashTests.swift | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Tests/OpenSwiftUICoreTests/Data/StrongHashTests.swift b/Tests/OpenSwiftUICoreTests/Data/StrongHashTests.swift index a2e02cc69..459fdb0dc 100644 --- a/Tests/OpenSwiftUICoreTests/Data/StrongHashTests.swift +++ b/Tests/OpenSwiftUICoreTests/Data/StrongHashTests.swift @@ -104,28 +104,28 @@ struct StrongHashTests { @Test( arguments: [ - (StrongHash(), OBUUID(uuid: UUID(uuidString: "00500000-0000-0000-0000-000000000080")!)), - (StrongHash(of: 1), OBUUID(uuid: UUID(uuidString: "3D589EE2-73BE-1343-7E7E-CF760F3FBD8D")!)), + (StrongHash(), (0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80)), + (StrongHash(of: 1), (0x3D, 0x58, 0x9E, 0xE2, 0x73, 0xBE, 0x13, 0x43, 0x7E, 0x7E, 0xCF, 0x76, 0x0F, 0x3F, 0xBD, 0x8D)), ] ) - func obUUID(hash: StrongHash, expectedUUID: OBUUID) { + func obUUID(hash: StrongHash, expectedBytes: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)) { let uuid = OBUUID(hash: hash) - #expect(uuid.bytes.0 == expectedUUID.bytes.0) - #expect(uuid.bytes.1 == expectedUUID.bytes.1) - #expect(uuid.bytes.2 == expectedUUID.bytes.2) - #expect(uuid.bytes.3 == expectedUUID.bytes.3) - #expect(uuid.bytes.4 == expectedUUID.bytes.4) - #expect(uuid.bytes.5 == expectedUUID.bytes.5) - #expect(uuid.bytes.6 == expectedUUID.bytes.6) - #expect(uuid.bytes.7 == expectedUUID.bytes.7) - #expect(uuid.bytes.8 == expectedUUID.bytes.8) - #expect(uuid.bytes.9 == expectedUUID.bytes.9) - #expect(uuid.bytes.10 == expectedUUID.bytes.10) - #expect(uuid.bytes.11 == expectedUUID.bytes.11) - #expect(uuid.bytes.12 == expectedUUID.bytes.12) - #expect(uuid.bytes.13 == expectedUUID.bytes.13) - #expect(uuid.bytes.14 == expectedUUID.bytes.14) - #expect(uuid.bytes.15 == expectedUUID.bytes.15) + #expect(uuid.bytes.0 == expectedBytes.0) + #expect(uuid.bytes.1 == expectedBytes.1) + #expect(uuid.bytes.2 == expectedBytes.2) + #expect(uuid.bytes.3 == expectedBytes.3) + #expect(uuid.bytes.4 == expectedBytes.4) + #expect(uuid.bytes.5 == expectedBytes.5) + #expect(uuid.bytes.6 == expectedBytes.6) + #expect(uuid.bytes.7 == expectedBytes.7) + #expect(uuid.bytes.8 == expectedBytes.8) + #expect(uuid.bytes.9 == expectedBytes.9) + #expect(uuid.bytes.10 == expectedBytes.10) + #expect(uuid.bytes.11 == expectedBytes.11) + #expect(uuid.bytes.12 == expectedBytes.12) + #expect(uuid.bytes.13 == expectedBytes.13) + #expect(uuid.bytes.14 == expectedBytes.14) + #expect(uuid.bytes.15 == expectedBytes.15) } @Test(