Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions .github/workflows/swift-arm.yml
Original file line number Diff line number Diff line change
@@ -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/
42 changes: 26 additions & 16 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:6.4
import PackageDescription
import class Foundation.ProcessInfo

Expand All @@ -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(
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion Sources/Netlink/AttributeType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions Sources/Netlink/Internal/CInterop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ internal extension CInterop.NetlinkSocketAddress {
}

extension CInterop.NetlinkSocketAddress: CSocketAddress {

@usableFromInline

static var family: SocketAddressFamily { .netlink }
}

Expand Down
7 changes: 2 additions & 5 deletions Sources/Netlink/Internal/CSocketAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
import SystemPackage
import Socket

@usableFromInline
internal protocol CSocketAddress {

static var family: SocketAddressFamily { get }
}

internal extension CSocketAddress {

@usableFromInline

func withUnsafePointer<Result>(
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32) throws -> Result
) rethrows -> Result {
Expand All @@ -25,7 +23,6 @@ internal extension CSocketAddress {
}
}

@usableFromInline
mutating func withUnsafeMutablePointer<Result>(
_ body: (UnsafeMutablePointer<CInterop.SocketAddress>, UInt32) throws -> Result
) rethrows -> Result {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Netlink/ProcessID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Sources/Netlink/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public final class NetlinkSocket {
// MARK: - Initialization

deinit {
let socket = self.socket
Task(priority: .high) {
await socket.close()
}
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions Sources/Netlink/SocketAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -33,27 +33,27 @@ public struct NetlinkSocketAddress: Equatable, Hashable, SocketAddress {
)
}

public func withUnsafePointer<Result>(
_ body: (UnsafePointer<CInterop.SocketAddress>, UInt32) throws -> Result
) rethrows -> Result {
public func withUnsafePointer<Result, Error>(
_ body: (UnsafePointer<CInterop.SocketAddress>, 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<CInterop.SocketAddress>
) -> Self {
return pointer.withMemoryRebound(to: CInterop.NetlinkSocketAddress.self, capacity: 1) { pointer in
return Self.init(pointer.pointee)
}
}

public static func withUnsafePointer(
_ body: (UnsafeMutablePointer<CInterop.SocketAddress>, UInt32) throws -> ()
_ body: (UnsafeMutablePointer<CInterop.SocketAddress>, CInterop.SocketLength) throws -> ()
) rethrows -> Self {
var socketAddress = CInterop.NetlinkSocketAddress()
try socketAddress.withUnsafeMutablePointer(body)
Expand Down
30 changes: 15 additions & 15 deletions Sources/Netlink/SocketOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result>(_ pointer: ((UnsafeRawBufferPointer) throws -> (Result))) rethrows -> Result {

public func withUnsafeBytes<Result, Error>(_ 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<Error>(_ 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<Result>(_ pointer: ((UnsafeRawBufferPointer) throws -> (Result))) rethrows -> Result {

public func withUnsafeBytes<Result, Error>(_ 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<Error>(_ 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)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Netlink/SocketProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Sources/NetlinkGeneric/GenericCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@_implementationOnly import CNetlink

public struct NetlinkGenericCommand: RawRepresentable, Equatable, Hashable {
public struct NetlinkGenericCommand: RawRepresentable, Equatable, Hashable, Sendable {

public let rawValue: UInt8

Expand Down
2 changes: 1 addition & 1 deletion Sources/NetlinkGeneric/GenericGroupName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Sources/NetlinkGeneric/GenericVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//

public struct NetlinkGenericVersion: RawRepresentable {
public struct NetlinkGenericVersion: RawRepresentable, Sendable {

public let rawValue: UInt8

Expand Down
Loading