Skip to content

Commit ec8ca11

Browse files
authored
Update Xcode 16 and add Swift 6 toolchain support on macOS (#80)
* Update swift-testing for Xcode 16 * Update CI config * Fix Testing breaking change for Swift 6 release * Fix werror issue * Fix missing simulator issue * Fix @retroactive break older Swift compiler support issue See https://github.com/swiftlang/swift-evolution/blob/main/proposals/0364-retroactive-conformance-warning.md#source-compatibility * Fix iOS and wasm issue * Fix iOS profdata path issue
1 parent 58961e8 commit ec8ca11

File tree

18 files changed

+211
-116
lines changed

18 files changed

+211
-116
lines changed

.github/workflows/compatibility_tests.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ jobs:
1414
matrix:
1515
include:
1616
- os: macos-14
17-
xcode-version: "15.3" # Swift 5.10
17+
xcode-version: "16.0" # Swift 6.0
1818
runs-on: ${{ matrix.os }}
1919
env:
2020
OPENGRAPH_WERROR: 1
21-
OPENGRAPH_SWIFT_TESTING: 1
2221
OPENGRAPH_ATTRIBUTEGRAPH: 1
2322
OPENGRAPH_COMPATIBILITY_TEST: 1
2423
steps:

.github/workflows/ios.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15+
os: [macos-14]
16+
xcode-version: ["16.0"] # Swift 6.0
17+
ios-version: ["18.0"]
1518
include:
16-
- os: macos-14
17-
xcode-version: "15.3" # Swift 5.10
19+
- ios-version: "18.0"
20+
ios-simulator-name: "iPhone 16 Pro"
1821
runs-on: ${{ matrix.os }}
1922
env:
2023
OPENGRAPH_WERROR: 1
21-
OPENGRAPH_SWIFT_TESTING: 1
2224
OPENGRAPH_ATTRIBUTEGRAPH: 0
2325
OPENGRAPH_COMPATIBILITY_TEST: 0
2426
steps:
@@ -34,7 +36,7 @@ jobs:
3436
xcodebuild build \
3537
-scheme OpenGraph-Package \
3638
-configuration Debug \
37-
-destination "platform=iOS" \
39+
-destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \
3840
-derivedDataPath .build-debug \
3941
-skipMacroValidation \
4042
-skipPackagePluginValidation \
@@ -44,16 +46,16 @@ jobs:
4446
xcodebuild test \
4547
-scheme OpenGraph-Package \
4648
-configuration Debug \
47-
-destination "platform=iOS-Simulator" \
49+
-destination "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}" \
4850
-enableCodeCoverage=YES \
4951
-derivedDataPath .build-test-debug \
5052
-skipPackagePluginValidation \
5153
-skipMacroValidation
5254
# OTHER_SWIFT_FLAGS="-warnings-as-errors" Conflicting options '-warnings-as-errors' and '-suppress-warnings'
53-
profdata_file_path=$(find . -path "*.build-test-debug/Build/ProfileData*Coverage.profdata" -type f)
55+
profdata_file_path=$(find . -path "./.build-test-debug/Build/ProfileData/*/Coverage.profdata" -type f)
5456
xcrun llvm-cov show \
5557
-instr-profile=$profdata_file_path \
56-
.build-test-debug/Build/Products/Debug/OpenGraphTests.xctest/Contents/MacOS/OpenGraphTests \
58+
.build-test-debug/Build/Products/Debug-iphonesimulator/OpenGraphTests.xctest/OpenGraphTests \
5759
> coverage.txt
5860
- uses: codecov/codecov-action@v3
5961
with:

.github/workflows/macos.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
include:
16-
- os: macos-14
17-
xcode-version: "15.3" # Swift 5.10
15+
os: [macos-14]
16+
xcode-version: [16.0] # Swift 6.0
1817
runs-on: ${{ matrix.os }}
1918
env:
2019
OPENGRAPH_WERROR: 1
21-
OPENGRAPH_SWIFT_TESTING: 1
2220
OPENGRAPH_ATTRIBUTEGRAPH: 0
2321
OPENGRAPH_COMPATIBILITY_TEST: 0
2422
steps:

Package.resolved

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"originHash" : "08c5b038cf77a79fefbf15fe8ee430265dbe92590190dde25f83708222a7942f",
2+
"originHash" : "498a1f428fea568463979c5b752f310e4e634606592667edadb13772101a8f20",
33
"pins" : [
44
{
55
"identity" : "swift-numerics",
@@ -9,24 +9,6 @@
99
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
1010
"version" : "1.0.2"
1111
}
12-
},
13-
{
14-
"identity" : "swift-syntax",
15-
"kind" : "remoteSourceControl",
16-
"location" : "https://github.com/apple/swift-syntax.git",
17-
"state" : {
18-
"revision" : "fa8f95c2d536d6620cc2f504ebe8a6167c9fc2dd",
19-
"version" : "510.0.1"
20-
}
21-
},
22-
{
23-
"identity" : "swift-testing",
24-
"kind" : "remoteSourceControl",
25-
"location" : "https://github.com/apple/swift-testing",
26-
"state" : {
27-
"revision" : "8097dd8bcf7f2ed85f8aa8883635ce413012f53b",
28-
"version" : "0.6.0"
29-
}
3012
}
3113
],
3214
"version" : 3

Package.swift

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.10
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import Foundation
@@ -20,7 +20,9 @@ func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
2020
let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"
2121
let development = envEnable("OPENGRAPH_DEVELOPMENT", default: false)
2222

23-
var sharedSwiftSettings: [SwiftSetting] = []
23+
var sharedSwiftSettings: [SwiftSetting] = [
24+
.swiftLanguageMode(.v5),
25+
]
2426

2527
let warningsAsErrorsCondition = envEnable("OPENGRAPH_WERROR", default: isXcodeEnv && development)
2628
if warningsAsErrorsCondition {
@@ -51,13 +53,12 @@ let openGraphTestTarget = Target.testTarget(
5153
)
5254
let openGraphCompatibilityTestTarget = Target.testTarget(
5355
name: "OpenGraphCompatibilityTests",
56+
dependencies: [
57+
.product(name: "RealModule", package: "swift-numerics"),
58+
],
5459
exclude: ["README.md"],
5560
swiftSettings: sharedSwiftSettings
5661
)
57-
let openGraphTempTestTarget = Target.testTarget(
58-
name: "OpenGraphTempTests",
59-
exclude: ["README.md"]
60-
)
6162

6263
let swiftBinPath = Context.environment["_"] ?? ""
6364
let swiftBinURL = URL(fileURLWithPath: swiftBinPath)
@@ -78,6 +79,9 @@ let package = Package(
7879
.library(name: "OpenGraphShims", targets: ["OpenGraphShims"]),
7980
.library(name: "OpenGraph", targets: ["OpenGraph"]),
8081
],
82+
dependencies: [
83+
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),
84+
],
8185
targets: [
8286
// FIXME: Merge into one target
8387
// OpenGraph is a C++ & Swift mix target.
@@ -106,6 +110,10 @@ let package = Package(
106110
)
107111
),
108112
openGraphShimsTarget,
113+
114+
openGraphTestTarget,
115+
openGraphShimsTestTarget,
116+
openGraphCompatibilityTestTarget,
109117
],
110118
cxxLanguageStandard: .cxx17
111119
)
@@ -131,45 +139,14 @@ if attributeGraphCondition {
131139
openGraphShimsTarget.dependencies.append("OpenGraph")
132140
}
133141

134-
// Remove this when swift-testing is 1.0.0
135-
let swiftTestingCondition = envEnable("OPENGRAPH_SWIFT_TESTING", default: true)
136-
if swiftTestingCondition {
137-
var dependencies = package.dependencies
138-
dependencies.append(contentsOf: [
139-
.package(url: "https://github.com/apple/swift-testing", exact: "0.6.0"),
140-
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),
141-
])
142-
package.dependencies = dependencies
143-
144-
func addTestDependency(_ target: Target) {
145-
var dependencies = target.dependencies
146-
dependencies.append(contentsOf: [
147-
.product(name: "Testing", package: "swift-testing"),
148-
.product(name: "RealModule", package: "swift-numerics"),
149-
])
150-
target.dependencies = dependencies
151-
}
152-
addTestDependency(openGraphTestTarget)
153-
package.targets.append(openGraphTestTarget)
154-
addTestDependency(openGraphCompatibilityTestTarget)
155-
package.targets.append(openGraphCompatibilityTestTarget)
156-
addTestDependency(openGraphTempTestTarget)
157-
package.targets.append(openGraphTempTestTarget)
158-
addTestDependency(openGraphShimsTestTarget)
159-
package.targets.append(openGraphShimsTestTarget)
160-
}
161-
162142
let compatibilityTestCondition = envEnable("OPENGRAPH_COMPATIBILITY_TEST")
163143
if compatibilityTestCondition && attributeGraphCondition {
164144
openGraphCompatibilityTestTarget.dependencies.append("AttributeGraph")
165-
openGraphTempTestTarget.dependencies.append("AttributeGraph")
166145
var swiftSettings: [SwiftSetting] = (openGraphCompatibilityTestTarget.swiftSettings ?? [])
167146
swiftSettings.append(.define("OPENGRAPH_COMPATIBILITY_TEST"))
168147
openGraphCompatibilityTestTarget.swiftSettings = swiftSettings
169-
openGraphTempTestTarget.swiftSettings = swiftSettings
170148
} else {
171149
openGraphCompatibilityTestTarget.dependencies.append("OpenGraph")
172-
openGraphTempTestTarget.dependencies.append("OpenGraph")
173150
}
174151

175152
extension [Platform] {

[email protected]

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// swift-tools-version: 5.10
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import Foundation
5+
import PackageDescription
6+
7+
func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
8+
guard let value = Context.environment[key] else {
9+
return defaultValue
10+
}
11+
if value == "1" {
12+
return true
13+
} else if value == "0" {
14+
return false
15+
} else {
16+
return defaultValue
17+
}
18+
}
19+
20+
let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"
21+
let development = envEnable("OPENGRAPH_DEVELOPMENT", default: false)
22+
23+
var sharedSwiftSettings: [SwiftSetting] = []
24+
25+
let warningsAsErrorsCondition = envEnable("OPENGRAPH_WERROR", default: isXcodeEnv && development)
26+
if warningsAsErrorsCondition {
27+
sharedSwiftSettings.append(.unsafeFlags(["-warnings-as-errors"]))
28+
}
29+
30+
let openGraphShimsTarget = Target.target(
31+
name: "OpenGraphShims",
32+
swiftSettings: sharedSwiftSettings
33+
)
34+
35+
let openGraphShimsTestTarget = Target.testTarget(
36+
name: "OpenGraphShimsTests",
37+
dependencies: [
38+
"OpenGraphShims",
39+
],
40+
exclude: ["README.md"],
41+
swiftSettings: sharedSwiftSettings
42+
)
43+
44+
let openGraphTestTarget = Target.testTarget(
45+
name: "OpenGraphTests",
46+
dependencies: [
47+
"OpenGraph",
48+
],
49+
exclude: ["README.md"],
50+
swiftSettings: sharedSwiftSettings
51+
)
52+
let openGraphCompatibilityTestTarget = Target.testTarget(
53+
name: "OpenGraphCompatibilityTests",
54+
exclude: ["README.md"],
55+
swiftSettings: sharedSwiftSettings
56+
)
57+
58+
let swiftBinPath = Context.environment["_"] ?? ""
59+
let swiftBinURL = URL(fileURLWithPath: swiftBinPath)
60+
let SDKPath = swiftBinURL.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path
61+
let includePath = SDKPath.appending("/usr/lib/swift_static")
62+
63+
let package = Package(
64+
name: "OpenGraph",
65+
platforms: [
66+
.iOS(.v13),
67+
.macOS(.v10_15),
68+
.macCatalyst(.v13),
69+
.tvOS(.v13),
70+
.watchOS(.v6),
71+
.visionOS(.v1),
72+
],
73+
products: [
74+
.library(name: "OpenGraphShims", targets: ["OpenGraphShims"]),
75+
.library(name: "OpenGraph", targets: ["OpenGraph"]),
76+
],
77+
targets: [
78+
// FIXME: Merge into one target
79+
// OpenGraph is a C++ & Swift mix target.
80+
// The SwiftPM support for such usage is still in progress.
81+
.target(
82+
name: "_OpenGraph",
83+
cSettings: [
84+
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
85+
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
86+
],
87+
cxxSettings: [
88+
.unsafeFlags(["-I", includePath], .when(platforms: .nonDarwinPlatforms)),
89+
.define("__COREFOUNDATION_FORSWIFTFOUNDATIONONLY__", to: "1", .when(platforms: .nonDarwinPlatforms)),
90+
]
91+
),
92+
.target(
93+
name: "OpenGraph",
94+
dependencies: ["_OpenGraph"],
95+
swiftSettings: sharedSwiftSettings
96+
),
97+
.plugin(
98+
name: "UpdateModule",
99+
capability: .command(
100+
intent: .custom(verb: "update-module", description: "Update AG xcframework"),
101+
permissions: [.writeToPackageDirectory(reason: "Update AG xcframework")]
102+
)
103+
),
104+
openGraphShimsTarget,
105+
],
106+
cxxLanguageStandard: .cxx17
107+
)
108+
109+
#if os(macOS)
110+
// FIXME: Enable it by default will cause non-iOS/macOS Apple OS build fail currently.
111+
// Add the corresponding tbd file and framework to fix it.
112+
let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH", default: true)
113+
#else
114+
let attributeGraphCondition = envEnable("OPENGRAPH_ATTRIBUTEGRAPH")
115+
#endif
116+
if attributeGraphCondition {
117+
let attributeGraphProduct = Product.library(name: "AttributeGraph", targets: ["AttributeGraph"])
118+
let attributeGraphTarget = Target.binaryTarget(name: "AttributeGraph", path: "AG/AttributeGraph.xcframework")
119+
package.products.append(attributeGraphProduct)
120+
package.targets.append(attributeGraphTarget)
121+
122+
var swiftSettings: [SwiftSetting] = (openGraphShimsTarget.swiftSettings ?? [])
123+
swiftSettings.append(.define("OPENGRAPH_ATTRIBUTEGRAPH"))
124+
openGraphShimsTarget.swiftSettings = swiftSettings
125+
openGraphShimsTarget.dependencies.append("AttributeGraph")
126+
} else {
127+
openGraphShimsTarget.dependencies.append("OpenGraph")
128+
}
129+
130+
// Remove this when swift-testing is 1.0.0
131+
let swiftTestingCondition = envEnable("OPENGRAPH_SWIFT_TESTING", default: true)
132+
if swiftTestingCondition {
133+
var dependencies = package.dependencies
134+
dependencies.append(contentsOf: [
135+
.package(url: "https://github.com/apple/swift-testing", exact: "0.6.0"),
136+
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),
137+
])
138+
package.dependencies = dependencies
139+
140+
func addTestDependency(_ target: Target) {
141+
var dependencies = target.dependencies
142+
dependencies.append(contentsOf: [
143+
.product(name: "Testing", package: "swift-testing"),
144+
.product(name: "RealModule", package: "swift-numerics"),
145+
])
146+
target.dependencies = dependencies
147+
}
148+
addTestDependency(openGraphTestTarget)
149+
package.targets.append(openGraphTestTarget)
150+
addTestDependency(openGraphCompatibilityTestTarget)
151+
package.targets.append(openGraphCompatibilityTestTarget)
152+
addTestDependency(openGraphShimsTestTarget)
153+
package.targets.append(openGraphShimsTestTarget)
154+
}
155+
156+
let compatibilityTestCondition = envEnable("OPENGRAPH_COMPATIBILITY_TEST")
157+
if compatibilityTestCondition && attributeGraphCondition {
158+
openGraphCompatibilityTestTarget.dependencies.append("AttributeGraph")
159+
var swiftSettings: [SwiftSetting] = (openGraphCompatibilityTestTarget.swiftSettings ?? [])
160+
swiftSettings.append(.define("OPENGRAPH_COMPATIBILITY_TEST"))
161+
openGraphCompatibilityTestTarget.swiftSettings = swiftSettings
162+
} else {
163+
openGraphCompatibilityTestTarget.dependencies.append("OpenGraph")
164+
}
165+
166+
extension [Platform] {
167+
static var nonDarwinPlatforms: [Platform] {
168+
[.linux, .android, .wasi, .openbsd, .windows]
169+
}
170+
}

0 commit comments

Comments
 (0)