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