Skip to content

Commit 98ed83a

Browse files
authored
Upgrade to Swift 6.2: Update tools version, CI matrix, and fix unsafe (#72)
* Upgrade to Swift 6.1: Update tools version, CI matrix, and fix unsafe pointer usage * Update Swift version badge in README * Remove obsolete XCTestManifests.swift * Update swift-actions/setup-swift to v3 * Update GitHub Actions checkout action to v6 This update ensures that the CI and documentation generation workflows are using the latest stable version of the `actions/checkout` action. * Update CI to use newer simulators and Swift versions Remove Swift 6.0 from CI matrix. Update iOS and watchOS simulator names to reflect newer hardware versions. * Simplify Package.swift dependencies
1 parent 8c676ce commit 98ed83a

File tree

9 files changed

+43
-42
lines changed

9 files changed

+43
-42
lines changed

.github/workflows/ci.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,35 @@ jobs:
66
lint:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v4
9+
- uses: actions/checkout@v6
1010
- uses: norio-nomura/action-swiftlint@3.2.1
1111
with:
1212
args: --strict
1313
macOS-test:
1414
strategy:
1515
matrix:
1616
swift-version:
17-
- "5.9"
17+
- "6.1"
18+
- "6.2"
1819
runs-on: macos-latest
1920
steps:
20-
- uses: actions/checkout@v4
21-
- uses: swift-actions/setup-swift@v1
21+
- uses: actions/checkout@v6
22+
- uses: swift-actions/setup-swift@v3
2223
with:
2324
swift-version: ${{ matrix.swift-version }}
2425
- run: swift test
2526
iOS-build:
2627
runs-on: macos-latest
2728
steps:
28-
- uses: actions/checkout@v4
29-
- run: xcodebuild -scheme NdArray -destination 'platform=iOS Simulator,name=iPhone 13'
29+
- uses: actions/checkout@v6
30+
- run: xcodebuild -scheme NdArray -destination 'platform=iOS Simulator,name=iPhone 16'
3031
tvOS-build:
3132
runs-on: macos-latest
3233
steps:
33-
- uses: actions/checkout@v4
34+
- uses: actions/checkout@v6
3435
- run: xcodebuild -scheme NdArray -destination 'platform=tvOS Simulator,name=Apple TV'
3536
whatchOS-build:
3637
runs-on: macos-latest
3738
steps:
38-
- uses: actions/checkout@v4
39-
- run: xcodebuild -scheme NdArray -destination 'platform=watchOS Simulator,name=Apple Watch Series 8 (45mm)'
39+
- uses: actions/checkout@v6
40+
- run: xcodebuild -scheme NdArray -destination 'platform=watchOS Simulator,name=Apple Watch Series 11 (46mm)'

.github/workflows/docc.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ jobs:
99
generate-docs:
1010
runs-on: macos-latest
1111
steps:
12-
- uses: actions/checkout@v4
13-
- uses: swift-actions/setup-swift@v1
12+
- uses: actions/checkout@v6
13+
- uses: swift-actions/setup-swift@v3
1414
with:
1515
swift-version: "5.9"
16+
1617
- name: generate-documentation
1718
# https://apple.github.io/swift-docc-plugin/documentation/swiftdoccplugin/generating-documentation-for-hosting-online/
1819
run: >
19-
swift package
20-
--allow-writing-to-directory ./docs
21-
generate-documentation
22-
--output-path ./docs
23-
--hosting-base-path NdArray
24-
--disable-indexing
20+
swift package
21+
--allow-writing-to-directory ./docs
22+
generate-documentation
23+
--output-path ./docs
24+
--hosting-base-path NdArray
25+
--disable-indexing
2526
--transform-for-static-hosting
2627
- name: generate theme-settings.json
2728
run: echo '' > theme-settings.json

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ DerivedData/
1111

1212
**.log
1313
**.bak
14+
15+
.DS_Store

Package.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.4
1+
// swift-tools-version:6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -11,16 +11,10 @@ let package = Package(
1111
name: "NdArray",
1212
targets: ["NdArray"]),
1313
],
14-
dependencies: {
14+
dependencies: [
1515
// https://apple.github.io/swift-docc-plugin/documentation/swiftdoccplugin/
16-
var deps: [PackageDescription.Package.Dependency] = []
17-
#if swift(>=5.6.0)
18-
deps.append(
19-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0")
20-
)
21-
#endif
22-
return deps
23-
}(),
16+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.5"),
17+
],
2418
targets: [
2519
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2620
// Targets can depend on other targets in this package, and on products in packages which this package depends on.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NdArray
22

3-
[![Swift Version](https://img.shields.io/badge/swift-5.9-blue.svg)](https://swift.org)
3+
[![Swift Version](https://img.shields.io/badge/swift-6.2-blue.svg)](https://swift.org)
44
![Platform](https://img.shields.io/badge/platform-macOS|iOS|tvOS|whatchOS-lightgray.svg)
55
![Build](https://github.com/dastrobu/NdArray/actions/workflows/ci.yaml/badge.svg)
66

@@ -711,4 +711,4 @@ Some features would be nice to have at some time but currently out of scope.
711711

712712
## Docs
713713

714-
Read the generated [docs](https://dastrobu.github.io/NdArray/documentation/ndarray).
714+
Read the generated [docs](https://dastrobu.github.io/NdArray/documentation/ndarray).

Sources/NdArray/NdArray.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ open class NdArray<T>: CustomDebugStringConvertible,
186186
for i in 0..<rowCount {
187187
let row = a[i]
188188
precondition(row.count == colCount, "\(row.count) == \(colCount) at row \(i)")
189-
memcpy(dataStart + i * strides[0], row, colCount * MemoryLayout<T>.stride)
189+
row.withUnsafeBufferPointer { p in
190+
if let base = p.baseAddress {
191+
memcpy(dataStart + i * strides[0], base, colCount * MemoryLayout<T>.stride)
192+
}
193+
}
190194
}
191195
case .F:
192196
for i in 0..<rowCount {
@@ -219,7 +223,11 @@ open class NdArray<T>: CustomDebugStringConvertible,
219223
for j in 0..<jCount {
220224
let aij = ai[j]
221225
precondition(aij.count == kCount, "\(aij.count) == \(kCount) at index \(i), \(j)")
222-
memcpy(dataStart + i * strides[0] + j * strides[1], aij, kCount * MemoryLayout<T>.stride)
226+
aij.withUnsafeBufferPointer { p in
227+
if let base = p.baseAddress {
228+
memcpy(dataStart + i * strides[0] + j * strides[1], base, kCount * MemoryLayout<T>.stride)
229+
}
230+
}
223231
}
224232
}
225233
case .F:

Sources/NdArray/matrix/Matrix.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ open class Matrix<T>: NdArray<T>, Sequence {
3333
for i in 0..<rowCount {
3434
let row = a[i]
3535
precondition(row.count == colCount, "\(row.count) == \(colCount) at row \(i)")
36-
memcpy(dataStart + i * strides[0], row, colCount * MemoryLayout<T>.stride)
36+
row.withUnsafeBufferPointer { p in
37+
if let base = p.baseAddress {
38+
memcpy(dataStart + i * strides[0], base, colCount * MemoryLayout<T>.stride)
39+
}
40+
}
3741
}
3842
case .F:
3943
for i in 0..<rowCount {

Tests/NdArrayTests/XCTestManifests.swift

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

Tests/NdArrayTests/test_support.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import XCTest
88
internal func XCTAssertEqual<T>(_ expression1: @autoclosure () throws -> [T],
99
_ expression2: @autoclosure () throws -> [T],
1010
accuracy: T, _ message: @autoclosure () -> String = "",
11-
file: StaticString = #file, line: UInt = #line) rethrows where T: FloatingPoint {
11+
file: StaticString = #filePath, line: UInt = #line) rethrows where T: FloatingPoint {
1212
let array1: [T] = try expression1()
1313
let array2: [T] = try expression2()
1414
XCTAssertEqual(array1.count, array2.count, file: file, line: line)

0 commit comments

Comments
 (0)