Skip to content

Commit 662abf6

Browse files
authored
Merge pull request #317 from hashgraph/sr/ci-matrix
ci(swift): Add CI jobs for multiple swift versions
2 parents 6e22077 + 0e3f39a commit 662abf6

22 files changed

+67
-51
lines changed

.github/workflows/swift-ci.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,22 @@ jobs:
6464
run: swift format lint --strict --configuration .swift-format.json --recursive --parallel Sources/ Tests/ Examples/ Package.swift
6565

6666
build:
67+
strategy:
68+
matrix:
69+
swift: ["5.5", "5.7"]
6770
needs: build-ffi
6871
runs-on: macos-12
6972
steps:
73+
- uses: swift-actions/setup-swift@v1
74+
with:
75+
swift-version: ${{ matrix.swift }}
76+
7077
- uses: actions/checkout@v3
7178

7279
- uses: actions/cache@v3
7380
with:
7481
path: sdk/swift/.build
75-
key: ${{ runner.os }}-spm-${{ github.job }}-${{ hashFiles('**/Package.resolved') }}
82+
key: ${{ runner.os }}-spm-${{ github.job }}-${{ matrix.swift }}-${{ hashFiles('**/Package.resolved') }}
7683

7784
- name: Download CHedera artifacts
7885
uses: actions/download-artifact@v3
@@ -91,15 +98,21 @@ jobs:
9198
run: swift build
9299

93100
test:
101+
strategy:
102+
matrix:
103+
swift: ["5.5", "5.7"]
94104
needs: [build-ffi, build]
95105
runs-on: macos-12
96106
steps:
107+
- uses: swift-actions/setup-swift@v1
108+
with:
109+
swift-version: ${{ matrix.swift }}
97110
- uses: actions/checkout@v3
98111

99112
- uses: actions/cache@v3
100113
with:
101114
path: sdk/swift/.build
102-
key: ${{ runner.os }}-spm-${{ github.job }}-${{ hashFiles('**/Package.resolved') }}
115+
key: ${{ runner.os }}-spm-${{ github.job }}-${{ matrix.swift }}-${{ hashFiles('**/Package.resolved') }}
103116

104117
- name: Download CHedera `x86_64-apple-darwin`
105118
uses: actions/download-artifact@v3

sdk/rust/rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2022-07-30"
2+
channel = "nightly-2022-10-30"
33
components = ["rust-src", "miri"]

sdk/swift/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
## Requirements
1111

12-
- Swift v5.3+
12+
- Swift v5.5+
1313
- MacOS v10.15+ (2019, Catalina)
14-
- iOS 12+ (2018)
14+
- iOS 13+ (2019)
1515

1616
## Install
1717

sdk/swift/Sources/Hedera/Account/AccountBalance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public final class AccountBalance: Codable {
4242
}
4343

4444
public static func fromBytes(_ bytes: Data) throws -> Self {
45-
try bytes.withUnsafeBytes { (pointer: UnsafeRawBufferPointer) in
45+
try bytes.withUnsafeTypedBytes { pointer in
4646
var balance = HederaAccountBalance()
4747

4848
let err = hedera_account_balance_from_bytes(

sdk/swift/Sources/Hedera/Account/AccountId.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public final class AccountId: EntityId {
9393
}
9494

9595
public static func fromBytes(_ bytes: Data) throws -> Self {
96-
try bytes.withUnsafeBytes { (pointer: UnsafeRawBufferPointer) in
96+
try bytes.withUnsafeTypedBytes { pointer in
9797
var id = HederaAccountId()
9898

9999
let err = hedera_account_id_from_bytes(

sdk/swift/Sources/Hedera/Account/AccountInfo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public final class AccountInfo: Codable {
7676
public let staking: StakingInfo?
7777

7878
public static func fromBytes(_ bytes: Data) throws -> Self {
79-
let json: String = try bytes.withUnsafeBytes { (pointer: UnsafeRawBufferPointer) in
80-
var ptr: UnsafeMutablePointer<CChar>? = UnsafeMutablePointer(bitPattern: 0)
79+
let json: String = try bytes.withUnsafeTypedBytes { pointer in
80+
var ptr: UnsafeMutablePointer<CChar>? = nil
8181
let err = hedera_account_info_from_bytes(
8282
pointer.baseAddress,
8383
pointer.count,

sdk/swift/Sources/Hedera/Contract/ContractInfo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public final class ContractInfo: Codable {
6666
public let stakingInfo: StakingInfo
6767

6868
public static func fromBytes(_ bytes: Data) throws -> Self {
69-
let json: String = try bytes.withUnsafeBytes { (pointer: UnsafeRawBufferPointer) in
70-
var ptr: UnsafeMutablePointer<CChar>? = UnsafeMutablePointer(bitPattern: 0)
69+
let json: String = try bytes.withUnsafeTypedBytes { pointer in
70+
var ptr: UnsafeMutablePointer<CChar>? = nil
7171
let err = hedera_contract_info_from_bytes(
7272
pointer.baseAddress,
7373
pointer.count,

sdk/swift/Sources/Hedera/Data+Extensions.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension Data {
4545
// safety: `hedera_bytes_free` needs to be called so...
4646
// perf: might as well enable use of the no copy constructor.
4747
internal static let unsafeCHederaBytesFree: Data.Deallocator = .custom { (buf, size) in
48-
hedera_bytes_free(buf, size)
48+
hedera_bytes_free(buf.bindMemory(to: UInt8.self, capacity: size), size)
4949
}
5050

5151
private static let hexAlphabet = Array("0123456789abcdef".unicodeScalars)
@@ -89,3 +89,11 @@ extension Data {
8989
self.init(arr)
9090
}
9191
}
92+
93+
extension Data {
94+
internal func withUnsafeTypedBytes<R>(_ body: (UnsafeBufferPointer<UInt8>) throws -> R) rethrows -> R {
95+
try self.withUnsafeBytes { pointer in
96+
try body(pointer.bindMemory(to: UInt8.self))
97+
}
98+
}
99+
}

sdk/swift/Sources/Hedera/EntityId.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public final class FileId: EntityId {
9595
public static let exchangeRates: FileId = FileId(num: 112)
9696

9797
public static func fromBytes(_ bytes: Data) throws -> Self {
98-
try bytes.withUnsafeBytes { (pointer: UnsafeRawBufferPointer) in
98+
try bytes.withUnsafeTypedBytes { pointer in
9999
var shard: UInt64 = 0
100100
var realm: UInt64 = 0
101101
var num: UInt64 = 0
@@ -121,7 +121,7 @@ public final class FileId: EntityId {
121121
/// The unique identifier for a smart contract on Hedera.
122122
public final class ContractId: EntityId {
123123
public static func fromBytes(_ bytes: Data) throws -> Self {
124-
try bytes.withUnsafeBytes { (pointer: UnsafeRawBufferPointer) in
124+
try bytes.withUnsafeTypedBytes { pointer in
125125
var shard: UInt64 = 0
126126
var realm: UInt64 = 0
127127
var num: UInt64 = 0
@@ -147,7 +147,7 @@ public final class ContractId: EntityId {
147147
/// The unique identifier for a topic on Hedera.
148148
public final class TopicId: EntityId {
149149
public static func fromBytes(_ bytes: Data) throws -> Self {
150-
try bytes.withUnsafeBytes { (pointer: UnsafeRawBufferPointer) in
150+
try bytes.withUnsafeTypedBytes { pointer in
151151
var shard: UInt64 = 0
152152
var realm: UInt64 = 0
153153
var num: UInt64 = 0
@@ -173,7 +173,7 @@ public final class TopicId: EntityId {
173173
/// The unique identifier for a token on Hedera.
174174
public final class TokenId: EntityId {
175175
public static func fromBytes(_ bytes: Data) throws -> Self {
176-
try bytes.withUnsafeBytes { (pointer: UnsafeRawBufferPointer) in
176+
try bytes.withUnsafeTypedBytes { pointer in
177177
var shard: UInt64 = 0
178178
var realm: UInt64 = 0
179179
var num: UInt64 = 0
@@ -199,7 +199,7 @@ public final class TokenId: EntityId {
199199
/// The unique identifier for a schedule on Hedera.
200200
public final class ScheduleId: EntityId {
201201
public static func fromBytes(_ bytes: Data) throws -> Self {
202-
try bytes.withUnsafeBytes { (pointer: UnsafeRawBufferPointer) in
202+
try bytes.withUnsafeTypedBytes { pointer in
203203
var shard: UInt64 = 0
204204
var realm: UInt64 = 0
205205
var num: UInt64 = 0

sdk/swift/Sources/Hedera/File/FileInfo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public final class FileInfo: Codable {
4343
public let ledgerId: LedgerId
4444

4545
public static func fromBytes(_ bytes: Data) throws -> Self {
46-
let json: String = try bytes.withUnsafeBytes { (pointer: UnsafeRawBufferPointer) in
47-
var ptr: UnsafeMutablePointer<CChar>? = UnsafeMutablePointer(bitPattern: 0)
46+
let json: String = try bytes.withUnsafeTypedBytes { pointer in
47+
var ptr: UnsafeMutablePointer<CChar>? = nil
4848
let err = hedera_file_info_from_bytes(
4949
pointer.baseAddress,
5050
pointer.count,

0 commit comments

Comments
 (0)