diff --git a/.github/workflows/swift-arm.yml b/.github/workflows/swift-arm.yml index de3f377..85235e1 100644 --- a/.github/workflows/swift-arm.yml +++ b/.github/workflows/swift-arm.yml @@ -1,24 +1,35 @@ name: Swift ARM -on: [push] + +on: + push: + branches: [master] + pull_request: + jobs: linux-armv7-crosscompile-build: name: Crosscompile for Linux Armv7 runs-on: ubuntu-latest - container: colemancda/swift-armv7:latest-prebuilt steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + # The SDK must match the host Swift toolchain version exactly. + - uses: SwiftyLab/setup-swift@latest + with: + swift-version: "6.4.2" + - name: Install armhf SDK + uses: swift-embedded-linux/armhf-action@main + id: armhf-sdk + with: + swift-version: 6.4.2 + distribution: debian-bookworm + arch: armv7 - name: Swift Version run: swift --version - name: Build (Release) - run: | - cd $SRC_ROOT - export SWIFT_PACKAGE_SRCDIR=$GITHUB_WORKSPACE - export SWIFT_PACKAGE_BUILDDIR=$SWIFT_PACKAGE_SRCDIR/.build - $SRC_ROOT/build-swift-package.sh + run: swift build -c release --build-system native --destination ${{ steps.armhf-sdk.outputs.destination_json }} - name: Archive Build artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: linux-armv7-crosscompile-test - path: .build/*/*.xctest + name: linux-armv7-crosscompile-build + path: .build/armv7-unknown-linux-gnueabihf/release/ diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 07aa121..a5ee7e5 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -1,17 +1,25 @@ name: Swift -on: [push] + +on: + push: + branches: [master] + pull_request: + jobs: macos: name: macOS - runs-on: macos-latest + runs-on: macos-26 steps: - - name: Install Swift - uses: slashmo/install-swift@v0.3.0 - with: - version: 5.7.3 - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 + # Xcode provides the macOS SDK; the Swift 6.4 toolchain comes from swift.org. + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: latest-stable + - uses: SwiftyLab/setup-swift@latest + with: + swift-version: "6.4.2" - name: Swift Version run: swift --version - name: Build (Debug) @@ -20,20 +28,22 @@ jobs: run: swift build -c release - name: Test (Debug) run: swift test -c debug - + linux: - name: Linux + name: Linux (${{ matrix.arch }}) strategy: + fail-fast: false matrix: - swift: [5.7.3] - runs-on: ubuntu-20.04 + include: + - arch: x86_64 + runner: ubuntu-latest + - arch: arm64 + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} + container: swift:6.4-noble steps: - - name: Install Swift - uses: slashmo/install-swift@v0.3.0 - with: - version: ${{ matrix.swift }} - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Swift Version run: swift --version - name: Build (Debug) diff --git a/Package.swift b/Package.swift index fecceae..56d73ab 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.5 +// swift-tools-version:6.4 import PackageDescription import class Foundation.ProcessInfo @@ -9,10 +9,10 @@ let libraryType: PackageDescription.Product.Library.LibraryType? = dynamicLibrar var package = Package( name: "Netlink", platforms: [ - .macOS(.v10_15), - .iOS(.v13), - .watchOS(.v6), - .tvOS(.v13), + .macOS(.v13), + .iOS(.v16), + .watchOS(.v9), + .tvOS(.v16), ], products: [ .library( @@ -85,12 +85,10 @@ var package = Package( ] ) -// SwiftPM command plugins are only supported by Swift version 5.6 and later. -#if swift(>=5.6) +// Documentation generation let buildDocs = ProcessInfo.processInfo.environment["BUILDING_FOR_DOCUMENTATION_GENERATION"] != nil if buildDocs { package.dependencies += [ .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"), ] } -#endif diff --git a/Sources/Netlink/AttributeType.swift b/Sources/Netlink/AttributeType.swift index eb56fdc..309e541 100644 --- a/Sources/Netlink/AttributeType.swift +++ b/Sources/Netlink/AttributeType.swift @@ -8,7 +8,7 @@ @_implementationOnly import CNetlink /// Netlink Attribute Type -public struct NetlinkAttributeType: RawRepresentable, Equatable, Hashable, OptionSet { +public struct NetlinkAttributeType: RawRepresentable, Equatable, Hashable, OptionSet, Sendable { public let rawValue: UInt16 diff --git a/Sources/Netlink/Internal/CInterop.swift b/Sources/Netlink/Internal/CInterop.swift index 9f9a22c..30393d4 100644 --- a/Sources/Netlink/Internal/CInterop.swift +++ b/Sources/Netlink/Internal/CInterop.swift @@ -54,8 +54,7 @@ internal extension CInterop.NetlinkSocketAddress { } extension CInterop.NetlinkSocketAddress: CSocketAddress { - - @usableFromInline + static var family: SocketAddressFamily { .netlink } } diff --git a/Sources/Netlink/Internal/CSocketAddress.swift b/Sources/Netlink/Internal/CSocketAddress.swift index 73f3a00..33813a1 100644 --- a/Sources/Netlink/Internal/CSocketAddress.swift +++ b/Sources/Netlink/Internal/CSocketAddress.swift @@ -8,15 +8,13 @@ import SystemPackage import Socket -@usableFromInline internal protocol CSocketAddress { - + static var family: SocketAddressFamily { get } } internal extension CSocketAddress { - - @usableFromInline + func withUnsafePointer( _ body: (UnsafePointer, UInt32) throws -> Result ) rethrows -> Result { @@ -25,7 +23,6 @@ internal extension CSocketAddress { } } - @usableFromInline mutating func withUnsafeMutablePointer( _ body: (UnsafeMutablePointer, UInt32) throws -> Result ) rethrows -> Result { diff --git a/Sources/Netlink/ProcessID.swift b/Sources/Netlink/ProcessID.swift index b924157..4b8f1ca 100644 --- a/Sources/Netlink/ProcessID.swift +++ b/Sources/Netlink/ProcessID.swift @@ -10,7 +10,7 @@ import SystemPackage /// POSIX Process ID @frozen -public struct ProcessID: RawRepresentable, Equatable, Hashable, Codable { +public struct ProcessID: RawRepresentable, Equatable, Hashable, Codable, Sendable { /// The raw C process ID. @_alwaysEmitIntoClient diff --git a/Sources/Netlink/Socket.swift b/Sources/Netlink/Socket.swift index 68ad1b9..e09c08d 100644 --- a/Sources/Netlink/Socket.swift +++ b/Sources/Netlink/Socket.swift @@ -21,6 +21,7 @@ public final class NetlinkSocket { // MARK: - Initialization deinit { + let socket = self.socket Task(priority: .high) { await socket.close() } @@ -38,7 +39,7 @@ public final class NetlinkSocket { processID: .current, group: group ) - try fileDescriptor.closeIfThrows { + try fileDescriptor.closeIfThrows { () throws(Errno) in try fileDescriptor.bind(address) } // initialize socket diff --git a/Sources/Netlink/SocketAddress.swift b/Sources/Netlink/SocketAddress.swift index d8c4de8..a2dc3c1 100644 --- a/Sources/Netlink/SocketAddress.swift +++ b/Sources/Netlink/SocketAddress.swift @@ -10,7 +10,7 @@ import SystemPackage import Socket @frozen -public struct NetlinkSocketAddress: Equatable, Hashable, SocketAddress { +public struct NetlinkSocketAddress: Equatable, Hashable, Sendable, SocketAddress { public typealias ProtocolID = NetlinkSocketProtocol @@ -33,17 +33,17 @@ public struct NetlinkSocketAddress: Equatable, Hashable, SocketAddress { ) } - public func withUnsafePointer( - _ body: (UnsafePointer, UInt32) throws -> Result - ) rethrows -> Result { - + public func withUnsafePointer( + _ body: (UnsafePointer, CInterop.SocketLength) throws(Error) -> Result + ) rethrows -> Result where Error: Swift.Error { + let socketAddress = CInterop.NetlinkSocketAddress( processID: processID, group: group ) return try socketAddress.withUnsafePointer(body) } - + public static func withUnsafePointer( _ pointer: UnsafeMutablePointer ) -> Self { @@ -51,9 +51,9 @@ public struct NetlinkSocketAddress: Equatable, Hashable, SocketAddress { return Self.init(pointer.pointee) } } - + public static func withUnsafePointer( - _ body: (UnsafeMutablePointer, UInt32) throws -> () + _ body: (UnsafeMutablePointer, CInterop.SocketLength) throws -> () ) rethrows -> Self { var socketAddress = CInterop.NetlinkSocketAddress() try socketAddress.withUnsafeMutablePointer(body) diff --git a/Sources/Netlink/SocketOption.swift b/Sources/Netlink/SocketOption.swift index f23dc8c..a8d1995 100644 --- a/Sources/Netlink/SocketOption.swift +++ b/Sources/Netlink/SocketOption.swift @@ -39,47 +39,47 @@ public extension NetlinkSocketOption { public extension NetlinkSocketOption { struct AddMembership: SocketOption { - + @_alwaysEmitIntoClient public static var id: NetlinkSocketOption { .addMembership } - + public var group: CInt - + public init(group: CInt) { self.group = group } - - public func withUnsafeBytes(_ pointer: ((UnsafeRawBufferPointer) throws -> (Result))) rethrows -> Result { + + public func withUnsafeBytes(_ pointer: ((UnsafeRawBufferPointer) throws(Error) -> (Result))) rethrows -> Result where Error: Swift.Error { return try Swift.withUnsafeBytes(of: group) { bufferPointer in try pointer(bufferPointer) } } - - public static func withUnsafeBytes(_ body: (UnsafeMutableRawBufferPointer) throws -> ()) rethrows -> Self { + + public static func withUnsafeBytes(_ body: (UnsafeMutableRawBufferPointer) throws(Error) -> ()) rethrows -> Self where Error: Swift.Error { var value: CInt = 0 try Swift.withUnsafeMutableBytes(of: &value, body) return self.init(group: value) } } - + struct DropMembership: SocketOption { - + @_alwaysEmitIntoClient public static var id: NetlinkSocketOption { .dropMembership } - + public var group: CInt - + public init(group: CInt) { self.group = group } - - public func withUnsafeBytes(_ pointer: ((UnsafeRawBufferPointer) throws -> (Result))) rethrows -> Result { + + public func withUnsafeBytes(_ pointer: ((UnsafeRawBufferPointer) throws(Error) -> (Result))) rethrows -> Result where Error: Swift.Error { return try Swift.withUnsafeBytes(of: group) { bufferPointer in try pointer(bufferPointer) } } - - public static func withUnsafeBytes(_ body: (UnsafeMutableRawBufferPointer) throws -> ()) rethrows -> Self { + + public static func withUnsafeBytes(_ body: (UnsafeMutableRawBufferPointer) throws(Error) -> ()) rethrows -> Self where Error: Swift.Error { var value: CInt = 0 try Swift.withUnsafeMutableBytes(of: &value, body) return self.init(group: value) diff --git a/Sources/Netlink/SocketProtocol.swift b/Sources/Netlink/SocketProtocol.swift index 707040a..99dfe7b 100644 --- a/Sources/Netlink/SocketProtocol.swift +++ b/Sources/Netlink/SocketProtocol.swift @@ -12,7 +12,7 @@ import Socket /// Netlink Socket Protocol @frozen -public struct NetlinkSocketProtocol: RawRepresentable, Equatable, Hashable { +public struct NetlinkSocketProtocol: RawRepresentable, Equatable, Hashable, Sendable { public let rawValue: Int32 diff --git a/Sources/NetlinkGeneric/GenericCommand.swift b/Sources/NetlinkGeneric/GenericCommand.swift index c2bb607..3cc0578 100644 --- a/Sources/NetlinkGeneric/GenericCommand.swift +++ b/Sources/NetlinkGeneric/GenericCommand.swift @@ -7,7 +7,7 @@ @_implementationOnly import CNetlink -public struct NetlinkGenericCommand: RawRepresentable, Equatable, Hashable { +public struct NetlinkGenericCommand: RawRepresentable, Equatable, Hashable, Sendable { public let rawValue: UInt8 diff --git a/Sources/NetlinkGeneric/GenericGroupName.swift b/Sources/NetlinkGeneric/GenericGroupName.swift index 01e50c4..e4d4b15 100644 --- a/Sources/NetlinkGeneric/GenericGroupName.swift +++ b/Sources/NetlinkGeneric/GenericGroupName.swift @@ -5,7 +5,7 @@ // Created by Alsey Coleman Miller on 7/7/18. // -public struct NetlinkGenericMulticastGroupName: RawRepresentable, Equatable, Hashable, Codable { +public struct NetlinkGenericMulticastGroupName: RawRepresentable, Equatable, Hashable, Codable, Sendable { public let rawValue: String diff --git a/Sources/NetlinkGeneric/GenericVersion.swift b/Sources/NetlinkGeneric/GenericVersion.swift index 6bb5c22..36facf2 100644 --- a/Sources/NetlinkGeneric/GenericVersion.swift +++ b/Sources/NetlinkGeneric/GenericVersion.swift @@ -6,7 +6,7 @@ // // -public struct NetlinkGenericVersion: RawRepresentable { +public struct NetlinkGenericVersion: RawRepresentable, Sendable { public let rawValue: UInt8