Skip to content

Commit 7b5ede4

Browse files
authored
Merge pull request #50 from lhoward/lhoward/linux
Fixes for building `OSCKitCore` on Linux
2 parents 24e9951 + 56ac435 commit 7b5ede4

8 files changed

Lines changed: 89 additions & 27 deletions

File tree

.github/workflows/build.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171

7272
iOS:
7373
name: iOS
74-
runs-on: macos-lates
74+
runs-on: macos-latest
7575
steps:
7676
- uses: actions/checkout@main
7777
- uses: maxim-lobanov/setup-xcode@v1
@@ -107,7 +107,7 @@ jobs:
107107

108108
tvOS:
109109
name: tvOS
110-
runs-on: macos-lates
110+
runs-on: macos-latest
111111
steps:
112112
- uses: actions/checkout@main
113113
- uses: maxim-lobanov/setup-xcode@v1
@@ -143,7 +143,7 @@ jobs:
143143

144144
watchOS:
145145
name: watchOS
146-
runs-on: macos-lates
146+
runs-on: macos-latest
147147
steps:
148148
- uses: actions/checkout@main
149149
- uses: maxim-lobanov/setup-xcode@v1
@@ -215,3 +215,13 @@ jobs:
215215
run: xcodebuild -project "Examples/UDP Socket/OSC UDP Socket.xcodeproj" -resolvePackageDependencies | xcbeautify --renderer github-actions && exit ${PIPESTATUS[0]}
216216
- name: UDP Socket - Build
217217
run: xcodebuild build -project "Examples/UDP Socket/OSC UDP Socket.xcodeproj" -scheme "OSC UDP Socket" -destination "generic/platform=macOS,name=Any Mac" | xcbeautify --renderer github-actions && exit ${PIPESTATUS[0]}
218+
219+
linux:
220+
name: Linux (OSCKitCore)
221+
runs-on: ubuntu-latest
222+
steps:
223+
- uses: actions/checkout@main
224+
- name: Build
225+
run: swift build
226+
- name: Unit Tests
227+
run: swift test

Package.swift

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,48 @@ import PackageDescription
66
let package = Package(
77
name: "OSCKit",
88
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13)],
9-
products: [
10-
.library(
11-
name: "OSCKit",
12-
targets: ["OSCKit"]
13-
),
14-
.library(
15-
name: "OSCKitCore",
16-
targets: ["OSCKitCore"]
17-
)
18-
],
19-
dependencies: [
20-
.package(url: "https://github.com/robbiehanson/CocoaAsyncSocket", from: "7.0.0"),
21-
.package(url: "https://github.com/orchetect/SwiftASCII", from: "1.1.5"),
9+
products: products,
10+
dependencies: dependencies,
11+
targets: targets
12+
)
13+
14+
var products: [Product] {
15+
var products: [Product] = []
16+
17+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
18+
products += [
19+
.library(name: "OSCKit", targets: ["OSCKit"])
20+
]
21+
#endif
22+
23+
products += [
24+
.library(name: "OSCKitCore", targets: ["OSCKitCore"])
25+
]
26+
return products
27+
}
28+
29+
var dependencies: [Package.Dependency] {
30+
var dependencies: [Package.Dependency] = []
31+
32+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
33+
dependencies += [
34+
.package(url: "https://github.com/robbiehanson/CocoaAsyncSocket", from: "7.0.0")
35+
]
36+
#endif
37+
38+
dependencies += [
39+
.package(url: "https://github.com/orchetect/SwiftASCII", from: "1.2.0"),
2240
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2")
23-
],
24-
targets: [
41+
]
42+
43+
return dependencies
44+
}
45+
46+
var targets: [Target] {
47+
var targets: [Target] = []
48+
49+
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
50+
targets += [
2551
.target(
2652
name: "OSCKit",
2753
dependencies: [
@@ -34,15 +60,19 @@ let package = Package(
3460
],
3561
swiftSettings: [.define("DEBUG", .when(configuration: .debug))]
3662
),
63+
.testTarget(
64+
name: "OSCKitTests",
65+
dependencies: ["OSCKit"]
66+
)
67+
]
68+
#endif
69+
70+
targets += [
3771
.target(
3872
name: "OSCKitCore",
3973
dependencies: ["SwiftASCII"],
4074
swiftSettings: [.define("DEBUG", .when(configuration: .debug))]
4175
),
42-
.testTarget(
43-
name: "OSCKitTests",
44-
dependencies: ["OSCKit"]
45-
),
4676
.testTarget(
4777
name: "OSCKitCoreTests",
4878
dependencies: [
@@ -51,4 +81,6 @@ let package = Package(
5181
]
5282
)
5383
]
54-
)
84+
85+
return targets
86+
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Forchetect%2FOSCKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/orchetect/OSCKit) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Forchetect%2FOSCKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/orchetect/OSCKit) [![Xcode 16](https://img.shields.io/badge/Xcode-16-blue.svg?style=flat)](https://developer.apple.com/swift) [![License: MIT](http://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/orchetect/OSCKit/blob/main/LICENSE)
66

7-
Open Sound Control ([OSC](https://opensoundcontrol.stanford.edu)) library for macOS, iOS, tvOS, and visionOS written in Swift.
7+
Open Sound Control ([OSC](https://opensoundcontrol.stanford.edu)) library written in Swift.
8+
9+
The core library is compatible with Apple platforms and Linux. The network layer is currently built for only Apple platforms.
810

911
- OSC address pattern matching and dispatch
1012
- Convenient OSC message value type masking, validation and strong-typing

Sources/OSCKitCore/Utilities/Outsourced/Data.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/// ----------------------------------------------
1010
/// ----------------------------------------------
1111

12+
import CoreFoundation
1213
import Foundation
1314

1415
// MARK: - Int

Sources/OSCKitCore/Utilities/Outsourced/FloatingPoint and Darwin.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
/// ----------------------------------------------
1010
/// ----------------------------------------------
1111

12+
#if canImport(Darwin)
1213
import Darwin
14+
#elseif canImport(Glibc)
15+
import Glibc
16+
#endif
1317

1418
extension FloatingPoint {
1519
/// Similar to `Int.quotientAndRemainder(dividingBy:)` from the standard Swift library.

Tests/OSCKitCoreTests/OSCTimeTag/OSCTimeTag Static Constructors Tests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Testing
1515
#elseif os(tvOS) || os(watchOS)
1616
// allow more time variance for CI pipeline to de-flake
1717
let tolerance: TimeInterval = 0.01
18+
#else // linux
19+
let tolerance: TimeInterval = 0.01
1820
#endif
1921

2022
// MARK: - Static Constructors

Tests/OSCKitCoreTests/OSCTimeTag/OSCTimeTag Tests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import Testing
1414
let tolerance: TimeInterval = 0.001
1515
#elseif targetEnvironment(macCatalyst) || os(iOS) || os(tvOS) || os(watchOS)
1616
let tolerance: TimeInterval = 0.01
17+
#else // linux
18+
let tolerance: TimeInterval = 0.05
1719
#endif
1820

1921
@Test
@@ -204,9 +206,10 @@ import Testing
204206

205207
@Test
206208
func now_date() {
209+
let date = Date()
207210
let tag = OSCTimeTag.now()
208211
let captureDate = tag.date
209-
#expect(Date().timeIntervalSince(captureDate).isApproximatelyEqual(to: 0.0, absoluteTolerance: tolerance))
212+
#expect(date.timeIntervalSince(captureDate).isApproximatelyEqual(to: 0.0, absoluteTolerance: tolerance))
210213
}
211214

212215
@Test

Tests/OSCKitCoreTests/Test Utilities.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,26 @@
44
// © 2020-2025 Steffan Andrews • Licensed under MIT License
55
//
66

7+
import CoreFoundation
78
import Foundation
89
import Testing
910

11+
#if canImport(Darwin)
12+
import Darwin
13+
#elseif canImport(Glibc)
14+
import Glibc
15+
private let USEC_PER_SEC = 1_000_000
16+
#endif
17+
1018
/// Use as a condition for individual tests that rely on stable/precise system timing.
1119
func isSystemTimingStable(
1220
duration: TimeInterval = 0.1,
1321
tolerance: TimeInterval = 0.01
1422
) -> Bool {
15-
let durationMS = UInt32(duration * TimeInterval(USEC_PER_SEC))
23+
let durationUS = UInt32(duration * TimeInterval(USEC_PER_SEC))
1624

1725
let start = Date()
18-
usleep(durationMS)
26+
usleep(durationUS)
1927
let end = Date()
2028
let diff = end.timeIntervalSince(start)
2129

0 commit comments

Comments
 (0)