Skip to content
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

Swift 6 Fixes #37

Merged
merged 2 commits into from
Sep 28, 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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
name: macOS
runs-on: firebreak
env:
DEVELOPER_DIR: /Applications/Xcode_15.2.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_16.0.app/Contents/Developer
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
Expand All @@ -35,7 +35,7 @@ jobs:
name: Linux
runs-on: ubuntu-latest
container:
image: swift:5.9.0-jammy
image: swift:6.0-jammy
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: Upload Release Artifact
runs-on: firebreak
env:
DEVELOPER_DIR: /Applications/Xcode_15.2.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_16.0.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
15 changes: 9 additions & 6 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# file options

--symlinks ignore
--swiftversion 5.9

# rules
--enable isEmpty
--disable andOperator
--disable wrapMultilineStatementBraces
--swiftversion 6

# format options

Expand All @@ -22,7 +17,15 @@
--operatorfunc no-space
--nospaceoperators ..<, ...
--selfrequired validate
--someAny false
--stripunusedargs closure-only
--wraparguments preserve
--wrapcollections preserve
--wrapparameters preserve

# rules

--enable isEmpty
--disable andOperator
--disable opaqueGenericParameters
--disable wrapMultilineStatementBraces
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ All notable changes to this project will be documented in this file.

---

## [0.11.0](https://github.com/Alamofire/Firewalk/releases/tag/0.11.0)

Released on 2024-09-28.

#### Updated

- Swift 6 compatibility and dependencies.
- Updated by [Jon Shier](https://github.com/jshier) in PR [#37](https://github.com/Alamofire/Firewalk/pull/37).

---

## [0.10.4](https://github.com/Alamofire/Firewalk/releases/tag/0.10.4)

Released on 2023-01-27.
Expand Down
67 changes: 34 additions & 33 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"originHash" : "4f523e35011309ed8a0f9c831f0c7fe184d85cfb80844040ec3694705f41d864",
"pins" : [
{
"identity" : "async-http-client",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/async-http-client.git",
"state" : {
"revision" : "291438696abdd48d2a83b52465c176efbd94512b",
"version" : "1.20.1"
"revision" : "0ae99db85b2b9d1e79b362bd31fd1ffe492f7c47",
"version" : "1.21.2"
}
},
{
Expand All @@ -23,26 +24,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/console-kit.git",
"state" : {
"revision" : "a31f44ebfbd15a2cc0fda705279676773ac16355",
"version" : "4.14.1"
"revision" : "9f7932f22ab6f64aafadc14491e694179b7d0f6f",
"version" : "4.14.3"
}
},
{
"identity" : "multipart-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/multipart-kit.git",
"state" : {
"revision" : "12ee56f25bd3fc4c2d09c2aa16e69de61dc786e8",
"version" : "4.6.0"
"revision" : "a31236f24bfd2ea2f520a74575881f6731d7ae68",
"version" : "4.7.0"
}
},
{
"identity" : "routing-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/routing-kit.git",
"state" : {
"revision" : "2a92a7eac411a82fb3a03731be5e76773ebe1b3e",
"version" : "4.9.0"
"revision" : "8c9a227476555c55837e569be71944e02a056b72",
"version" : "4.9.1"
}
},
{
Expand All @@ -68,26 +69,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "d029d9d39c87bed85b1c50adee7c41795261a192",
"version" : "1.0.6"
"revision" : "ee97538f5b81ae89698fd95938896dec5217b148",
"version" : "1.1.1"
}
},
{
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "cc76b894169a3c86b71bac10c78a4db6beb7a9ad",
"version" : "3.2.0"
"revision" : "bc1c29221f6dfeb0ebbfbc98eb95cd3d4967868e",
"version" : "3.4.0"
}
},
{
"identity" : "swift-http-types",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-http-types",
"state" : {
"revision" : "12358d55a3824bd5fed310b999ea8cf83a9a1a65",
"version" : "1.0.3"
"revision" : "1ddbea1ee34354a6a2532c60f98501c35ae8edfa",
"version" : "1.2.0"
}
},
{
Expand All @@ -104,53 +105,53 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-metrics.git",
"state" : {
"revision" : "971ba26378ab69c43737ee7ba967a896cb74c0d1",
"version" : "2.4.1"
"revision" : "e0165b53d49b413dd987526b641e05e246782685",
"version" : "2.5.0"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "635b2589494c97e48c62514bc8b37ced762e0a62",
"version" : "2.63.0"
"revision" : "e5a216ba89deba84356bad9d4c2eab99071c745b",
"version" : "2.67.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "363da63c1966405764f380c627409b2f9d9e710b",
"version" : "1.21.0"
"revision" : "d1ead62745cc3269e482f1c51f27608057174379",
"version" : "1.24.0"
}
},
{
"identity" : "swift-nio-http2",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "0904bf0feb5122b7e5c3f15db7df0eabe623dd87",
"version" : "1.30.0"
"revision" : "8d8eb609929aee75336a0a3d2417280786265868",
"version" : "1.32.0"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5",
"version" : "2.26.0"
"revision" : "2b09805797f21c380f7dc9bedaab3157c5508efb",
"version" : "2.27.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "6cbe0ed2b394f21ab0d46b9f0c50c6be964968ce",
"version" : "1.20.1"
"revision" : "38ac8221dd20674682148d6451367f89c2652980",
"version" : "1.21.0"
}
},
{
Expand All @@ -167,28 +168,28 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496",
"version" : "1.2.1"
"revision" : "f9266c85189c2751589a50ea5aec72799797e471",
"version" : "1.3.0"
}
},
{
"identity" : "vapor",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/vapor.git",
"state" : {
"revision" : "4942d74e8493fc918ed6144c835c8a0e6affd4f4",
"version" : "4.92.1"
"revision" : "a4d7d4d32ef4a21dd10bc6375f4d20da3c5594e4",
"version" : "4.105.2"
}
},
{
"identity" : "websocket-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/websocket-kit.git",
"state" : {
"revision" : "53fe0639a98903858d0196b699720decb42aee7b",
"version" : "2.14.0"
"revision" : "4232d34efa49f633ba61afde365d3896fc7f8740",
"version" : "2.15.0"
}
}
],
"version" : 2
"version" : 3
}
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// swift-tools-version:5.8
// swift-tools-version:6.0
//
// Package.swift
//
// Copyright (c) 2020-2022 Alamofire Software Foundation (http://alamofire.org/)
// Copyright (c) 2020-2024 Alamofire Software Foundation (http://alamofire.org/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -35,7 +35,7 @@ swiftSettings = []
let package = Package(name: "Firewalk",
platforms: [.macOS(.v10_15)],
products: [.executable(name: "firewalk", targets: ["firewalk"])],
dependencies: [.package(url: "https://github.com/vapor/vapor.git", from: "4.92.0")],
dependencies: [.package(url: "https://github.com/vapor/vapor.git", from: "4.105.2")],
targets: [.executableTarget(name: "firewalk",
dependencies: [.product(name: "Vapor", package: "vapor")],
path: "Sources",
Expand Down
15 changes: 8 additions & 7 deletions Sources/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ func createDataRoutes(for app: Application) throws {
}

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

_ = writer.write(.buffer(.init(integer: UInt8(bytesToSend))))
bytesToSend -= 1
_ = writer.write(.buffer(.init(integer: UInt8(bytesToSend.value))))
bytesToSend.write { $0 -= 1 }
}
}))

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

_ = writer.write(.buffer(encodedReply))
payloadsToSend -= 1
payloadsToSend.write { $0 -= 1 }
}
}))

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

@Sendable
func writeBuffer() {
writer.write(.buffer(buffer)).whenComplete { result in
switch result {
Expand Down
12 changes: 6 additions & 6 deletions Sources/Download.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,26 @@ func createDownloadRoutes(for app: Application) throws {
response.headers.contentRange = .init(unit: .bytes, range: .within(start: totalCount - byteCount, end: totalCount))
} else {
response = Response(body: .init(stream: { writer in
var buffer = request.application.allocator.buffer(repeating: UInt8.random(), count: totalCount)
var bytesToSend = totalCount
let buffer = Protected(request.application.allocator.buffer(repeating: UInt8.random(), count: totalCount))
let bytesToSend = Protected(totalCount)
let segment = (totalCount / 10)
request.eventLoop.scheduleRepeatedTask(initialDelay: .seconds(0), delay: .milliseconds(1)) { task in
guard bytesToSend > 0 else { task.cancel(); _ = writer.write(.end); return }
guard bytesToSend.value > 0 else { task.cancel(); _ = writer.write(.end); return }

if shouldProduceError, bytesToSend < (totalCount / 2) {
if shouldProduceError, bytesToSend.value < (totalCount / 2) {
task.cancel()
_ = writer.write(.error(URLError(.networkConnectionLost)))
return
}

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

_ = writer.write(.buffer(bytes))
bytesToSend -= segment
bytesToSend.write { $0 -= segment }
}
}))
response.headers.add(name: .acceptRanges, value: "bytes")
Expand Down
8 changes: 4 additions & 4 deletions Sources/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import Vapor

extension Request: Authenticatable {}
extension Vapor.Request: Vapor.Authenticatable {}

extension Request {
var isAuthenticated: Bool {
Expand All @@ -37,14 +37,14 @@ extension Application {
func on(_ methods: [HTTPMethod],
_ path: PathComponent...,
body: HTTPBodyStreamStrategy = .collect,
use closure: @escaping (Request) throws -> some ResponseEncodable) -> [Route] {
use closure: @escaping @Sendable (Request) throws -> some ResponseEncodable) -> [Route] {
methods.map { on($0, path, body: body, use: closure) }
}

@discardableResult
func onMethods(_ methods: [HTTPMethod],
body: HTTPBodyStreamStrategy = .collect,
use closure: @escaping (Request) throws -> some ResponseEncodable) -> [Route] {
use closure: @escaping @Sendable (Request) throws -> some ResponseEncodable) -> [Route] {
methods.map { on($0, .constant($0.rawValue.lowercased()), body: body, use: closure) }
}
}
Expand All @@ -54,7 +54,7 @@ extension RoutesBuilder {
func on(_ methods: [HTTPMethod],
_ path: PathComponent...,
body: HTTPBodyStreamStrategy = .collect,
use closure: @escaping (Request) throws -> some ResponseEncodable) -> [Route] {
use closure: @escaping @Sendable (Request) throws -> some ResponseEncodable) -> [Route] {
methods.map { on($0, path, body: body, use: closure) }
}
}
Expand Down
Loading