Skip to content

Commit b1d230b

Browse files
authored
Swift 6 Fixes (#37)
### Goals ⚽ This PR upgrades dependencies and fixes `Sendable` issues to allow the project to build with the Swift 6 compiler.
1 parent 322d13b commit b1d230b

File tree

13 files changed

+146
-106
lines changed

13 files changed

+146
-106
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
name: macOS
2626
runs-on: firebreak
2727
env:
28-
DEVELOPER_DIR: /Applications/Xcode_15.2.app/Contents/Developer
28+
DEVELOPER_DIR: /Applications/Xcode_16.0.app/Contents/Developer
2929
timeout-minutes: 10
3030
steps:
3131
- uses: actions/checkout@v4
@@ -35,7 +35,7 @@ jobs:
3535
name: Linux
3636
runs-on: ubuntu-latest
3737
container:
38-
image: swift:5.9.0-jammy
38+
image: swift:6.0-jammy
3939
timeout-minutes: 10
4040
steps:
4141
- uses: actions/checkout@v4

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
name: Upload Release Artifact
1010
runs-on: firebreak
1111
env:
12-
DEVELOPER_DIR: /Applications/Xcode_15.2.app/Contents/Developer
12+
DEVELOPER_DIR: /Applications/Xcode_16.0.app/Contents/Developer
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v4

.swiftformat

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
# file options
22

33
--symlinks ignore
4-
--swiftversion 5.9
5-
6-
# rules
7-
--enable isEmpty
8-
--disable andOperator
9-
--disable wrapMultilineStatementBraces
4+
--swiftversion 6
105

116
# format options
127

@@ -22,7 +17,15 @@
2217
--operatorfunc no-space
2318
--nospaceoperators ..<, ...
2419
--selfrequired validate
20+
--someAny false
2521
--stripunusedargs closure-only
2622
--wraparguments preserve
2723
--wrapcollections preserve
2824
--wrapparameters preserve
25+
26+
# rules
27+
28+
--enable isEmpty
29+
--disable andOperator
30+
--disable opaqueGenericParameters
31+
--disable wrapMultilineStatementBraces

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ All notable changes to this project will be documented in this file.
1212

1313
---
1414

15+
## [0.11.0](https://github.com/Alamofire/Firewalk/releases/tag/0.11.0)
16+
17+
Released on 2024-09-28.
18+
19+
#### Updated
20+
21+
- Swift 6 compatibility and dependencies.
22+
- Updated by [Jon Shier](https://github.com/jshier) in PR [#37](https://github.com/Alamofire/Firewalk/pull/37).
23+
24+
---
25+
1526
## [0.10.4](https://github.com/Alamofire/Firewalk/releases/tag/0.10.4)
1627

1728
Released on 2023-01-27.

Package.resolved

Lines changed: 34 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version:6.0
22
//
33
// Package.swift
44
//
5-
// Copyright (c) 2020-2022 Alamofire Software Foundation (http://alamofire.org/)
5+
// Copyright (c) 2020-2024 Alamofire Software Foundation (http://alamofire.org/)
66
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the "Software"), to deal
@@ -35,7 +35,7 @@ swiftSettings = []
3535
let package = Package(name: "Firewalk",
3636
platforms: [.macOS(.v10_15)],
3737
products: [.executable(name: "firewalk", targets: ["firewalk"])],
38-
dependencies: [.package(url: "https://github.com/vapor/vapor.git", from: "4.92.0")],
38+
dependencies: [.package(url: "https://github.com/vapor/vapor.git", from: "4.105.2")],
3939
targets: [.executableTarget(name: "firewalk",
4040
dependencies: [.product(name: "Vapor", package: "vapor")],
4141
path: "Sources",

Sources/Data.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ func createDataRoutes(for app: Application) throws {
8181
}
8282

8383
let response = Response(body: .init(stream: { writer in
84-
var bytesToSend = count
84+
let bytesToSend = Protected(count)
8585
request.eventLoop.scheduleRepeatedTask(initialDelay: .seconds(0), delay: .milliseconds(20)) { task in
86-
guard bytesToSend > 0 else { task.cancel(); _ = writer.write(.end); return }
86+
guard bytesToSend.value > 0 else { task.cancel(); _ = writer.write(.end); return }
8787

88-
_ = writer.write(.buffer(.init(integer: UInt8(bytesToSend))))
89-
bytesToSend -= 1
88+
_ = writer.write(.buffer(.init(integer: UInt8(bytesToSend.value))))
89+
bytesToSend.write { $0 -= 1 }
9090
}
9191
}))
9292

@@ -103,12 +103,12 @@ func createDataRoutes(for app: Application) throws {
103103
let reply = try Reply(to: request)
104104
let encodedReply = try encoder.encodeAsByteBuffer(reply, allocator: app.allocator)
105105
let response = Response(body: .init(stream: { writer in
106-
var payloadsToSend = count
106+
let payloadsToSend = Protected(count)
107107
request.eventLoop.scheduleRepeatedTask(initialDelay: .seconds(0), delay: .milliseconds(20)) { task in
108-
guard payloadsToSend > 0 else { task.cancel(); _ = writer.write(.end); return }
108+
guard payloadsToSend.value > 0 else { task.cancel(); _ = writer.write(.end); return }
109109

110110
_ = writer.write(.buffer(encodedReply))
111-
payloadsToSend -= 1
111+
payloadsToSend.write { $0 -= 1 }
112112
}
113113
}))
114114

@@ -120,6 +120,7 @@ func createDataRoutes(for app: Application) throws {
120120
Response(body: .init(stream: { writer in
121121
let buffer = request.application.allocator.buffer(repeating: 1, count: 100_000_000)
122122

123+
@Sendable
123124
func writeBuffer() {
124125
writer.write(.buffer(buffer)).whenComplete { result in
125126
switch result {

Sources/Download.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,26 @@ func createDownloadRoutes(for app: Application) throws {
5959
response.headers.contentRange = .init(unit: .bytes, range: .within(start: totalCount - byteCount, end: totalCount))
6060
} else {
6161
response = Response(body: .init(stream: { writer in
62-
var buffer = request.application.allocator.buffer(repeating: UInt8.random(), count: totalCount)
63-
var bytesToSend = totalCount
62+
let buffer = Protected(request.application.allocator.buffer(repeating: UInt8.random(), count: totalCount))
63+
let bytesToSend = Protected(totalCount)
6464
let segment = (totalCount / 10)
6565
request.eventLoop.scheduleRepeatedTask(initialDelay: .seconds(0), delay: .milliseconds(1)) { task in
66-
guard bytesToSend > 0 else { task.cancel(); _ = writer.write(.end); return }
66+
guard bytesToSend.value > 0 else { task.cancel(); _ = writer.write(.end); return }
6767

68-
if shouldProduceError, bytesToSend < (totalCount / 2) {
68+
if shouldProduceError, bytesToSend.value < (totalCount / 2) {
6969
task.cancel()
7070
_ = writer.write(.error(URLError(.networkConnectionLost)))
7171
return
7272
}
7373

74-
guard let bytes = buffer.readSlice(length: segment) else {
74+
guard let bytes = buffer.write({ $0.readSlice(length: segment) }) else {
7575
request.logger.info("Failed to read \(segment) bytes from buffer with \(buffer.readableBytes) bytes, ending write.")
7676
task.cancel()
7777
return
7878
}
7979

8080
_ = writer.write(.buffer(bytes))
81-
bytesToSend -= segment
81+
bytesToSend.write { $0 -= segment }
8282
}
8383
}))
8484
response.headers.add(name: .acceptRanges, value: "bytes")

Sources/Extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import Vapor
2626

27-
extension Request: Authenticatable {}
27+
extension Vapor.Request: Vapor.Authenticatable {}
2828

2929
extension Request {
3030
var isAuthenticated: Bool {
@@ -37,14 +37,14 @@ extension Application {
3737
func on(_ methods: [HTTPMethod],
3838
_ path: PathComponent...,
3939
body: HTTPBodyStreamStrategy = .collect,
40-
use closure: @escaping (Request) throws -> some ResponseEncodable) -> [Route] {
40+
use closure: @escaping @Sendable (Request) throws -> some ResponseEncodable) -> [Route] {
4141
methods.map { on($0, path, body: body, use: closure) }
4242
}
4343

4444
@discardableResult
4545
func onMethods(_ methods: [HTTPMethod],
4646
body: HTTPBodyStreamStrategy = .collect,
47-
use closure: @escaping (Request) throws -> some ResponseEncodable) -> [Route] {
47+
use closure: @escaping @Sendable (Request) throws -> some ResponseEncodable) -> [Route] {
4848
methods.map { on($0, .constant($0.rawValue.lowercased()), body: body, use: closure) }
4949
}
5050
}
@@ -54,7 +54,7 @@ extension RoutesBuilder {
5454
func on(_ methods: [HTTPMethod],
5555
_ path: PathComponent...,
5656
body: HTTPBodyStreamStrategy = .collect,
57-
use closure: @escaping (Request) throws -> some ResponseEncodable) -> [Route] {
57+
use closure: @escaping @Sendable (Request) throws -> some ResponseEncodable) -> [Route] {
5858
methods.map { on($0, path, body: body, use: closure) }
5959
}
6060
}

0 commit comments

Comments
 (0)