Skip to content

Update Xcode 16 and add Swift 6 toolchain support on macOS #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/compatibility_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 \
Expand All @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 1 addition & 19 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 14 additions & 37 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -106,6 +110,10 @@ let package = Package(
)
),
openGraphShimsTarget,

openGraphTestTarget,
openGraphShimsTestTarget,
openGraphCompatibilityTestTarget,
],
cxxLanguageStandard: .cxx17
)
Expand All @@ -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] {
Expand Down
170 changes: 170 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -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]
}
}
Loading
Loading