Skip to content

Commit 58453d1

Browse files
adam-fowlerlitongjava
authored andcommitted
Swift 6.1 (TechEmpower#9907)
* Changes for swift 6.1 Also compile fixes for hummingbird2 postgres * Remove vapor-sqiftql changes * Revert postgres, sql-kit and swiftql vapor builds * newline * Remove Vapor changes * Remove more Vapor changes
1 parent 1ba29cb commit 58453d1

File tree

14 files changed

+77
-102
lines changed

14 files changed

+77
-102
lines changed

frameworks/Swift/hummingbird-core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Hummingbird Core is the HTTP server for the Hummingbird framework.
99

1010
## Important Libraries
1111
This version of Hummingbird requires
12-
* [Swift 5.7](https://swift.org)
12+
* [Swift 5.10](https://swift.org)
1313
* [SwiftNIO 2.x](https://github.com/apple/swift-nio/)
1414

1515
## Test URLs

frameworks/Swift/hummingbird-core/hummingbird-core.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ================================
22
# Build image
33
# ================================
4-
FROM swift:5.10 as build
4+
FROM swift:6.1 AS build
55
WORKDIR /build
66

77
# Copy entire repo into container
@@ -15,7 +15,7 @@ RUN swift build \
1515
# ================================
1616
# Run image
1717
# ================================
18-
FROM swift:5.10-slim
18+
FROM swift:6.1-slim
1919
WORKDIR /run
2020

2121
# Copy build artifacts

frameworks/Swift/hummingbird/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Hummingbird is a lightweight, flexible HTTP server framework written in Swift.
1313

1414
## Important Libraries
1515
This version of Hummingbird requires
16-
* [Swift 5.7](https://swift.org)
16+
* [Swift 5.10](https://swift.org)
1717
* [SwiftNIO 2.x](https://github.com/apple/swift-nio/)
1818
In these tests for database access it uses
1919
* [PostgresKit 2.0](https://github.com/vapor/postgres-kit/)

frameworks/Swift/hummingbird/hummingbird-postgres.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ================================
22
# Build image
33
# ================================
4-
FROM swift:5.10 as build
4+
FROM swift:6.1 AS build
55
WORKDIR /build
66

77
# Copy entire repo into container
@@ -15,7 +15,7 @@ RUN swift build \
1515
# ================================
1616
# Run image
1717
# ================================
18-
FROM swift:5.10-slim
18+
FROM swift:6.1-slim
1919
WORKDIR /run
2020

2121
# Copy build artifacts

frameworks/Swift/hummingbird/hummingbird.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ================================
22
# Build image
33
# ================================
4-
FROM swift:5.10 as build
4+
FROM swift:6.1 AS build
55
WORKDIR /build
66

77
# Copy entire repo into container
@@ -15,7 +15,7 @@ RUN swift build \
1515
# ================================
1616
# Run image
1717
# ================================
18-
FROM swift:5.10-slim
18+
FROM swift:6.1-slim
1919
WORKDIR /run
2020

2121
# Copy build artifacts

frameworks/Swift/hummingbird2/hummingbird2-postgres.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ================================
22
# Build image
33
# ================================
4-
FROM swift:5.10 as build
4+
FROM swift:6.1 AS build
55
WORKDIR /build
66

77
# Copy entire repo into container
@@ -15,7 +15,7 @@ RUN swift build \
1515
# ================================
1616
# Run image
1717
# ================================
18-
FROM swift:5.10-slim
18+
FROM swift:6.1-slim
1919
WORKDIR /run
2020

2121
# Copy build artifacts

frameworks/Swift/hummingbird2/hummingbird2.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ================================
22
# Build image
33
# ================================
4-
FROM swift:5.10 as build
4+
FROM swift:6.1 AS build
55
WORKDIR /build
66

77
# Copy entire repo into container
@@ -15,7 +15,7 @@ RUN swift build \
1515
# ================================
1616
# Run image
1717
# ================================
18-
FROM swift:5.10-slim
18+
FROM swift:6.1-slim
1919
WORKDIR /run
2020

2121
# Copy build artifacts
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
// swift-tools-version:5.10
1+
// swift-tools-version:6.1
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "server",
88
platforms: [.macOS(.v14)],
9-
products: [
10-
.executable(name: "server", targets: ["server"])
11-
],
129
dependencies: [
13-
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-beta.4"),
14-
.package(url: "https://github.com/hummingbird-project/swift-mustache.git", from: "2.0.0-beta"),
10+
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
11+
.package(url: "https://github.com/hummingbird-project/swift-mustache.git", from: "2.0.0"),
1512
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.21.0"),
1613
],
1714
targets: [
18-
.executableTarget(name: "server",
15+
.executableTarget(
16+
name: "server",
1917
dependencies: [
2018
.product(name: "Hummingbird", package: "hummingbird"),
2119
.product(name: "Mustache", package: "swift-mustache"),
@@ -27,6 +25,6 @@ let package = Package(
2725
// builds. See <https://github.com/swift-server/guides#building-for-production> for details.
2826
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
2927
]
30-
),
28+
)
3129
]
3230
)

frameworks/Swift/hummingbird2/src-postgres/Sources/server/Controllers/FortunesController.swift

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import PostgresNIO
55
struct HTML: ResponseGenerator, Sendable {
66
let html: String
77
public func response(from request: Request, context: some RequestContext) -> Response {
8-
let buffer = context.allocator.buffer(string: html)
9-
return Response(status: .ok, headers: [.contentType: "text/html; charset=utf-8"], body: .init(byteBuffer: buffer))
8+
return Response(
9+
status: .ok, headers: [.contentType: "text/html; charset=utf-8"],
10+
body: .init(byteBuffer: .init(string: html)))
1011
}
1112
}
1213

@@ -17,9 +18,10 @@ final class FortunesController: Sendable {
1718

1819
init(postgresClient: PostgresClient) {
1920
self.postgresClient = postgresClient
20-
self.template = try! MustacheTemplate(string: """
21-
<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>{{#.}}<tr><td>{{id}}</td><td>{{message}}</td></tr>{{/.}}</table></body></html>
22-
""")
21+
self.template = try! MustacheTemplate(
22+
string: """
23+
<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>{{#.}}<tr><td>{{id}}</td><td>{{message}}</td></tr>{{/.}}</table></body></html>
24+
""")
2325
}
2426

2527
var routes: RouteCollection<Context> {
@@ -28,11 +30,11 @@ final class FortunesController: Sendable {
2830
}
2931

3032
/// In this test, the framework's ORM is used to fetch all rows from a database
31-
/// table containing an unknown number of Unix fortune cookie messages (the
32-
/// table has 12 rows, but the code cannot have foreknowledge of the table's
33-
/// size). An additional fortune cookie message is inserted into the list at
34-
/// runtime and then the list is sorted by the message text. Finally, the list
35-
/// is delivered to the client using a server-side HTML template. The message
33+
/// table containing an unknown number of Unix fortune cookie messages (the
34+
/// table has 12 rows, but the code cannot have foreknowledge of the table's
35+
/// size). An additional fortune cookie message is inserted into the list at
36+
/// runtime and then the list is sorted by the message text. Finally, the list
37+
/// is delivered to the client using a server-side HTML template. The message
3638
/// text must be considered untrusted and properly escaped and the UTF-8 fortune messages must be rendered properly.
3739
@Sendable func fortunes(request: Request, context: Context) async throws -> HTML {
3840
let rows = try await self.postgresClient.execute(SelectFortuneStatement())
@@ -43,14 +45,14 @@ final class FortunesController: Sendable {
4345

4446
fortunes.append(.init(id: 0, message: "Additional fortune added at request time."))
4547
let sortedFortunes = fortunes.sorted { $0.message < $1.message }
46-
return HTML(html: self.template.render(sortedFortunes) )
47-
48+
return HTML(html: self.template.render(sortedFortunes))
49+
4850
}
4951

5052
struct SelectFortuneStatement: PostgresPreparedStatement {
5153
typealias Row = (Int32, String)
5254

53-
static var sql = "SELECT id, message FROM Fortune"
55+
static let sql = "SELECT id, message FROM Fortune"
5456

5557
func makeBindings() throws -> PostgresNIO.PostgresBindings {
5658
return .init()

frameworks/Swift/hummingbird2/src-postgres/Sources/server/Controllers/WorldController.swift

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ struct WorldController {
1212
.get("updates", use: updates)
1313
}
1414

15-
/// In this test, each request is processed by fetching a single row from a
15+
/// In this test, each request is processed by fetching a single row from a
1616
/// simple database table. That row is then serialized as a JSON response.
1717
@Sendable func single(request: Request, context: Context) async throws -> World {
1818
let id = Int32.random(in: 1...10_000)
1919
let rows = try await self.postgresClient.execute(SelectWorldStatement(id: id))
20-
guard let row = try await rows.first(where: {_ in true }) else {
20+
guard let row = try await rows.first(where: { _ in true }) else {
2121
throw HTTPError(.notFound)
2222
}
2323
return World(id: row.0, randomNumber: row.1)
2424
}
2525

26-
/// In this test, each request is processed by fetching multiple rows from a
27-
/// simple database table and serializing these rows as a JSON response. The
28-
/// test is run multiple times: testing 1, 5, 10, 15, and 20 queries per request.
26+
/// In this test, each request is processed by fetching multiple rows from a
27+
/// simple database table and serializing these rows as a JSON response. The
28+
/// test is run multiple times: testing 1, 5, 10, 15, and 20 queries per request.
2929
/// All tests are run at 512 concurrency.
3030
@Sendable func multiple(request: Request, context: Context) async throws -> [World] {
3131
let queries = (request.uri.queryParameters.get("queries", as: Int.self) ?? 1).bound(1, 500)
@@ -34,23 +34,24 @@ struct WorldController {
3434
result.reserveCapacity(queries)
3535
for _ in 0..<queries {
3636
let id = Int32.random(in: 1...10_000)
37-
let rows = try await conn.execute(SelectWorldStatement(id: id), logger: context.logger)
38-
guard let row = try await rows.first(where: {_ in true }) else {
37+
let rows = try await conn.execute(
38+
SelectWorldStatement(id: id), logger: context.logger)
39+
guard let row = try await rows.first(where: { _ in true }) else {
3940
throw HTTPError(.notFound)
4041
}
41-
result.append( World(id: row.0, randomNumber: row.1))
42+
result.append(World(id: row.0, randomNumber: row.1))
4243
}
4344
return result
4445
}
4546
}
4647

47-
/// This test exercises database writes. Each request is processed by fetching
48-
/// multiple rows from a simple database table, converting the rows to in-memory
49-
/// objects, modifying one attribute of each object in memory, updating each
50-
/// associated row in the database individually, and then serializing the list
51-
/// of objects as a JSON response. The test is run multiple times: testing 1, 5,
52-
/// 10, 15, and 20 updates per request. Note that the number of statements per
53-
/// request is twice the number of updates since each update is paired with one
48+
/// This test exercises database writes. Each request is processed by fetching
49+
/// multiple rows from a simple database table, converting the rows to in-memory
50+
/// objects, modifying one attribute of each object in memory, updating each
51+
/// associated row in the database individually, and then serializing the list
52+
/// of objects as a JSON response. The test is run multiple times: testing 1, 5,
53+
/// 10, 15, and 20 updates per request. Note that the number of statements per
54+
/// request is twice the number of updates since each update is paired with one
5455
/// query to fetch the object. All tests are run at 512 concurrency.
5556
@Sendable func updates(request: Request, context: Context) async throws -> [World] {
5657
let queries = (request.uri.queryParameters.get("queries", as: Int.self) ?? 1).bound(1, 500)
@@ -59,12 +60,15 @@ struct WorldController {
5960
result.reserveCapacity(queries)
6061
for _ in 0..<queries {
6162
let id = Int32.random(in: 1...10_000)
62-
let rows = try await conn.execute(SelectWorldStatement(id: id), logger: context.logger)
63-
guard let row = try await rows.first(where: {_ in true }) else {
63+
let rows = try await conn.execute(
64+
SelectWorldStatement(id: id), logger: context.logger)
65+
guard let row = try await rows.first(where: { _ in true }) else {
6466
throw HTTPError(.notFound)
6567
}
6668
let randomNumber = Int32.random(in: 1...10_000)
67-
_ = try await conn.execute(UpdateWorldStatement(id: id, randomNumber: randomNumber), logger: context.logger)
69+
_ = try await conn.execute(
70+
UpdateWorldStatement(id: id, randomNumber: randomNumber), logger: context.logger
71+
)
6872
result.append(World(id: row.0, randomNumber: randomNumber))
6973
}
7074
return result
@@ -76,7 +80,7 @@ struct WorldController {
7680

7781
let id: Int32
7882

79-
static var sql = "SELECT id, randomnumber FROM World WHERE id = $1"
83+
static let sql = "SELECT id, randomnumber FROM World WHERE id = $1"
8084

8185
func makeBindings() throws -> PostgresNIO.PostgresBindings {
8286
var bindings = PostgresNIO.PostgresBindings(capacity: 1)
@@ -93,7 +97,7 @@ struct WorldController {
9397
let id: Int32
9498
let randomNumber: Int32
9599

96-
static var sql = "UPDATE World SET randomnumber = $2 WHERE id = $1"
100+
static let sql = "UPDATE World SET randomnumber = $2 WHERE id = $1"
97101

98102
func makeBindings() throws -> PostgresNIO.PostgresBindings {
99103
var bindings = PostgresNIO.PostgresBindings(capacity: 2)

0 commit comments

Comments
 (0)