diff --git a/.github/workflows/compatibility_tests.yml b/.github/workflows/compatibility_tests.yml index f7d5a41..d48c614 100644 --- a/.github/workflows/compatibility_tests.yml +++ b/.github/workflows/compatibility_tests.yml @@ -14,11 +14,10 @@ jobs: matrix: include: - os: macos-14 - xcode-version: "15.3" # Swift 5.10 + xcode-version: "16.0" # Swift 6.0 runs-on: ${{ matrix.os }} env: OPENGRAPH_WERROR: 1 - OPENGRAPH_SWIFT_TESTING: 1 OPENGRAPH_ATTRIBUTEGRAPH: 1 OPENGRAPH_COMPATIBILITY_TEST: 1 steps: diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 4b7a65b..5c11ed1 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -12,13 +12,15 @@ jobs: strategy: fail-fast: false matrix: + os: [macos-14] + xcode-version: ["16.0"] # Swift 6.0 + ios-version: ["18.0"] include: - - os: macos-14 - xcode-version: "15.3" # Swift 5.10 + - ios-version: "18.0" + ios-simulator-name: "iPhone 16 Pro" runs-on: ${{ matrix.os }} env: OPENGRAPH_WERROR: 1 - OPENGRAPH_SWIFT_TESTING: 1 OPENGRAPH_ATTRIBUTEGRAPH: 0 OPENGRAPH_COMPATIBILITY_TEST: 0 steps: @@ -34,7 +36,7 @@ jobs: xcodebuild build \ -scheme OpenGraph-Package \ -configuration Debug \ - -destination "platform=iOS" \ + -destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \ -derivedDataPath .build-debug \ -skipMacroValidation \ -skipPackagePluginValidation \ @@ -44,16 +46,16 @@ jobs: xcodebuild test \ -scheme OpenGraph-Package \ -configuration Debug \ - -destination "platform=iOS-Simulator" \ + -destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \ -enableCodeCoverage=YES \ -derivedDataPath .build-test-debug \ -skipPackagePluginValidation \ -skipMacroValidation # OTHER_SWIFT_FLAGS="-warnings-as-errors" Conflicting options '-warnings-as-errors' and '-suppress-warnings' - profdata_file_path=$(find . -path "*.build-test-debug/Build/ProfileData*Coverage.profdata" -type f) + profdata_file_path=$(find . -path "./.build-test-debug/Build/ProfileData/*/Coverage.profdata" -type f) xcrun llvm-cov show \ -instr-profile=$profdata_file_path \ - .build-test-debug/Build/Products/Debug/OpenGraphTests.xctest/Contents/MacOS/OpenGraphTests \ + .build-test-debug/Build/Products/Debug-iphonesimulator/OpenGraphTests.xctest/OpenGraphTests \ > coverage.txt - uses: codecov/codecov-action@v3 with: diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 86501ab..d80940e 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -12,13 +12,11 @@ jobs: strategy: fail-fast: false matrix: - include: - - os: macos-14 - xcode-version: "15.3" # Swift 5.10 + os: [macos-14] + xcode-version: [16.0] # Swift 6.0 runs-on: ${{ matrix.os }} env: OPENGRAPH_WERROR: 1 - OPENGRAPH_SWIFT_TESTING: 1 OPENGRAPH_ATTRIBUTEGRAPH: 0 OPENGRAPH_COMPATIBILITY_TEST: 0 steps: diff --git a/Package.resolved b/Package.resolved index c749553..7a9b51e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "08c5b038cf77a79fefbf15fe8ee430265dbe92590190dde25f83708222a7942f", + "originHash" : "498a1f428fea568463979c5b752f310e4e634606592667edadb13772101a8f20", "pins" : [ { "identity" : "swift-numerics", @@ -9,24 +9,6 @@ "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", "version" : "1.0.2" } - }, - { - "identity" : "swift-syntax", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-syntax.git", - "state" : { - "revision" : "fa8f95c2d536d6620cc2f504ebe8a6167c9fc2dd", - "version" : "510.0.1" - } - }, - { - "identity" : "swift-testing", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-testing", - "state" : { - "revision" : "8097dd8bcf7f2ed85f8aa8883635ce413012f53b", - "version" : "0.6.0" - } } ], "version" : 3 diff --git a/Package.swift b/Package.swift index 4698e25..d1dda28 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.10 +// swift-tools-version: 6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import Foundation @@ -20,7 +20,9 @@ func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool { let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode" let development = envEnable("OPENGRAPH_DEVELOPMENT", default: false) -var sharedSwiftSettings: [SwiftSetting] = [] +var sharedSwiftSettings: [SwiftSetting] = [ + .swiftLanguageMode(.v5), +] let warningsAsErrorsCondition = envEnable("OPENGRAPH_WERROR", default: isXcodeEnv && development) if warningsAsErrorsCondition { @@ -51,13 +53,12 @@ let openGraphTestTarget = Target.testTarget( ) let openGraphCompatibilityTestTarget = Target.testTarget( name: "OpenGraphCompatibilityTests", + dependencies: [ + .product(name: "RealModule", package: "swift-numerics"), + ], exclude: ["README.md"], swiftSettings: sharedSwiftSettings ) -let openGraphTempTestTarget = Target.testTarget( - name: "OpenGraphTempTests", - exclude: ["README.md"] -) let swiftBinPath = Context.environment["_"] ?? "" let swiftBinURL = URL(fileURLWithPath: swiftBinPath) @@ -78,6 +79,9 @@ let package = Package( .library(name: "OpenGraphShims", targets: ["OpenGraphShims"]), .library(name: "OpenGraph", targets: ["OpenGraph"]), ], + dependencies: [ + .package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"), + ], targets: [ // FIXME: Merge into one target // OpenGraph is a C++ & Swift mix target. @@ -106,6 +110,10 @@ let package = Package( ) ), openGraphShimsTarget, + + openGraphTestTarget, + openGraphShimsTestTarget, + openGraphCompatibilityTestTarget, ], cxxLanguageStandard: .cxx17 ) @@ -131,45 +139,14 @@ if attributeGraphCondition { openGraphShimsTarget.dependencies.append("OpenGraph") } -// Remove this when swift-testing is 1.0.0 -let swiftTestingCondition = envEnable("OPENGRAPH_SWIFT_TESTING", default: true) -if swiftTestingCondition { - var dependencies = package.dependencies - dependencies.append(contentsOf: [ - .package(url: "https://github.com/apple/swift-testing", exact: "0.6.0"), - .package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"), - ]) - package.dependencies = dependencies - - func addTestDependency(_ target: Target) { - var dependencies = target.dependencies - dependencies.append(contentsOf: [ - .product(name: "Testing", package: "swift-testing"), - .product(name: "RealModule", package: "swift-numerics"), - ]) - target.dependencies = dependencies - } - addTestDependency(openGraphTestTarget) - package.targets.append(openGraphTestTarget) - addTestDependency(openGraphCompatibilityTestTarget) - package.targets.append(openGraphCompatibilityTestTarget) - addTestDependency(openGraphTempTestTarget) - package.targets.append(openGraphTempTestTarget) - addTestDependency(openGraphShimsTestTarget) - package.targets.append(openGraphShimsTestTarget) -} - let compatibilityTestCondition = envEnable("OPENGRAPH_COMPATIBILITY_TEST") if compatibilityTestCondition && attributeGraphCondition { openGraphCompatibilityTestTarget.dependencies.append("AttributeGraph") - openGraphTempTestTarget.dependencies.append("AttributeGraph") var swiftSettings: [SwiftSetting] = (openGraphCompatibilityTestTarget.swiftSettings ?? []) swiftSettings.append(.define("OPENGRAPH_COMPATIBILITY_TEST")) openGraphCompatibilityTestTarget.swiftSettings = swiftSettings - openGraphTempTestTarget.swiftSettings = swiftSettings } else { openGraphCompatibilityTestTarget.dependencies.append("OpenGraph") - openGraphTempTestTarget.dependencies.append("OpenGraph") } extension [Platform] { diff --git a/Package@swift-5.10.swift b/Package@swift-5.10.swift new file mode 100644 index 0000000..e712d85 --- /dev/null +++ b/Package@swift-5.10.swift @@ -0,0 +1,170 @@ +// swift-tools-version: 5.10 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import Foundation +import PackageDescription + +func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool { + guard let value = Context.environment[key] else { + return defaultValue + } + if value == "1" { + return true + } else if value == "0" { + return false + } else { + return defaultValue + } +} + +let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode" +let development = envEnable("OPENGRAPH_DEVELOPMENT", default: false) + +var sharedSwiftSettings: [SwiftSetting] = [] + +let warningsAsErrorsCondition = envEnable("OPENGRAPH_WERROR", default: isXcodeEnv && development) +if warningsAsErrorsCondition { + sharedSwiftSettings.append(.unsafeFlags(["-warnings-as-errors"])) +} + +let openGraphShimsTarget = Target.target( + name: "OpenGraphShims", + swiftSettings: sharedSwiftSettings +) + +let openGraphShimsTestTarget = Target.testTarget( + name: "OpenGraphShimsTests", + dependencies: [ + "OpenGraphShims", + ], + exclude: ["README.md"], + swiftSettings: sharedSwiftSettings +) + +let openGraphTestTarget = Target.testTarget( + name: "OpenGraphTests", + dependencies: [ + "OpenGraph", + ], + exclude: ["README.md"], + swiftSettings: sharedSwiftSettings +) +let openGraphCompatibilityTestTarget = Target.testTarget( + name: "OpenGraphCompatibilityTests", + exclude: ["README.md"], + swiftSettings: sharedSwiftSettings +) + +let swiftBinPath = Context.environment["_"] ?? "" +let swiftBinURL = URL(fileURLWithPath: swiftBinPath) +let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path +let includePath = SDKPath.appending("/usr/lib/swift_static") + +let package = Package( + name: "OpenGraph", + platforms: [ + .iOS(.v13), + .macOS(.v10_15), + .macCatalyst(.v13), + .tvOS(.v13), + .watchOS(.v6), + .visionOS(.v1), + ], + products: [ + .library(name: "OpenGraphShims", targets: ["OpenGraphShims"]), + .library(name: "OpenGraph", targets: ["OpenGraph"]), + ], + targets: [ + // FIXME: Merge into one target + // OpenGraph is a C++ & Swift mix target. + // The SwiftPM support for such usage is still in progress. + .target( + name: "_OpenGraph", + cSettings: [ + .unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)), + .define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)), + ], + cxxSettings: [ + .unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)), + .define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)), + ] + ), + .target( + name: "OpenGraph", + dependencies: ["_OpenGraph"], + swiftSettings: sharedSwiftSettings + ), + .plugin( + name: "UpdateModule", + capability: .command( + intent: .custom(verb: "update-module", description: "Update AG xcframework"), + permissions: [.writeToPackageDirectory(reason: "Update AG xcframework")] + ) + ), + openGraphShimsTarget, + ], + cxxLanguageStandard: .cxx17 +) + +#if os(macOS) +// FIXME: Enable it by default will cause non-iOS/macOS Apple OS build fail currently. +// Add the corresponding tbd file and framework to fix it. +let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH", default: true) +#else +let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH") +#endif +if attributeGraphCondition { + let attributeGraphProduct = Product.library(name: "AttributeGraph", targets: ["AttributeGraph"]) + let attributeGraphTarget = Target.binaryTarget(name: "AttributeGraph", path: "AG/AttributeGraph.xcframework") + package.products.append(attributeGraphProduct) + package.targets.append(attributeGraphTarget) + + var swiftSettings: [SwiftSetting] = (openGraphShimsTarget.swiftSettings ?? []) + swiftSettings.append(.define("OPENGRAPH_ATTRIBUTEGRAPH")) + openGraphShimsTarget.swiftSettings = swiftSettings + openGraphShimsTarget.dependencies.append("AttributeGraph") +} else { + openGraphShimsTarget.dependencies.append("OpenGraph") +} + +// Remove this when swift-testing is 1.0.0 +let swiftTestingCondition = envEnable("OPENGRAPH_SWIFT_TESTING", default: true) +if swiftTestingCondition { + var dependencies = package.dependencies + dependencies.append(contentsOf: [ + .package(url: "https://github.com/apple/swift-testing", exact: "0.6.0"), + .package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"), + ]) + package.dependencies = dependencies + + func addTestDependency(_ target: Target) { + var dependencies = target.dependencies + dependencies.append(contentsOf: [ + .product(name: "Testing", package: "swift-testing"), + .product(name: "RealModule", package: "swift-numerics"), + ]) + target.dependencies = dependencies + } + addTestDependency(openGraphTestTarget) + package.targets.append(openGraphTestTarget) + addTestDependency(openGraphCompatibilityTestTarget) + package.targets.append(openGraphCompatibilityTestTarget) + addTestDependency(openGraphShimsTestTarget) + package.targets.append(openGraphShimsTestTarget) +} + +let compatibilityTestCondition = envEnable("OPENGRAPH_COMPATIBILITY_TEST") +if compatibilityTestCondition && attributeGraphCondition { + openGraphCompatibilityTestTarget.dependencies.append("AttributeGraph") + var swiftSettings: [SwiftSetting] = (openGraphCompatibilityTestTarget.swiftSettings ?? []) + swiftSettings.append(.define("OPENGRAPH_COMPATIBILITY_TEST")) + openGraphCompatibilityTestTarget.swiftSettings = swiftSettings +} else { + openGraphCompatibilityTestTarget.dependencies.append("OpenGraph") +} + +extension [Platform] { + static var nonDarwinPlatforms: [Platform] { + [.linux, .android, .wasi, .openbsd, .windows] + } +} diff --git a/Plugins/UpdateModule/UpdateModuleCommand.swift b/Plugins/UpdateModule/UpdateModuleCommand.swift index eecec11..49a2704 100644 --- a/Plugins/UpdateModule/UpdateModuleCommand.swift +++ b/Plugins/UpdateModule/UpdateModuleCommand.swift @@ -11,17 +11,16 @@ import Foundation struct UpdateModuleCommand: CommandPlugin { func performCommand(context: PackagePlugin.PluginContext, arguments: [String]) async throws { let process = Process() - - let path = try context.tool(named: "zsh").path.string - let url: URL? #if os(macOS) - url = if #available(macOS 14, *) { + let path: String = try context.tool(named: "zsh").url.path() + let url: URL? = if #available(macOS 14, *) { URL(filePath: path) } else { URL(string: "file://\(path)") } #else - url = URL(string: "file://\(path)") + let path = try context.tool(named: "zsh").path.string + let url = URL(string: "file://\(path)") #endif process.executableURL = url process.arguments = ["AG/update.sh"] diff --git a/Sources/OpenGraph/Attribute/Attribute/OGAttribute.swift b/Sources/OpenGraph/Attribute/Attribute/OGAttribute.swift index 62d4929..7fecc84 100644 --- a/Sources/OpenGraph/Attribute/Attribute/OGAttribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/OGAttribute.swift @@ -78,7 +78,7 @@ extension OGAttribute { // MARK: CustomStringConvertible -extension OGAttribute: CustomStringConvertible { +extension OGAttribute: Swift.CustomStringConvertible { @inlinable public var description: String { "#\(rawValue)" } } diff --git a/Sources/OpenGraph/Attribute/Weak/OGWeakAttribute.swift b/Sources/OpenGraph/Attribute/Weak/OGWeakAttribute.swift index 8633e62..3073da7 100644 --- a/Sources/OpenGraph/Attribute/Weak/OGWeakAttribute.swift +++ b/Sources/OpenGraph/Attribute/Weak/OGWeakAttribute.swift @@ -35,7 +35,7 @@ extension OGWeakAttribute { } } -extension OGWeakAttribute: Hashable { +extension OGWeakAttribute: Swift.Hashable { @_alwaysEmitIntoClient public static func == (lhs: OGWeakAttribute, rhs: OGWeakAttribute) -> Bool { lhs.raw_attribute == rhs.raw_attribute && lhs.subgraph_id == rhs.subgraph_id @@ -53,7 +53,7 @@ extension OGWeakAttribute: Hashable { } } -extension OGWeakAttribute: CustomStringConvertible { +extension OGWeakAttribute: Swift.CustomStringConvertible { @_alwaysEmitIntoClient public var description: String { attribute?.description ?? "nil" } } diff --git a/Sources/OpenGraph/Runtime/OGTypeID.swift b/Sources/OpenGraph/Runtime/OGTypeID.swift index f068b36..f43c0d5 100644 --- a/Sources/OpenGraph/Runtime/OGTypeID.swift +++ b/Sources/OpenGraph/Runtime/OGTypeID.swift @@ -23,7 +23,7 @@ public func OGTypeApplyFields2( body: (UnsafePointer, Int, Any.Type) -> Bool ) -> Bool -extension OGTypeID: Hashable, CustomStringConvertible { +extension OGTypeID: Swift.Hashable, Swift.CustomStringConvertible { @inlinable @inline(__always) public init(_ type: Any.Type) { diff --git a/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/PointerOffsetTests.swift b/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/PointerOffsetTests.swift index 41f3fa6..e52525e 100644 --- a/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/PointerOffsetTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/PointerOffsetTests.swift @@ -42,7 +42,8 @@ struct PointerOffsetTests { #expect(invalidPointer == UnsafeMutablePointer(bitPattern: stride)) } - @Test(.bug("#70", relationship: .verifiesFix)) + #if canImport(Darwin) + @Test(.bug("https://github.com/OpenSwiftUIProject/OpenGraph/issues", id: 70, "Verify fix")) func ofAndOffset() { struct Empty { var value: Void @@ -78,6 +79,7 @@ struct PointerOffsetTests { .of(&invalid.third) } } + #endif @Test("Extension API between UnsafePointer/UnsafeMutablePointer and PointerOffset") func unsafePointerAndUnsafeMutablePointerExtension() { diff --git a/Tests/OpenGraphCompatibilityTests/Scaffolding.swift b/Tests/OpenGraphCompatibilityTests/Scaffolding.swift index f326952..a1d5d8f 100644 --- a/Tests/OpenGraphCompatibilityTests/Scaffolding.swift +++ b/Tests/OpenGraphCompatibilityTests/Scaffolding.swift @@ -5,8 +5,11 @@ import Testing import XCTest +#if !canImport(Darwin) +// FIXME: Leave Scaffolding since we still use 5.10 toolchain on non-Darwin platform final class AllTests: XCTestCase { func testAll() async { await XCTestScaffold.runAllTests(hostedBy: self) } } +#endif diff --git a/Tests/OpenGraphTempTests/AttributeTestBase.swift b/Tests/OpenGraphTempTests/AttributeTestBase.swift deleted file mode 120000 index a21363c..0000000 --- a/Tests/OpenGraphTempTests/AttributeTestBase.swift +++ /dev/null @@ -1 +0,0 @@ -../OpenGraphCompatibilityTests/Attribute/AttributeTestBase.swift \ No newline at end of file diff --git a/Tests/OpenGraphTempTests/AttributeTestHelper.swift b/Tests/OpenGraphTempTests/AttributeTestHelper.swift deleted file mode 120000 index dd39833..0000000 --- a/Tests/OpenGraphTempTests/AttributeTestHelper.swift +++ /dev/null @@ -1 +0,0 @@ -../OpenGraphCompatibilityTests/Attribute/AttributeTestHelper.swift \ No newline at end of file diff --git a/Tests/OpenGraphTempTests/GraphShims.swift b/Tests/OpenGraphTempTests/GraphShims.swift deleted file mode 120000 index 951448a..0000000 --- a/Tests/OpenGraphTempTests/GraphShims.swift +++ /dev/null @@ -1 +0,0 @@ -../OpenGraphCompatibilityTests/GraphShims.swift \ No newline at end of file diff --git a/Tests/OpenGraphTempTests/README.md b/Tests/OpenGraphTempTests/README.md deleted file mode 100644 index c6837e8..0000000 --- a/Tests/OpenGraphTempTests/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## OpenGraphTempTests - -A temporary test target to iterate new test case. - -Remove this once the IDE support for swift-testing is provided. - -Please do not commit any new files to this folder. diff --git a/Tests/OpenGraphTempTests/Scaffolding.swift b/Tests/OpenGraphTempTests/Scaffolding.swift deleted file mode 100644 index 326d249..0000000 --- a/Tests/OpenGraphTempTests/Scaffolding.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// Scaffolding.swift -// OpenGraphTempTests - - -import Testing -import XCTest - -// See https://github.com/apple/swift-testing/issues/329 -//final class AllTests: XCTestCase { -// func testAll() async { -// await XCTestScaffold.runAllTests(hostedBy: self) -// } -//} diff --git a/Tests/OpenGraphTests/Scaffolding.swift b/Tests/OpenGraphTests/Scaffolding.swift deleted file mode 100644 index eb8a98f..0000000 --- a/Tests/OpenGraphTests/Scaffolding.swift +++ /dev/null @@ -1,13 +0,0 @@ -// -// Scaffolding.swift -// OpenGraphTests - -import Testing -import XCTest - -// See https://github.com/apple/swift-testing/issues/329 -//final class AllTests: XCTestCase { -// func testAll() async { -// await XCTestScaffold.runAllTests(hostedBy: self) -// } -//}