Skip to content

Commit

Permalink
Swift Language Support: Drop <5.9, Add 6.0 (#84)
Browse files Browse the repository at this point in the history
* Swift 6 Language Mode

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip
  • Loading branch information
stephencelis authored Jun 18, 2024
1 parent 698be41 commit 07d5617
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 70 deletions.
50 changes: 20 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,31 @@ concurrency:

jobs:
build:
name: MacOS
runs-on: macOS-latest
name: macOS
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_15.4.app
- name: Run tests
run: make test

ubuntu:
name: Ubuntu
linux:
strategy:
matrix:
swift:
- '5.10'
name: Ubuntu (Swift ${{ matrix.swift }})
runs-on: ubuntu-latest
container: swift:${{ matrix.swift }}
steps:
- uses: actions/checkout@v4
- name: Run tests
run: make test-linux
- uses: actions/checkout@v4
- name: Install dependencies
run: apt-get update && apt-get install -y build-essential libcurl4-openssl-dev
- name: Run tests
run: make test
- name: Build for static-stdlib
run: make build-for-static-stdlib

wasm:
name: Wasm
Expand All @@ -54,31 +65,10 @@ jobs:
steps:
- uses: compnerd/gha-setup-swift@main
with:
branch: swift-5.8.1-release
tag: 5.8.1-RELEASE
branch: swift-5.10-release
tag: 5.10-RELEASE
- uses: actions/checkout@v4
- name: Build
run: swift build -c ${{ matrix.config }}
- name: Run tests (debug only)
# There is an issue that exists in the 5.8.1 toolchain
# which fails on release configuration testing, but
# this issue is fixed 5.9 so we can remove the if once
# that is generally available.
if: ${{ matrix.config == 'debug' }}
run: swift test

static-stdlib:
name: Static standard library
strategy:
matrix:
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- uses: swift-actions/setup-swift@v1
with:
swift-version: '5.8.0'
- name: Install dependencies
run: sudo apt-get install -y libcurl4-openssl-dev
- uses: actions/checkout@v4
- name: Build for static-stdlib
run: make build-for-static-stdlib
24 changes: 0 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,6 @@ test-debug:
test: test-debug
@swift test -c release

test-linux: test-debug

test-linux: test

test-linux-docker:
@docker run \
--rm \
-v "$(PWD):$(PWD)" \
-w "$(PWD)" \
swift:5.6.2-focal \
bash -c "apt-get update && apt-get install make && make test"

test-linux-static-stdlib:
@docker run \
-v "$(PWD):$(PWD)" \
-w "$(PWD)" \
swift:5.6.2-focal \
bash -c "swift build -c debug -Xswiftc -static-stdlib"
@docker run \
-v "$(PWD):$(PWD)" \
-w "$(PWD)" \
swift:5.6.2-focal \
bash -c "swift build -c release -Xswiftc -static-stdlib"

build-for-static-stdlib:
@swift build -c debug --static-swift-stdlib
@swift build -c release --static-swift-stdlib
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version: 5.9

import PackageDescription

Expand Down
31 changes: 31 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// swift-tools-version: 6.0

import PackageDescription

let package = Package(
name: "xctest-dynamic-overlay",
platforms: [
.iOS(.v13),
.macOS(.v10_15),
.tvOS(.v13),
.watchOS(.v6),
],
products: [
.library(name: "XCTestDynamicOverlay", targets: ["XCTestDynamicOverlay"])
],
targets: [
.target(name: "XCTestDynamicOverlay"),
.testTarget(
name: "XCTestDynamicOverlayTests",
dependencies: ["XCTestDynamicOverlay"]
),
],
swiftLanguageVersions: [.v6]
)

#if !os(Windows)
// Add the documentation compiler plugin if possible
package.dependencies.append(
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")
)
#endif
15 changes: 12 additions & 3 deletions Sources/XCTestDynamicOverlay/Internal/RuntimeWarnings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func runtimeWarn(
#if DEBUG && canImport(os)
os_log(
.fault,
dso: dso,
dso: dso.wrappedValue,
log: OSLog(subsystem: "com.apple.runtime-issues", category: "XCTestDynamicOverlay"),
"%@",
message()
Expand All @@ -29,7 +29,7 @@ func runtimeWarn(
//
// Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
@usableFromInline
let dso = { () -> UnsafeMutableRawPointer in
let dso = UncheckedSendable({ () -> UnsafeMutableRawPointer in
let count = _dyld_image_count()
for i in 0..<count {
if let name = _dyld_get_image_name(i) {
Expand All @@ -42,5 +42,14 @@ func runtimeWarn(
}
}
return UnsafeMutableRawPointer(mutating: #dsohandle)
}()
}())

@usableFromInline
struct UncheckedSendable<Value>: @unchecked Sendable {
@usableFromInline
var wrappedValue: Value
init(_ value: Value) {
self.wrappedValue = value
}
}
#endif
2 changes: 1 addition & 1 deletion Sources/XCTestDynamicOverlay/Unimplemented.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ func _fail(_ description: String, _ parameters: Any?, fileID: StaticString, line
Defined at:
\(fileID):\(line)
"""
if let parameters = parameters {
if let parameters {
var parametersDescription = ""
debugPrint(parameters, terminator: "", to: &parametersDescription)
debugDescription.append(
Expand Down
4 changes: 2 additions & 2 deletions Sources/XCTestDynamicOverlay/XCTExpectFailure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Foundation
return try failingBlock()
}

if let issueMatcher = issueMatcher {
if let issueMatcher {
let issueMatcher: @convention(block) (AnyObject) -> Bool = { issue in
issueMatcher(_XCTIssue(issue))
}
Expand Down Expand Up @@ -96,7 +96,7 @@ import Foundation
return
}

if let issueMatcher = issueMatcher {
if let issueMatcher {
let issueMatcher: @convention(block) (AnyObject) -> Bool = { issue in
issueMatcher(_XCTIssue(issue))
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/XCTestDynamicOverlayTests/CurrentTestCaseTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@_spi(CurrentTestCase) import XCTestDynamicOverlay

// Make sure XCTCurrentTestCase is visible to SPI.
private let currentTestCase = XCTCurrentTestCase
@MainActor private let currentTestCase = XCTCurrentTestCase
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
XCTFail("Stream should be finished")
}

let throwingStream: () -> AsyncThrowingStream<Int, Error> = unimplemented("throwingStream")
let throwingStream: @Sendable () -> AsyncThrowingStream<Int, Error> = unimplemented(
"throwingStream"
)
let result = await Task {
try await XCTExpectFailure(failingBlock: throwingStream).first(where: { _ in true })
try await XCTExpectFailure { throwingStream() }.first(where: { _ in true })
}.result
XCTAssertThrowsError(try result.get()) { XCTAssertTrue($0 is CancellationError) }

Expand Down
12 changes: 6 additions & 6 deletions Tests/XCTestDynamicOverlayTests/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ struct Client {

struct User { let id: UUID }

let f00: () -> Int = unimplemented("f00", placeholder: 42)
let f01: (String) -> Int = unimplemented("f01", placeholder: 42)
let f02: (String, Int) -> Int = unimplemented("f02", placeholder: 42)
let f03: (String, Int, Double) -> Int = unimplemented("f03", placeholder: 42)
let f04: (String, Int, Double, [Int]) -> Int = unimplemented("f04", placeholder: 42)
let f05: (String, Int, Double, [Int], User) -> Int = unimplemented("f05", placeholder: 42)
@MainActor let f00: () -> Int = unimplemented("f00", placeholder: 42)
@MainActor let f01: (String) -> Int = unimplemented("f01", placeholder: 42)
@MainActor let f02: (String, Int) -> Int = unimplemented("f02", placeholder: 42)
@MainActor let f03: (String, Int, Double) -> Int = unimplemented("f03", placeholder: 42)
@MainActor let f04: (String, Int, Double, [Int]) -> Int = unimplemented("f04", placeholder: 42)
@MainActor let f05: (String, Int, Double, [Int], User) -> Int = unimplemented("f05", placeholder: 42)

private struct Autoclosing {
init(
Expand Down

0 comments on commit 07d5617

Please sign in to comment.