From 75f05d6389b88e53a1bee80b23a0d99ec196a417 Mon Sep 17 00:00:00 2001 From: mustiikhalil <26250654+mustiikhalil@users.noreply.github.com> Date: Wed, 29 May 2024 22:07:54 +0200 Subject: [PATCH] Sets Swift minimum version to 5.8 (#8228) Updates copyright from 2023 to 2024 & formats code - updates formatting rules Updates CI to run with swift 5.8 Adds wasmer & updates command to run carton as a swift plugin Update bazelci to also accept swift 5.8 Adds swift 5.10 to the test matrix --- .bazelci/presubmit.yml | 4 +- .github/workflows/build.yml | 13 ++++++- Package.swift | 2 +- Package@swift-5.5.swift | 37 ------------------ .../FlatbuffersBenchmarks.swift | 2 +- .../swift/Greeter/Sources/client/main.swift | 2 +- .../swift/Greeter/Sources/server/main.swift | 2 +- samples/sample_binary.swift | 2 +- swift.swiftformat | 4 +- swift/Sources/FlatBuffers/ByteBuffer.swift | 39 ++++++++----------- swift/Sources/FlatBuffers/Constants.swift | 10 +---- swift/Sources/FlatBuffers/Enum.swift | 6 +-- .../FlatBuffers/FlatBufferBuilder.swift | 9 ++--- .../FlatBuffers/FlatBufferObject.swift | 6 +-- .../FlatBuffers/FlatBuffersUtils.swift | 6 +-- .../FlatBuffers/FlatbuffersErrors.swift | 6 +-- swift/Sources/FlatBuffers/Int+extension.swift | 6 +-- swift/Sources/FlatBuffers/Message.swift | 6 +-- swift/Sources/FlatBuffers/Mutable.swift | 8 +--- swift/Sources/FlatBuffers/NativeObject.swift | 6 +-- swift/Sources/FlatBuffers/Offset.swift | 6 +-- swift/Sources/FlatBuffers/Root.swift | 9 ++--- .../FlatBuffers/String+extension.swift | 6 +-- swift/Sources/FlatBuffers/Struct.swift | 6 +-- swift/Sources/FlatBuffers/Table.swift | 6 +-- swift/Sources/FlatBuffers/TableVerifier.swift | 6 +-- .../Sources/FlatBuffers/VeriferOptions.swift | 6 +-- swift/Sources/FlatBuffers/Verifiable.swift | 6 +-- swift/Sources/FlatBuffers/Verifier.swift | 6 +-- tests/swift/Wasm.tests/.swift-version | 1 - tests/swift/Wasm.tests/Package.swift | 10 +++-- .../swift/Wasm.tests/Sources/Wasm/Wasm.swift | 2 +- .../FlatBuffersMonsterWriterTests.swift | 2 +- tests/swift/tests/Package.swift | 13 +++++-- .../tests/Sources/SwiftFlatBuffers/main.swift | 2 +- .../FlatBuffersMonsterWriterTests.swift | 2 +- .../FlatBuffersNanInfTests.swift | 2 +- .../FlatBuffersStructsTests.swift | 2 +- .../FlatBuffersTests.swift | 2 +- .../FlatBuffersUnionTests.swift | 2 +- .../FlatBuffersVectorsTests.swift | 2 +- .../FlatbuffersDoubleTests.swift | 2 +- .../FlatbuffersMoreDefaults.swift | 2 +- .../FlatbuffersVerifierTests.swift | 2 +- 44 files changed, 89 insertions(+), 192 deletions(-) delete mode 100644 Package@swift-5.5.swift delete mode 100644 tests/swift/Wasm.tests/.swift-version diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 1dcf09d23..2497ad41f 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -5,7 +5,7 @@ platforms: ubuntu1804: environment: CC: clang - SWIFT_VERSION: "5.5.3" + SWIFT_VERSION: "5.8" SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION" PATH: "$PATH:$SWIFT_HOME/usr/bin" shell_commands: @@ -19,7 +19,7 @@ platforms: ubuntu2004: environment: CC: clang - SWIFT_VERSION: "5.5.3" + SWIFT_VERSION: "5.8" SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION" PATH: "$PATH:$SWIFT_HOME/usr/bin" shell_commands: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b501bdfc9..520f55542 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -486,10 +486,18 @@ jobs: build-swift: name: Build Swift + strategy: + matrix: + swift: ["5.8", "5.9", "5.10"] # Only 22.04 has swift at the moment https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md?plain=1#L30 runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 + - uses: swift-actions/setup-swift@v2 + with: + swift-version: ${{ matrix.swift }} + - name: Get swift version + run: swift --version - name: test working-directory: tests/swift/tests run: | @@ -505,9 +513,12 @@ jobs: - uses: actions/checkout@v3 - name: Setup Wasmer uses: wasmerio/setup-wasmer@v2 + - uses: swiftwasm/setup-swiftwasm@v1 + with: + swift-version: "wasm-5.9.2-RELEASE" - name: Test working-directory: tests/swift/Wasm.tests - run: carton test + run: swift run carton test build-ts: name: Build TS diff --git a/Package.swift b/Package.swift index 0fc26da76..dd9d32be3 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.6 +// swift-tools-version:5.8 /* * Copyright 2020 Google Inc. All rights reserved. * diff --git a/Package@swift-5.5.swift b/Package@swift-5.5.swift deleted file mode 100644 index 13313560e..000000000 --- a/Package@swift-5.5.swift +++ /dev/null @@ -1,37 +0,0 @@ -// swift-tools-version:5.5 -/* - * Copyright 2020 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import PackageDescription - -let package = Package( - name: "FlatBuffers", - platforms: [ - .iOS(.v11), - .macOS(.v10_14), - ], - products: [ - .library( - name: "FlatBuffers", - targets: ["FlatBuffers"]), - ], - targets: [ - .target( - name: "FlatBuffers", - dependencies: [], - path: "swift/Sources"), - ]) - diff --git a/benchmarks/swift/Benchmarks/FlatbuffersBenchmarks/FlatbuffersBenchmarks.swift b/benchmarks/swift/Benchmarks/FlatbuffersBenchmarks/FlatbuffersBenchmarks.swift index 902ff475a..263e006be 100644 --- a/benchmarks/swift/Benchmarks/FlatbuffersBenchmarks/FlatbuffersBenchmarks.swift +++ b/benchmarks/swift/Benchmarks/FlatbuffersBenchmarks/FlatbuffersBenchmarks.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/grpc/examples/swift/Greeter/Sources/client/main.swift b/grpc/examples/swift/Greeter/Sources/client/main.swift index a4b2a675c..e7065ac9c 100644 --- a/grpc/examples/swift/Greeter/Sources/client/main.swift +++ b/grpc/examples/swift/Greeter/Sources/client/main.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/grpc/examples/swift/Greeter/Sources/server/main.swift b/grpc/examples/swift/Greeter/Sources/server/main.swift index 62286c475..60deb544a 100644 --- a/grpc/examples/swift/Greeter/Sources/server/main.swift +++ b/grpc/examples/swift/Greeter/Sources/server/main.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/sample_binary.swift b/samples/sample_binary.swift index 4df546fca..08fb9a825 100644 --- a/samples/sample_binary.swift +++ b/samples/sample_binary.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/swift.swiftformat b/swift.swiftformat index 80e475a51..f8b2a6b02 100644 --- a/swift.swiftformat +++ b/swift.swiftformat @@ -6,7 +6,7 @@ # options --self remove # redundantSelf ---importgrouping testable-bottom # sortedImports +--importgrouping testable-bottom # sortImports --trimwhitespace always --indentcase false --ifdef no-indent #indent @@ -17,7 +17,7 @@ --typeattributes prev-line # wrapAttributes # rules ---rules wrap,todos,anyObjectProtocol,redundantParens,redundantReturn,redundantSelf,sortedImports,strongifiedSelf,trailingCommas,trailingSpace,wrapArguments,wrapMultilineStatementBraces,indent,wrapAttributes,void,fileHeader +--rules wrap,todos,anyObjectProtocol,redundantParens,redundantReturn,redundantSelf,sortImports,strongifiedSelf,trailingCommas,trailingSpace,wrapArguments,wrapMultilineStatementBraces,indent,wrapAttributes,void,fileHeader --disable trailingclosures --exclude **/*_generated.swift diff --git a/swift/Sources/FlatBuffers/ByteBuffer.swift b/swift/Sources/FlatBuffers/ByteBuffer.swift index d33574d8b..f8de2ca74 100644 --- a/swift/Sources/FlatBuffers/ByteBuffer.swift +++ b/swift/Sources/FlatBuffers/ByteBuffer.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// `ByteBuffer` is the interface that stores the data for a `Flatbuffers` object /// it allows users to write and read data directly from memory thus the use of its @@ -121,11 +117,11 @@ public struct ByteBuffer { public let allowReadingUnalignedBuffers: Bool /// Constructor that creates a Flatbuffer object from a UInt8 - /// - Parameter + /// - Parameter /// - bytes: Array of UInt8 /// - allowReadingUnalignedBuffers: allow reading from unaligned buffer public init( - bytes: [UInt8], + bytes: [UInt8], allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false) { var b = bytes @@ -133,17 +129,17 @@ public struct ByteBuffer { _writerSize = _storage.capacity allowReadingUnalignedBuffers = allowUnalignedBuffers b.withUnsafeMutableBytes { bufferPointer in - self._storage.copy(from: bufferPointer.baseAddress!, count: bytes.count) + _storage.copy(from: bufferPointer.baseAddress!, count: bytes.count) } } #if !os(WASI) /// Constructor that creates a Flatbuffer from the Swift Data type object - /// - Parameter + /// - Parameter /// - data: Swift data Object /// - allowReadingUnalignedBuffers: allow reading from unaligned buffer public init( - data: Data, + data: Data, allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false) { var b = data @@ -151,7 +147,7 @@ public struct ByteBuffer { _writerSize = _storage.capacity allowReadingUnalignedBuffers = allowUnalignedBuffers b.withUnsafeMutableBytes { bufferPointer in - self._storage.copy(from: bufferPointer.baseAddress!, count: data.count) + _storage.copy(from: bufferPointer.baseAddress!, count: data.count) } } #endif @@ -175,7 +171,7 @@ public struct ByteBuffer { /// - allowReadingUnalignedBuffers: allow reading from unaligned buffer public init( contiguousBytes: Bytes, - count: Int, + count: Int, allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false) { _storage = Storage(count: count, alignment: alignment) @@ -208,7 +204,7 @@ public struct ByteBuffer { /// - count: count of bytes /// - allowReadingUnalignedBuffers: allow reading from unaligned buffer init( - memory: UnsafeMutableRawPointer, + memory: UnsafeMutableRawPointer, count: Int, allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false) { @@ -228,7 +224,7 @@ public struct ByteBuffer { memory: UnsafeMutableRawPointer, count: Int, removing removeBytes: Int, - allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false) + allowReadingUnalignedBuffers allowUnalignedBuffers: Bool = false) { _storage = Storage(count: count, alignment: alignment) _storage.copy(from: memory, count: count) @@ -257,7 +253,7 @@ public struct ByteBuffer { _storage.memory.advanced(by: writerIndex &- ptr.count), UnsafeRawPointer(ptr.baseAddress!), ptr.count) - self._writerSize = self._writerSize &+ ptr.count + _writerSize = _writerSize &+ ptr.count } } @@ -271,7 +267,7 @@ public struct ByteBuffer { _storage.memory .advanced(by: writerIndex &- ptr.count) .copyMemory(from: ptr.baseAddress!, byteCount: ptr.count) - self._writerSize = self._writerSize &+ ptr.count + _writerSize = _writerSize &+ ptr.count } } @@ -287,7 +283,7 @@ public struct ByteBuffer { _storage.memory.advanced(by: writerIndex &- ptr.count), UnsafeRawPointer(ptr.baseAddress!), ptr.count) - self._writerSize = self._writerSize &+ ptr.count + _writerSize = _writerSize &+ ptr.count } } #endif @@ -306,7 +302,7 @@ public struct ByteBuffer { _storage.memory.advanced(by: writerIndex &- size), $0.baseAddress!, size) - self._writerSize = self._writerSize &+ size + _writerSize = _writerSize &+ size } } @@ -324,7 +320,7 @@ public struct ByteBuffer { _storage.memory.advanced(by: writerIndex &- len), $0.baseAddress!, len) - self._writerSize = self._writerSize &+ len + _writerSize = _writerSize &+ len } } @@ -429,11 +425,9 @@ public struct ByteBuffer { /// - position: the index of the object in the buffer @inline(__always) public func read(def: T.Type, position: Int) -> T { - #if swift(>=5.7) if allowReadingUnalignedBuffers { return _storage.memory.advanced(by: position).loadUnaligned(as: T.self) } - #endif return _storage.memory.advanced(by: position).load(as: T.self) } @@ -538,7 +532,8 @@ extension ByteBuffer: CustomDebugStringConvertible { public var debugDescription: String { """ buffer located at: \(_storage.memory), with capacity of \(_storage.capacity) - { writerSize: \(_writerSize), readerSize: \(reader), writerIndex: \(writerIndex) } + { writerSize: \(_writerSize), readerSize: \(reader), writerIndex: \( + writerIndex) } """ } } diff --git a/swift/Sources/FlatBuffers/Constants.swift b/swift/Sources/FlatBuffers/Constants.swift index 03a9b9f5c..0790dd03e 100644 --- a/swift/Sources/FlatBuffers/Constants.swift +++ b/swift/Sources/FlatBuffers/Constants.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,15 +14,7 @@ * limitations under the License. */ -#if !os(WASI) -#if os(Linux) -import CoreFoundation -#else import Foundation -#endif -#else -import SwiftOverlayShims -#endif /// A boolean to see if the system is littleEndian let isLitteEndian: Bool = { diff --git a/swift/Sources/FlatBuffers/Enum.swift b/swift/Sources/FlatBuffers/Enum.swift index ab5db06c9..29b382247 100644 --- a/swift/Sources/FlatBuffers/Enum.swift +++ b/swift/Sources/FlatBuffers/Enum.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// Enum is a protocol that all flatbuffers enums should conform to /// Since it allows us to get the actual `ByteSize` and `Value` from diff --git a/swift/Sources/FlatBuffers/FlatBufferBuilder.swift b/swift/Sources/FlatBuffers/FlatBufferBuilder.swift index bf1978e33..57fecc6c9 100644 --- a/swift/Sources/FlatBuffers/FlatBufferBuilder.swift +++ b/swift/Sources/FlatBuffers/FlatBufferBuilder.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// ``FlatBufferBuilder`` builds a `FlatBuffer` through manipulating its internal state. /// @@ -836,7 +832,8 @@ extension FlatBufferBuilder: CustomDebugStringConvertible { buffer debug: \(_bb) builder debug: - { finished: \(finished), serializeDefaults: \(serializeDefaults), isNested: \(isNested) } + { finished: \(finished), serializeDefaults: \( + serializeDefaults), isNested: \(isNested) } """ } diff --git a/swift/Sources/FlatBuffers/FlatBufferObject.swift b/swift/Sources/FlatBuffers/FlatBufferObject.swift index 705c93463..e836e6120 100644 --- a/swift/Sources/FlatBuffers/FlatBufferObject.swift +++ b/swift/Sources/FlatBuffers/FlatBufferObject.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// NativeStruct is a protocol that indicates if the struct is a native `swift` struct /// since now we will be serializing native structs into the buffer. diff --git a/swift/Sources/FlatBuffers/FlatBuffersUtils.swift b/swift/Sources/FlatBuffers/FlatBuffersUtils.swift index 338988df7..18c130f5a 100644 --- a/swift/Sources/FlatBuffers/FlatBuffersUtils.swift +++ b/swift/Sources/FlatBuffers/FlatBuffersUtils.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// FlatBuffersUtils hosts some utility functions that might be useful public enum FlatBuffersUtils { diff --git a/swift/Sources/FlatBuffers/FlatbuffersErrors.swift b/swift/Sources/FlatBuffers/FlatbuffersErrors.swift index 1a9284eba..c054d1661 100644 --- a/swift/Sources/FlatBuffers/FlatbuffersErrors.swift +++ b/swift/Sources/FlatBuffers/FlatbuffersErrors.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// Collection of thrown from the Flatbuffer verifier public enum FlatbuffersErrors: Error, Equatable { diff --git a/swift/Sources/FlatBuffers/Int+extension.swift b/swift/Sources/FlatBuffers/Int+extension.swift index c8cd0e364..62b5cd5cd 100644 --- a/swift/Sources/FlatBuffers/Int+extension.swift +++ b/swift/Sources/FlatBuffers/Int+extension.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif extension Int { diff --git a/swift/Sources/FlatBuffers/Message.swift b/swift/Sources/FlatBuffers/Message.swift index 172a339db..8ccfca418 100644 --- a/swift/Sources/FlatBuffers/Message.swift +++ b/swift/Sources/FlatBuffers/Message.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// FlatBufferGRPCMessage protocol that should allow us to invoke /// initializers directly from the GRPC generated code diff --git a/swift/Sources/FlatBuffers/Mutable.swift b/swift/Sources/FlatBuffers/Mutable.swift index 7a1a3d5bc..f6e4688b1 100644 --- a/swift/Sources/FlatBuffers/Mutable.swift +++ b/swift/Sources/FlatBuffers/Mutable.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,17 +14,13 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// Mutable is a protocol that allows us to mutate Scalar values within a ``ByteBuffer`` public protocol Mutable { /// makes Flatbuffer accessed within the Protocol var bb: ByteBuffer { get } - /// makes position of the ``Table``/``struct`` accessed within the Protocol + /// makes position of the ``Table``/``Struct`` accessed within the Protocol var postion: Int32 { get } } diff --git a/swift/Sources/FlatBuffers/NativeObject.swift b/swift/Sources/FlatBuffers/NativeObject.swift index 9c72b50b7..318896cc0 100644 --- a/swift/Sources/FlatBuffers/NativeObject.swift +++ b/swift/Sources/FlatBuffers/NativeObject.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// NativeObject is a protocol that all of the `Object-API` generated code should be /// conforming to since it allows developers the ease of use to pack and unpack their diff --git a/swift/Sources/FlatBuffers/Offset.swift b/swift/Sources/FlatBuffers/Offset.swift index e433f35a2..95ef9df99 100644 --- a/swift/Sources/FlatBuffers/Offset.swift +++ b/swift/Sources/FlatBuffers/Offset.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// Offset object for all the Objects that are written into the buffer public struct Offset { diff --git a/swift/Sources/FlatBuffers/Root.swift b/swift/Sources/FlatBuffers/Root.swift index 6269148bb..8e606e6cc 100644 --- a/swift/Sources/FlatBuffers/Root.swift +++ b/swift/Sources/FlatBuffers/Root.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// Takes in a prefixed sized buffer, where the prefixed size would be skipped. /// And would verify that the buffer passed is a valid `Flatbuffers` Object. @@ -74,7 +70,8 @@ public func getCheckedPrefixedSizeRoot( /// /// ``getPrefixedSizeCheckedRoot(byteBuffer:options:)`` would skip the first Bytes in /// the ``ByteBuffer`` and then calls ``getRoot(byteBuffer:)`` -public func getPrefixedSizeRoot(byteBuffer: inout ByteBuffer) +public func getPrefixedSizeRoot( + byteBuffer: inout ByteBuffer) -> T { byteBuffer.skipPrefix() diff --git a/swift/Sources/FlatBuffers/String+extension.swift b/swift/Sources/FlatBuffers/String+extension.swift index 35c83cbdb..de4f5f91f 100644 --- a/swift/Sources/FlatBuffers/String+extension.swift +++ b/swift/Sources/FlatBuffers/String+extension.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif extension String: Verifiable { diff --git a/swift/Sources/FlatBuffers/Struct.swift b/swift/Sources/FlatBuffers/Struct.swift index 04cfba092..5124b2af9 100644 --- a/swift/Sources/FlatBuffers/Struct.swift +++ b/swift/Sources/FlatBuffers/Struct.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// Struct is a representation of a mutable `Flatbuffers` struct /// since native structs are value types and cant be mutated diff --git a/swift/Sources/FlatBuffers/Table.swift b/swift/Sources/FlatBuffers/Table.swift index 0da5919a8..7ad0ae0cc 100644 --- a/swift/Sources/FlatBuffers/Table.swift +++ b/swift/Sources/FlatBuffers/Table.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// `Table` is a Flatbuffers object that can read, /// mutate scalar fields within a valid flatbuffers buffer diff --git a/swift/Sources/FlatBuffers/TableVerifier.swift b/swift/Sources/FlatBuffers/TableVerifier.swift index 45f0a5aba..6c763c59b 100644 --- a/swift/Sources/FlatBuffers/TableVerifier.swift +++ b/swift/Sources/FlatBuffers/TableVerifier.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// `TableVerifier` verifies a table object is within a provided memory. /// It checks if all the objects for a specific generated table, are within diff --git a/swift/Sources/FlatBuffers/VeriferOptions.swift b/swift/Sources/FlatBuffers/VeriferOptions.swift index a760ffbab..a7f11e243 100644 --- a/swift/Sources/FlatBuffers/VeriferOptions.swift +++ b/swift/Sources/FlatBuffers/VeriferOptions.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// `VerifierOptions` is a set of options to verify a flatbuffer public struct VerifierOptions { diff --git a/swift/Sources/FlatBuffers/Verifiable.swift b/swift/Sources/FlatBuffers/Verifiable.swift index f16d42172..3d3e08f0f 100644 --- a/swift/Sources/FlatBuffers/Verifiable.swift +++ b/swift/Sources/FlatBuffers/Verifiable.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// Verifiable is a protocol all swift flatbuffers object should conform to, /// since swift is similar to `cpp` and `rust` where the data is read directly diff --git a/swift/Sources/FlatBuffers/Verifier.swift b/swift/Sources/FlatBuffers/Verifier.swift index 6daf6f50c..121f43498 100644 --- a/swift/Sources/FlatBuffers/Verifier.swift +++ b/swift/Sources/FlatBuffers/Verifier.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,7 @@ * limitations under the License. */ -#if !os(WASI) import Foundation -#else -import SwiftOverlayShims -#endif /// Verifier that check if the buffer passed into it is a valid, /// safe, aligned Flatbuffers object since swift read from `unsafeMemory` diff --git a/tests/swift/Wasm.tests/.swift-version b/tests/swift/Wasm.tests/.swift-version deleted file mode 100644 index d9bd01e0a..000000000 --- a/tests/swift/Wasm.tests/.swift-version +++ /dev/null @@ -1 +0,0 @@ -wasm-5.7-SNAPSHOT-2022-09-24-a \ No newline at end of file diff --git a/tests/swift/Wasm.tests/Package.swift b/tests/swift/Wasm.tests/Package.swift index e45db6ffd..f5994cd50 100644 --- a/tests/swift/Wasm.tests/Package.swift +++ b/tests/swift/Wasm.tests/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.1 +// swift-tools-version:5.9 /* * Copyright 2020 Google Inc. All rights reserved. * @@ -24,11 +24,13 @@ let package = Package( ], dependencies: [ .package(path: "../../.."), + .package(url: "https://github.com/swiftwasm/carton", exact: "1.0.1"), ], targets: [ - .target( - name: "Wasm"), + .target(name: "Wasm"), .testTarget( name: "FlatBuffers.Test.Swift.WasmTests", - dependencies: ["FlatBuffers"]), + dependencies: [ + .product(name: "FlatBuffers", package: "flatbuffers"), + ]), ]) diff --git a/tests/swift/Wasm.tests/Sources/Wasm/Wasm.swift b/tests/swift/Wasm.tests/Sources/Wasm/Wasm.swift index 1b0952bc0..e77aa2fec 100644 --- a/tests/swift/Wasm.tests/Sources/Wasm/Wasm.swift +++ b/tests/swift/Wasm.tests/Sources/Wasm/Wasm.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/FlatBuffersMonsterWriterTests.swift b/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/FlatBuffersMonsterWriterTests.swift index b00094e2a..d126b0f6a 100644 --- a/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/FlatBuffersMonsterWriterTests.swift +++ b/tests/swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests/FlatBuffersMonsterWriterTests.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/swift/tests/Package.swift b/tests/swift/tests/Package.swift index 8b91712b4..c9a621e64 100644 --- a/tests/swift/tests/Package.swift +++ b/tests/swift/tests/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.1 +// swift-tools-version:5.8 /* * Copyright 2020 Google Inc. All rights reserved. * @@ -28,10 +28,15 @@ let package = Package( .package(url: "https://github.com/grpc/grpc-swift.git", from: "1.4.1"), ], targets: [ - .target( + .executableTarget( name: "SwiftFlatBuffers", - dependencies: ["FlatBuffers"]), + dependencies: [ + .product(name: "FlatBuffers", package: "flatbuffers"), + ]), .testTarget( name: "FlatBuffers.Test.SwiftTests", - dependencies: ["FlatBuffers", "GRPC"]), + dependencies: [ + .product(name: "FlatBuffers", package: "flatbuffers"), + .product(name: "GRPC", package: "grpc-swift"), + ]), ]) diff --git a/tests/swift/tests/Sources/SwiftFlatBuffers/main.swift b/tests/swift/tests/Sources/SwiftFlatBuffers/main.swift index cfd3009e5..146b6362e 100644 --- a/tests/swift/tests/Sources/SwiftFlatBuffers/main.swift +++ b/tests/swift/tests/Sources/SwiftFlatBuffers/main.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift index b72af55a5..ccd8200bc 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift index 07cdeb010..096992338 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift index 21b4d4b5e..3efdb2042 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift index 5f4916847..13780d53d 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift index 4eb3f345b..1f7edaf68 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersVectorsTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersVectorsTests.swift index be9b405e0..ab9d2fea9 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersVectorsTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersVectorsTests.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersDoubleTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersDoubleTests.swift index f85abf63d..8898391e9 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersDoubleTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersDoubleTests.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift index 45be6cf6c..66a106e37 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift index cb52d1168..00b02b760 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google Inc. All rights reserved. + * Copyright 2024 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.