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
This commit is contained in:
mustiikhalil
2024-05-29 22:07:54 +02:00
committed by GitHub
parent 3b27f5396e
commit 75f05d6389
44 changed files with 89 additions and 192 deletions

View File

@@ -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<Bytes: ContiguousBytes>(
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<T>(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) }
"""
}
}

View File

@@ -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 = {

View File

@@ -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

View File

@@ -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) }
"""
}

View File

@@ -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.

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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

View File

@@ -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 }
}

View File

@@ -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

View File

@@ -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 {

View File

@@ -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<T: FlatBufferObject & Verifiable>(
///
/// ``getPrefixedSizeCheckedRoot(byteBuffer:options:)`` would skip the first Bytes in
/// the ``ByteBuffer`` and then calls ``getRoot(byteBuffer:)``
public func getPrefixedSizeRoot<T: FlatBufferObject>(byteBuffer: inout ByteBuffer)
public func getPrefixedSizeRoot<T: FlatBufferObject>(
byteBuffer: inout ByteBuffer)
-> T
{
byteBuffer.skipPrefix()

View File

@@ -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 {

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 {

View File

@@ -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

View File

@@ -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`