Skip to content

Commit 48a952a

Browse files
committed
Setting Swift minimum version to 5.7
Updates copyright from 2023 to 2024 & formats code - updates formatting rules Updates CI to run with swift 5.7 Adds wasmer & updates command to run carton as a swift plugin Update bazelci to also accept swift 5.7
1 parent 67eb95d commit 48a952a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+89
-194
lines changed

.bazelci/presubmit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ platforms:
55
ubuntu1804:
66
environment:
77
CC: clang
8-
SWIFT_VERSION: "5.5.3"
8+
SWIFT_VERSION: "5.7"
99
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
1010
PATH: "$PATH:$SWIFT_HOME/usr/bin"
1111
shell_commands:
@@ -19,7 +19,7 @@ platforms:
1919
ubuntu2004:
2020
environment:
2121
CC: clang
22-
SWIFT_VERSION: "5.5.3"
22+
SWIFT_VERSION: "5.7"
2323
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
2424
PATH: "$PATH:$SWIFT_HOME/usr/bin"
2525
shell_commands:

.github/workflows/build.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,17 @@ jobs:
478478
479479
build-swift:
480480
name: Build Swift
481+
strategy:
482+
matrix:
483+
swift: ["5.7", "5.8", "5.9"]
481484
runs-on: ubuntu-22.04-64core
482485
steps:
483486
- uses: actions/checkout@v3
487+
- uses: swift-actions/setup-swift@v1
488+
with:
489+
swift-version: ${{ matrix.swift }}
490+
- name: Get swift version
491+
run: swift --version
484492
- name: test
485493
working-directory: tests/swift/tests
486494
run: |
@@ -490,15 +498,16 @@ jobs:
490498
build-swift-wasm:
491499
name: Build Swift Wasm
492500
runs-on: ubuntu-22.04-64core
493-
container:
494-
image: ghcr.io/swiftwasm/carton:0.15.3
495501
steps:
496502
- uses: actions/checkout@v3
497503
- name: Setup Wasmer
498504
uses: wasmerio/setup-wasmer@v2
505+
- uses: swiftwasm/setup-swiftwasm@v1
506+
with:
507+
swift-version: "wasm-5.9.2-RELEASE"
499508
- name: Test
500509
working-directory: tests/swift/Wasm.tests
501-
run: carton test
510+
run: swift run carton test
502511

503512
build-ts:
504513
name: Build TS

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.6
1+
// swift-tools-version:5.7
22
/*
33
* Copyright 2020 Google Inc. All rights reserved.
44
*

[email protected]

Lines changed: 0 additions & 37 deletions
This file was deleted.

benchmarks/swift/Benchmarks/FlatbuffersBenchmarks/FlatbuffersBenchmarks.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 Google Inc. All rights reserved.
2+
* Copyright 2024 Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

grpc/examples/swift/Greeter/Sources/client/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 Google Inc. All rights reserved.
2+
* Copyright 2024 Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

grpc/examples/swift/Greeter/Sources/server/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 Google Inc. All rights reserved.
2+
* Copyright 2024 Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

samples/sample_binary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 Google Inc. All rights reserved.
2+
* Copyright 2024 Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

swift.swiftformat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# options
88
--self remove # redundantSelf
9-
--importgrouping testable-bottom # sortedImports
9+
--importgrouping testable-bottom # sortImports
1010
--trimwhitespace always
1111
--indentcase false
1212
--ifdef no-indent #indent
@@ -17,7 +17,7 @@
1717
--typeattributes prev-line # wrapAttributes
1818

1919
# rules
20-
--rules wrap,todos,anyObjectProtocol,redundantParens,redundantReturn,redundantSelf,sortedImports,strongifiedSelf,trailingCommas,trailingSpace,wrapArguments,wrapMultilineStatementBraces,indent,wrapAttributes,void,fileHeader
20+
--rules wrap,todos,anyObjectProtocol,redundantParens,redundantReturn,redundantSelf,sortImports,strongifiedSelf,trailingCommas,trailingSpace,wrapArguments,wrapMultilineStatementBraces,indent,wrapAttributes,void,fileHeader
2121
--disable trailingclosures
2222

2323
--exclude **/*_generated.swift

swift/Sources/FlatBuffers/ByteBuffer.swift

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 Google Inc. All rights reserved.
2+
* Copyright 2024 Google Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,11 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#if !os(WASI)
1817
import Foundation
19-
#else
20-
import SwiftOverlayShims
21-
#endif
2218

2319
/// `ByteBuffer` is the interface that stores the data for a `Flatbuffers` object
2420
/// it allows users to write and read data directly from memory thus the use of its
@@ -121,37 +117,37 @@ public struct ByteBuffer {
121117
public let allowReadingUnalignedBuffers: Bool
122118

123119
/// Constructor that creates a Flatbuffer object from a UInt8
124-
/// - Parameter
120+
/// - Parameter
125121
/// - bytes: Array of UInt8
126122
/// - allowReadingUnalignedBuffers: allow reading from unaligned buffer
127123
public init(
128-
bytes: [UInt8],
124+
bytes: [UInt8],
129125
allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false)
130126
{
131127
var b = bytes
132128
_storage = Storage(count: bytes.count, alignment: alignment)
133129
_writerSize = _storage.capacity
134130
allowReadingUnalignedBuffers = allowUnalignedBuffers
135131
b.withUnsafeMutableBytes { bufferPointer in
136-
self._storage.copy(from: bufferPointer.baseAddress!, count: bytes.count)
132+
_storage.copy(from: bufferPointer.baseAddress!, count: bytes.count)
137133
}
138134
}
139135

140136
#if !os(WASI)
141137
/// Constructor that creates a Flatbuffer from the Swift Data type object
142-
/// - Parameter
138+
/// - Parameter
143139
/// - data: Swift data Object
144140
/// - allowReadingUnalignedBuffers: allow reading from unaligned buffer
145141
public init(
146-
data: Data,
142+
data: Data,
147143
allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false)
148144
{
149145
var b = data
150146
_storage = Storage(count: data.count, alignment: alignment)
151147
_writerSize = _storage.capacity
152148
allowReadingUnalignedBuffers = allowUnalignedBuffers
153149
b.withUnsafeMutableBytes { bufferPointer in
154-
self._storage.copy(from: bufferPointer.baseAddress!, count: data.count)
150+
_storage.copy(from: bufferPointer.baseAddress!, count: data.count)
155151
}
156152
}
157153
#endif
@@ -175,7 +171,7 @@ public struct ByteBuffer {
175171
/// - allowReadingUnalignedBuffers: allow reading from unaligned buffer
176172
public init<Bytes: ContiguousBytes>(
177173
contiguousBytes: Bytes,
178-
count: Int,
174+
count: Int,
179175
allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false)
180176
{
181177
_storage = Storage(count: count, alignment: alignment)
@@ -208,7 +204,7 @@ public struct ByteBuffer {
208204
/// - count: count of bytes
209205
/// - allowReadingUnalignedBuffers: allow reading from unaligned buffer
210206
init(
211-
memory: UnsafeMutableRawPointer,
207+
memory: UnsafeMutableRawPointer,
212208
count: Int,
213209
allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false)
214210
{
@@ -228,7 +224,7 @@ public struct ByteBuffer {
228224
memory: UnsafeMutableRawPointer,
229225
count: Int,
230226
removing removeBytes: Int,
231-
allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false)
227+
allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false)
232228
{
233229
_storage = Storage(count: count, alignment: alignment)
234230
_storage.copy(from: memory, count: count)
@@ -257,7 +253,7 @@ public struct ByteBuffer {
257253
_storage.memory.advanced(by: writerIndex &- ptr.count),
258254
UnsafeRawPointer(ptr.baseAddress!),
259255
ptr.count)
260-
self._writerSize = self._writerSize &+ ptr.count
256+
_writerSize = _writerSize &+ ptr.count
261257
}
262258
}
263259

@@ -271,7 +267,7 @@ public struct ByteBuffer {
271267
_storage.memory
272268
.advanced(by: writerIndex &- ptr.count)
273269
.copyMemory(from: ptr.baseAddress!, byteCount: ptr.count)
274-
self._writerSize = self._writerSize &+ ptr.count
270+
_writerSize = _writerSize &+ ptr.count
275271
}
276272
}
277273

@@ -287,7 +283,7 @@ public struct ByteBuffer {
287283
_storage.memory.advanced(by: writerIndex &- ptr.count),
288284
UnsafeRawPointer(ptr.baseAddress!),
289285
ptr.count)
290-
self._writerSize = self._writerSize &+ ptr.count
286+
_writerSize = _writerSize &+ ptr.count
291287
}
292288
}
293289
#endif
@@ -306,7 +302,7 @@ public struct ByteBuffer {
306302
_storage.memory.advanced(by: writerIndex &- size),
307303
$0.baseAddress!,
308304
size)
309-
self._writerSize = self._writerSize &+ size
305+
_writerSize = _writerSize &+ size
310306
}
311307
}
312308

@@ -324,7 +320,7 @@ public struct ByteBuffer {
324320
_storage.memory.advanced(by: writerIndex &- len),
325321
$0.baseAddress!,
326322
len)
327-
self._writerSize = self._writerSize &+ len
323+
_writerSize = _writerSize &+ len
328324
}
329325
}
330326

@@ -429,11 +425,9 @@ public struct ByteBuffer {
429425
/// - position: the index of the object in the buffer
430426
@inline(__always)
431427
public func read<T>(def: T.Type, position: Int) -> T {
432-
#if swift(>=5.7)
433428
if allowReadingUnalignedBuffers {
434429
return _storage.memory.advanced(by: position).loadUnaligned(as: T.self)
435430
}
436-
#endif
437431
return _storage.memory.advanced(by: position).load(as: T.self)
438432
}
439433

@@ -538,7 +532,8 @@ extension ByteBuffer: CustomDebugStringConvertible {
538532
public var debugDescription: String {
539533
"""
540534
buffer located at: \(_storage.memory), with capacity of \(_storage.capacity)
541-
{ writerSize: \(_writerSize), readerSize: \(reader), writerIndex: \(writerIndex) }
535+
{ writerSize: \(_writerSize), readerSize: \(reader), writerIndex: \(
536+
writerIndex) }
542537
"""
543538
}
544539
}

0 commit comments

Comments
 (0)