From 4023048781f17cbd4f1dcff058ed77ffb731abf8 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 11 May 2025 15:36:16 +0800 Subject: [PATCH 1/6] Bump to Swift 6.1 Toolchain --- .github/workflows/compatibility_tests.yml | 4 +-- .github/workflows/ios.yml | 2 +- .github/workflows/macos.yml | 2 +- .github/workflows/ubuntu.yml | 2 +- README.md | 2 +- .../AppearanceActionModifierTests.swift | 4 --- .../Semantic/SemanticsTests.swift | 36 ------------------- 7 files changed, 6 insertions(+), 46 deletions(-) diff --git a/.github/workflows/compatibility_tests.yml b/.github/workflows/compatibility_tests.yml index 971e9217..81e25fc9 100644 --- a/.github/workflows/compatibility_tests.yml +++ b/.github/workflows/compatibility_tests.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: os: [macos-15] - xcode-version: ["16.0"] + xcode-version: ["16.3"] release: [2024] runs-on: ${{ matrix.os }} env: @@ -60,7 +60,7 @@ jobs: fail-fast: false matrix: os: [macos-15] - xcode-version: ["16.0"] + xcode-version: ["16.3"] release: [2024] ios-version: ["18.0"] include: diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 110d45dd..3c9dfb69 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: os: [macos-15] - xcode-version: ["16.0"] + xcode-version: ["16.3"] release: [2024] ios-version: ["18.0"] include: diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 5b081683..065c3c32 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: os: [macos-15] - xcode-version: ["16.0"] + xcode-version: ["16.3"] release: [2024] runs-on: ${{ matrix.os }} env: diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 5777f73b..c47dbf9a 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - swift_version: ["6.0.1"] + swift_version: ["6.1.0"] runs-on: ubuntu-22.04 env: OPENSWIFTUI_WERROR: 1 diff --git a/README.md b/README.md index d33ff290..fe02e2cf 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ See Example folder and try it with ExampleApp ## Build -The current suggested toolchain to build the project is Swift 6.0 / Xcode 16.0. +The current suggested toolchain to build the project is Swift 6.1 / Xcode 16.3. ### Build without testing framework diff --git a/Tests/OpenSwiftUICompatibilityTests/SwiftUICore/Modifier/ViewModifier/AppearanceActionModifierTests.swift b/Tests/OpenSwiftUICompatibilityTests/SwiftUICore/Modifier/ViewModifier/AppearanceActionModifierTests.swift index 6dd71c69..2f491923 100644 --- a/Tests/OpenSwiftUICompatibilityTests/SwiftUICore/Modifier/ViewModifier/AppearanceActionModifierTests.swift +++ b/Tests/OpenSwiftUICompatibilityTests/SwiftUICore/Modifier/ViewModifier/AppearanceActionModifierTests.swift @@ -34,9 +34,6 @@ struct AppearanceActionModifierTests { #endif } - #if !DEBUG || compiler(>=6.1) - // For Xcode 16.3-/Swift 6.1-, Xcode will infer OpaqueTypeErasure to be true which will make some difference to the result. - // And there is no way to opt-out it for package yet. @Test func idTest() async throws { enum Helper { @@ -69,6 +66,5 @@ struct AppearanceActionModifierTests { #expect(Helper.result.hasPrefix("AAD")) #endif } - #endif } #endif diff --git a/Tests/OpenSwiftUICoreTests/Semantic/SemanticsTests.swift b/Tests/OpenSwiftUICoreTests/Semantic/SemanticsTests.swift index 928a7d47..218fec6c 100644 --- a/Tests/OpenSwiftUICoreTests/Semantic/SemanticsTests.swift +++ b/Tests/OpenSwiftUICoreTests/Semantic/SemanticsTests.swift @@ -61,24 +61,6 @@ struct SemanticsTests { #expect(isDeployedOnOrAfter(.v5) == false) #expect(isDeployedOnOrAfter(.v6) == false) #expect(isDeployedOnOrAfter(.v7) == false) - #elseif compiler(>=6.0) - // Path: /Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Agents/xctest - // SDK version: 18.0 - // min version: 14.0 - #expect(isLinkedOnOrAfter(.v1) == true) - #expect(isLinkedOnOrAfter(.v2) == true) - #expect(isLinkedOnOrAfter(.v3) == true) - #expect(isLinkedOnOrAfter(.v4) == true) - #expect(isLinkedOnOrAfter(.v5) == true) - #expect(isLinkedOnOrAfter(.v6) == true) - #expect(isLinkedOnOrAfter(.v7) == false) - #expect(isDeployedOnOrAfter(.v1) == true) - #expect(isDeployedOnOrAfter(.v2) == true) - #expect(isDeployedOnOrAfter(.v3) == false) - #expect(isDeployedOnOrAfter(.v4) == false) - #expect(isDeployedOnOrAfter(.v5) == false) - #expect(isDeployedOnOrAfter(.v6) == false) - #expect(isDeployedOnOrAfter(.v7) == false) #endif #elseif os(macOS) #if compiler(<6.2) && compiler(>=6.1) @@ -99,24 +81,6 @@ struct SemanticsTests { #expect(isDeployedOnOrAfter(.v5) == true) #expect(isDeployedOnOrAfter(.v6) == false) #expect(isDeployedOnOrAfter(.v7) == false) - #elseif compiler(>=6.0) - // Path: /Applications/Xcode-16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Xcode/Agents/xctest - // SDK version: 15.0 - // min version: 13.0 - #expect(isLinkedOnOrAfter(.v1) == true) - #expect(isLinkedOnOrAfter(.v2) == true) - #expect(isLinkedOnOrAfter(.v3) == true) - #expect(isLinkedOnOrAfter(.v4) == true) - #expect(isLinkedOnOrAfter(.v5) == true) - #expect(isLinkedOnOrAfter(.v6) == true) - #expect(isLinkedOnOrAfter(.v7) == false) - #expect(isDeployedOnOrAfter(.v1) == true) - #expect(isDeployedOnOrAfter(.v2) == true) - #expect(isDeployedOnOrAfter(.v3) == true) - #expect(isDeployedOnOrAfter(.v4) == true) - #expect(isDeployedOnOrAfter(.v5) == false) - #expect(isDeployedOnOrAfter(.v6) == false) - #expect(isDeployedOnOrAfter(.v7) == false) #endif #endif } From 38292c5bd7a6198e59c27614d220448c0ccb2edf Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 11 May 2025 17:40:30 +0800 Subject: [PATCH 2/6] Add fix-toolchain.sh to workaround Linux toolchain issue --- .github/scripts/fix-toolchain.sh | 33 ++++++++++++++++++++++++++++++++ .github/workflows/ubuntu.yml | 4 ++++ 2 files changed, 37 insertions(+) create mode 100755 .github/scripts/fix-toolchain.sh diff --git a/.github/scripts/fix-toolchain.sh b/.github/scripts/fix-toolchain.sh new file mode 100755 index 00000000..447ef4c7 --- /dev/null +++ b/.github/scripts/fix-toolchain.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +# Find the path to swift binary +SWIFT_PATH=$(which swift) +echo "Swift binary found at: $SWIFT_PATH" + +# Extract the toolchain path from swift binary path +# Remove /usr/bin/swift from the path to get the toolchain root +TOOLCHAIN_ROOT=$(dirname $(dirname "$SWIFT_PATH")) +echo "Toolchain root: $TOOLCHAIN_ROOT" + +# Construct the path to CFBase.h +CFBASE_PATH="$TOOLCHAIN_ROOT/lib/swift/CoreFoundation/CFBase.h" +echo "Looking for CFBase.h at: $CFBASE_PATH" + +# Check if the file exists +if [ -f "$CFBASE_PATH" ]; then + echo "Found CFBase.h, applying patch..." + + # Create a backup of the original file + cp "$CFBASE_PATH" "$CFBASE_PATH.bak" + + # Replace the include line + sed -i 's/#include /\/\/ #include /g' "$CFBASE_PATH" + + echo "Patch applied successfully." + echo "Original file backed up at $CFBASE_PATH.bak" +else + echo "ERROR: Could not find CFBase.h in expected location." + echo "Toolchain structure may be different than expected." + exit 1 +fi diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index c47dbf9a..df8811c0 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -23,6 +23,10 @@ jobs: container: swift:${{ matrix.swift_version }}-jammy steps: - uses: actions/checkout@v4 + - name: Toolchain fix patch + run: | + # Fix swift-corelibs-foundation#5211 + .github/scripts/fix-toolchain.sh - name: Building and running tests in debug mode with coverage run: | swift test \ From 5533c19eb64dfd96ec95ce88dc3c6ff4cddc9346 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 11 May 2025 19:22:41 +0800 Subject: [PATCH 3/6] Fix IDView crash --- Sources/OpenSwiftUICore/View/IDView.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/OpenSwiftUICore/View/IDView.swift b/Sources/OpenSwiftUICore/View/IDView.swift index a05c271a..d29e485d 100644 --- a/Sources/OpenSwiftUICore/View/IDView.swift +++ b/Sources/OpenSwiftUICore/View/IDView.swift @@ -53,15 +53,16 @@ extension View { extension IDView { @usableFromInline package static func _makeView(view: _GraphValue, inputs: _ViewInputs) -> _ViewOutputs { - if _SemanticFeature_v2.isEnabled { - return makeImplicitRoot(view: view, inputs: inputs) - } else { + // FIXME: makeImplicitRoot is not implemented yet +// if _SemanticFeature_v2.isEnabled { +// return makeImplicitRoot(view: view, inputs: inputs) +// } else { let id = view.value[offset: { .of(&$0.id) }] let phase = IDPhase(id: id, phase: inputs.viewPhase, lastID: nil, delta: 0) var inputs = inputs inputs.viewPhase = Attribute(phase) return Content.makeDebuggableView(view: view[offset: { .of(&$0.content)}], inputs: inputs) - } +// } } } From 30d20ed088598b9888cf43d7c5555e931e090cdf Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 11 May 2025 21:07:55 +0800 Subject: [PATCH 4/6] Add OPENSWIFTUI_LIBRARY_EVOLUTION to fix the ABI call issue --- Package.resolved | 6 ++-- Package.swift | 14 ++++++++- .../Hosting/UIKit/View/UIHostingView.swift | 31 ++++++------------- .../AppKit/NSViewPlatformViewDefinition.swift | 21 ++----------- .../UIKit/UIViewPlatformViewDefinition.swift | 23 +++----------- Sources/OpenSwiftUI/Scene/Core/Scene.swift | 5 +++ .../DisplayList/DisplayListViewRenderer.swift | 12 +++---- .../Render/PlatformViewDefinition.swift | 9 ------ 8 files changed, 43 insertions(+), 78 deletions(-) diff --git a/Package.resolved b/Package.resolved index 42cac7e4..8fcc9bc8 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "c72e2bc714f92bcf02092961f7be834040b491a370d9391bb55c683896efa9b3", + "originHash" : "9ca697a10d8a0a61a84b81e3ce8848e297d4f66f9bb9de0b4b988b448b652b20", "pins" : [ { "identity" : "darwinprivateframeworks", @@ -16,7 +16,7 @@ "location" : "https://github.com/OpenSwiftUIProject/OpenBox", "state" : { "branch" : "main", - "revision" : "de81c145fd3ef582d4cb41b2190febf487ce6125" + "revision" : "3fb0395e4681d076a6876b12db5055cb59a468cb" } }, { @@ -25,7 +25,7 @@ "location" : "https://github.com/OpenSwiftUIProject/OpenGraph", "state" : { "branch" : "main", - "revision" : "5204ae0d031a520df99b5b2f32c5c9ddbfdb5036" + "revision" : "74d5cae4ec281717dd37644b332a72ab9fff1cd0" } }, { diff --git a/Package.swift b/Package.swift index 91b165bf..1180d815 100644 --- a/Package.swift +++ b/Package.swift @@ -123,6 +123,18 @@ if warningsAsErrorsCondition { // sharedSwiftSettings.append(.unsafeFlags(["-Wwarning", "concurrency"])) } +// MARK: - [env] OPENSWIFTUI_LIBRARY_EVOLUTION + +#if os(macOS) +let libraryEvolutionCondition = envEnable("OPENSWIFTUI_LIBRARY_EVOLUTION", default: true) +#else +let libraryEvolutionCondition = envEnable("OPENSWIFTUI_LIBRARY_EVOLUTION") +#endif + +if libraryEvolutionCondition { + sharedSwiftSettings.append(.unsafeFlags(["-enable-library-evolution"])) +} + // MARK: - CoreGraphicsShims Target let coreGraphicsShimsTarget = Target.target( @@ -352,7 +364,7 @@ let package = Package( name: "OpenSwiftUI", products: products, dependencies: [ - .package(url: "https://github.com/apple/swift-numerics.git", from: "1.0.3"), + .package(url: "https://github.com/apple/swift-numerics", from: "1.0.3"), ], targets: [ // TODO: Add SwiftGTK as an backend alternative for UIKit/AppKit on Linux and macOS diff --git a/Sources/OpenSwiftUI/Integration/Hosting/UIKit/View/UIHostingView.swift b/Sources/OpenSwiftUI/Integration/Hosting/UIKit/View/UIHostingView.swift index 5e69ee40..0df68c25 100644 --- a/Sources/OpenSwiftUI/Integration/Hosting/UIKit/View/UIHostingView.swift +++ b/Sources/OpenSwiftUI/Integration/Hosting/UIKit/View/UIHostingView.swift @@ -534,28 +534,15 @@ extension _UIHostingView: ViewRendererHost { let scale = window?.screen.scale ?? 1 let environment = DisplayList.ViewRenderer.Environment(contentsScale: scale) #if canImport(SwiftUI, _underlyingVersion: 6.0.87) && _OPENSWIFTUI_SWIFTUI_RENDER - return withUnsafePointer(to: list) { list in - withUnsafePointer(to: time) { time in - withUnsafePointer(to: nextTime) { nextTime in - withUnsafePointer(to: version) { version in - withUnsafePointer(to: maxVersion) { maxVersion in - withUnsafePointer(to: environment) { environment in - return renderer - .swiftUI_render( - rootView: self, - from: list, - time: time, - nextTime: nextTime, - version: version, - maxVersion: maxVersion, - environment: environment - ) - } - } - } - } - } - } + return renderer.swiftUI_render( + rootView: self, + from: list, + time: time, + nextTime: nextTime, + version: version, + maxVersion: maxVersion, + environment: environment + ) #else return renderer.render( rootView: self, diff --git a/Sources/OpenSwiftUI/Integration/Render/AppKit/NSViewPlatformViewDefinition.swift b/Sources/OpenSwiftUI/Integration/Render/AppKit/NSViewPlatformViewDefinition.swift index 1cca82f9..7afc54ea 100644 --- a/Sources/OpenSwiftUI/Integration/Render/AppKit/NSViewPlatformViewDefinition.swift +++ b/Sources/OpenSwiftUI/Integration/Render/AppKit/NSViewPlatformViewDefinition.swift @@ -13,28 +13,13 @@ import AppKit final class NSViewPlatformViewDefinition: PlatformViewDefinition, @unchecked Sendable { override final class var system: PlatformViewDefinition.System { .nsView } - #if _OPENSWIFTUI_SWIFTUI_RENDER - override static func makeView(kind: UnsafePointer) -> AnyObject { - _makeView(kind: kind.pointee) - } - - override static func makeLayerView(type: CALayer.Type, kind: UnsafePointer) -> AnyObject { - preconditionFailure("TODO") - } - #else override static func makeView(kind: PlatformViewDefinition.ViewKind) -> AnyObject { - _makeView(kind: kind) + // TODO + return NSView() } - override static func makeLayerView(type: CALayer.Type, kind: UnsafePointer) -> AnyObject { + override static func makeLayerView(type: CALayer.Type, kind: PlatformViewDefinition.ViewKind) -> AnyObject { preconditionFailure("TODO") } - #endif - - // FIXME: A shim for _OPENSWIFTUI_SWIFTUI_RENDER - private static func _makeView(kind: PlatformViewDefinition.ViewKind) -> AnyObject { - // TODO - return NSView() - } } #endif diff --git a/Sources/OpenSwiftUI/Integration/Render/UIKit/UIViewPlatformViewDefinition.swift b/Sources/OpenSwiftUI/Integration/Render/UIKit/UIViewPlatformViewDefinition.swift index 4dd84a15..8fca851b 100644 --- a/Sources/OpenSwiftUI/Integration/Render/UIKit/UIViewPlatformViewDefinition.swift +++ b/Sources/OpenSwiftUI/Integration/Render/UIKit/UIViewPlatformViewDefinition.swift @@ -15,26 +15,7 @@ import OpenSwiftUISymbolDualTestsSupport final class UIViewPlatformViewDefinition: PlatformViewDefinition, @unchecked Sendable { override final class var system: PlatformViewDefinition.System { .uiView } - #if _OPENSWIFTUI_SWIFTUI_RENDER - override static func makeView(kind: UnsafePointer) -> AnyObject { - _makeView(kind: kind.pointee) - } - - override static func makeLayerView(type: CALayer.Type, kind: UnsafePointer) -> AnyObject { - preconditionFailure("TODO") - } - #else override static func makeView(kind: PlatformViewDefinition.ViewKind) -> AnyObject { - _makeView(kind: kind) - } - - override static func makeLayerView(type: CALayer.Type, kind: UnsafePointer) -> AnyObject { - preconditionFailure("TODO") - } - #endif - - // FIXME: A shim for _OPENSWIFTUI_SWIFTUI_RENDER - private static func _makeView(kind: PlatformViewDefinition.ViewKind) -> AnyObject { let view: UIView switch kind { case .mask: @@ -48,6 +29,10 @@ final class UIViewPlatformViewDefinition: PlatformViewDefinition, @unchecked Sen return view } + override static func makeLayerView(type: CALayer.Type, kind: PlatformViewDefinition.ViewKind) -> AnyObject { + preconditionFailure("TODO") + } + private static func initView(_ view: UIView, kind: PlatformViewDefinition.ViewKind) { if kind != .platformView && kind != .platformGroup { view.autoresizesSubviews = false diff --git a/Sources/OpenSwiftUI/Scene/Core/Scene.swift b/Sources/OpenSwiftUI/Scene/Core/Scene.swift index c15499bc..9929ad2a 100644 --- a/Sources/OpenSwiftUI/Scene/Core/Scene.swift +++ b/Sources/OpenSwiftUI/Scene/Core/Scene.swift @@ -5,6 +5,10 @@ // Audited for iOS 15.5 // Status: Empty +#if canImport(CoreTransferable) +import CoreTransferable +#endif + public protocol Scene { associatedtype Body: Scene @@ -12,6 +16,7 @@ public protocol Scene { var body: Self.Body { get } // static func _makeScene(scene: _GraphValue, inputs: _SceneInputs) -> _SceneOutputs } + extension Never: Scene {} extension Scene { diff --git a/Sources/OpenSwiftUICore/Render/DisplayList/DisplayListViewRenderer.swift b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayListViewRenderer.swift index f919ca3f..c51395db 100644 --- a/Sources/OpenSwiftUICore/Render/DisplayList/DisplayListViewRenderer.swift +++ b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayListViewRenderer.swift @@ -102,12 +102,12 @@ extension DisplayList { @_silgen_name("OpenSwiftUITestStub_DisplayListViewRendererRenderRootView") package func swiftUI_render( rootView: AnyObject, - from list: UnsafePointer, - time: UnsafePointer