Skip to content

Commit c75118f

Browse files
authored
Support Linux (#10)
1 parent 742fc72 commit c75118f

37 files changed

Lines changed: 1074 additions & 1037 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,13 @@ jobs:
3030
run: CONFIG=${{ matrix.config }} make build-all-platforms
3131
- name: Build for library evolution
3232
run: make build-for-library-evolution
33+
34+
ubuntu-tests:
35+
strategy:
36+
matrix:
37+
os: [ubuntu-18.04, ubuntu-20.04]
38+
runs-on: ${{ matrix.os }}
39+
steps:
40+
- uses: actions/checkout@v3
41+
- name: Run tests
42+
run: make test-swift

DependenciesAdditions.xcworkspace/xcshareddata/xcschemes/_NotificationDependency.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
3030
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "_NotificationDependencyTests"
36+
BuildableName = "_NotificationDependencyTests"
37+
BlueprintName = "_NotificationDependencyTests"
38+
ReferencedContainer = "container:">
39+
</BuildableReference>
40+
</TestableReference>
3141
</Testables>
3242
</TestAction>
3343
<LaunchAction

Sources/CompressionDependency/Compressor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if canImport(Compression)
12
import Compression
23
import Dependencies
34
import Foundation
@@ -58,3 +59,4 @@ public struct Compressor: Sendable {
5859
try await self.compressAsync(data, algorithm())
5960
}
6061
}
62+
#endif

Sources/CompressionDependency/Decompressor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if canImport(Compression)
12
import Compression
23
import Dependencies
34
import Foundation
@@ -62,3 +63,4 @@ public struct Decompressor: Sendable {
6263
try await self.decompressAsync(data, algorithm())
6364
}
6465
}
66+
#endif

Sources/CompressionDependency/Internal/_Compression.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if canImport(Compression)
12
import Compression
23
import Dependencies
34
import Foundation
@@ -64,3 +65,4 @@ func defaultAsync(_ operation: FilterOperation) -> @Sendable (
6465
return processed
6566
}
6667
}
68+
#endif

Sources/DependenciesAdditionsBasics/ConcurrencySupport/BroadcastableAsyncSequence.swift

Lines changed: 83 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1-
@preconcurrency import Combine
21
import Dependencies
32
import Foundation
43

4+
#if canImport(Combine)
5+
@preconcurrency import Combine
6+
#endif
7+
58
public protocol BroadcastableAsyncSequence: AsyncSequence {}
69

7-
extension BroadcastableAsyncSequence {
8-
@_spi(Internals) public func publisher() -> AnyPublisher<Element, Never>
9-
where Self: Sendable, Self.Element: Sendable {
10-
let subject = CurrentValueSubject<Element?, Never>(.none)
10+
#if canImport(Combine)
11+
extension BroadcastableAsyncSequence {
12+
@_spi(Internals) public func publisher() -> AnyPublisher<Element, Never>
13+
where Self: Sendable, Self.Element: Sendable {
14+
let subject = CurrentValueSubject<Element?, Never>(.none)
1115

12-
let task = Task { @MainActor in
13-
do {
14-
for try await element in self {
15-
subject.send(element)
16+
let task = Task { @MainActor in
17+
do {
18+
for try await element in self {
19+
subject.send(element)
20+
}
21+
} catch {
22+
subject.send(completion: .finished)
1623
}
17-
} catch {
18-
subject.send(completion: .finished)
1924
}
20-
}
2125

22-
return subject.handleEvents(
23-
receiveCancel: {
24-
task.cancel()
25-
})
26-
.compactMap { $0 }
27-
.eraseToAnyPublisher()
26+
return subject.handleEvents(
27+
receiveCancel: {
28+
task.cancel()
29+
})
30+
.compactMap { $0 }
31+
.eraseToAnyPublisher()
32+
}
2833
}
29-
}
34+
#endif
3035

3136
extension BroadcastableAsyncSequence where Self: Sendable {
3237
public func forEach(
@@ -42,68 +47,69 @@ extension BroadcastableAsyncSequence where Self: Sendable {
4247
}.eraseToAnyCancellableTask()
4348
}
4449
}
50+
#if canImport(Combine)
51+
extension BroadcastableAsyncSequence where Self: Sendable, Self.Element: Sendable {
52+
/// Assigns each element from an async sequence to a property on an object.
53+
/// - Parameters:
54+
/// - keyPath: A key path that indicates the property to assign.
55+
/// - object: The object that contains the property. The subscriber assigns the object’s
56+
/// property every time it receives a new value.
57+
/// - Returns: An AnyCancellable instance. Call cancel() on this instance when you no longer want
58+
/// the publisher to automatically assign the property. Deinitializing this instance will also
59+
/// cancel automatic assignment.
60+
@_disfavoredOverload
61+
public func assign<Root>(to keyPath: ReferenceWritableKeyPath<Root, Element>, on object: Root)
62+
-> AnyCancellable
63+
{
64+
self.publisher().assign(to: keyPath, on: object)
65+
}
4566

46-
extension BroadcastableAsyncSequence where Self: Sendable, Self.Element: Sendable {
47-
/// Assigns each element from an async sequence to a property on an object.
48-
/// - Parameters:
49-
/// - keyPath: A key path that indicates the property to assign.
50-
/// - object: The object that contains the property. The subscriber assigns the object’s
51-
/// property every time it receives a new value.
52-
/// - Returns: An AnyCancellable instance. Call cancel() on this instance when you no longer want
53-
/// the publisher to automatically assign the property. Deinitializing this instance will also
54-
/// cancel automatic assignment.
55-
@_disfavoredOverload
56-
public func assign<Root>(to keyPath: ReferenceWritableKeyPath<Root, Element>, on object: Root)
57-
-> AnyCancellable
58-
{
59-
self.publisher().assign(to: keyPath, on: object)
60-
}
61-
62-
/// Assigns each element from an async sequence to a property on an object.
63-
///
64-
/// The assign(to:) operator manages the life cycle of the subscription, canceling the
65-
/// subscription automatically when the Published instance deinitializes. Because of this, the
66-
/// ``NotificationStream/assign(to:)-5dfsw`` operator doesn’t return an `AnyCancellable` that
67-
/// you’re responsible for like ``NotificationStream/assign(to:on:)-rllq`` does.
68-
///
69-
/// - Parameter published: A property marked with the @Published attribute, which receives and
70-
/// republishes all elements received from the upstream publisher.
71-
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
72-
@_disfavoredOverload
73-
public func assign(to published: inout Published<Element>.Publisher) {
74-
self.publisher().assign(to: &published)
75-
}
67+
/// Assigns each element from an async sequence to a property on an object.
68+
///
69+
/// The assign(to:) operator manages the life cycle of the subscription, canceling the
70+
/// subscription automatically when the Published instance deinitializes. Because of this, the
71+
/// ``NotificationStream/assign(to:)-5dfsw`` operator doesn’t return an `AnyCancellable` that
72+
/// you’re responsible for like ``NotificationStream/assign(to:on:)-rllq`` does.
73+
///
74+
/// - Parameter published: A property marked with the @Published attribute, which receives and
75+
/// republishes all elements received from the upstream publisher.
76+
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
77+
@_disfavoredOverload
78+
public func assign(to published: inout Published<Element>.Publisher) {
79+
self.publisher().assign(to: &published)
80+
}
7681

77-
/// Assigns each element from an async sequence to a property on an object.
78-
/// - Parameters:
79-
/// - keyPath: A key path that indicates the property to assign.
80-
/// - object: The object that contains the property. The subscriber assigns the object’s
81-
/// property every time it receives a new value.
82-
/// - Returns: An AnyCancellable instance. Call cancel() on this instance when you no longer want
83-
/// the publisher to automatically assign the property. Deinitializing this instance will also
84-
/// cancel automatic assignment.
85-
@_disfavoredOverload
86-
public func assign<Root>(to keyPath: ReferenceWritableKeyPath<Root, Element?>, on object: Root)
87-
-> AnyCancellable
88-
{
89-
self.publisher().map(Optional.some).assign(to: keyPath, on: object)
90-
}
82+
/// Assigns each element from an async sequence to a property on an object.
83+
/// - Parameters:
84+
/// - keyPath: A key path that indicates the property to assign.
85+
/// - object: The object that contains the property. The subscriber assigns the object’s
86+
/// property every time it receives a new value.
87+
/// - Returns: An AnyCancellable instance. Call cancel() on this instance when you no longer want
88+
/// the publisher to automatically assign the property. Deinitializing this instance will also
89+
/// cancel automatic assignment.
90+
@_disfavoredOverload
91+
public func assign<Root>(to keyPath: ReferenceWritableKeyPath<Root, Element?>, on object: Root)
92+
-> AnyCancellable
93+
{
94+
self.publisher().map(Optional.some).assign(to: keyPath, on: object)
95+
}
9196

92-
/// Assigns each element from an async sequence to a property on an object.
93-
///
94-
/// The assign(to:) operator manages the life cycle of the subscription, canceling the
95-
/// subscription automatically when the Published instance deinitializes. Because of this, the
96-
/// ``NotificationStream/assign(to:)-3sgyd`` operator doesn’t return an `AnyCancellable` that
97-
/// you’re responsible for like ``NotificationStream/assign(to:on:)-fj51`` does.
98-
///
99-
/// - Parameter published: A property marked with the @Published attribute, which receives and
100-
/// republishes all elements received from the upstream publisher.
101-
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
102-
@_disfavoredOverload
103-
public func assign(to published: inout Published<Element?>.Publisher) {
104-
self.publisher().map(Optional.some).assign(to: &published)
97+
/// Assigns each element from an async sequence to a property on an object.
98+
///
99+
/// The assign(to:) operator manages the life cycle of the subscription, canceling the
100+
/// subscription automatically when the Published instance deinitializes. Because of this, the
101+
/// ``NotificationStream/assign(to:)-3sgyd`` operator doesn’t return an `AnyCancellable` that
102+
/// you’re responsible for like ``NotificationStream/assign(to:on:)-fj51`` does.
103+
///
104+
/// - Parameter published: A property marked with the @Published attribute, which receives and
105+
/// republishes all elements received from the upstream publisher.
106+
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
107+
@_disfavoredOverload
108+
public func assign(to published: inout Published<Element?>.Publisher) {
109+
self.publisher().map(Optional.some).assign(to: &published)
110+
}
105111
}
106-
}
112+
#endif
107113

108114
extension AsyncMapSequence: BroadcastableAsyncSequence
109115
where Base: BroadcastableAsyncSequence {}

Sources/DependenciesAdditionsBasics/Proxies.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,7 @@ public struct AnyProxyBindable<Value: Sendable>: ProxyBindable {
455455
public var setValue: @Sendable (Value) -> Void
456456
}
457457

458-
public protocol _Sendable: Sendable {}
459-
extension LockIsolated: ProxyBindable where Value: _Sendable {
458+
extension LockIsolated: ProxyBindable {
460459
public var getValue: @Sendable () -> Value {
461460
{ self.value }
462461
}

Sources/DependenciesAdditionsBasics/RandomNumberGenerator/SecureRandomNumberGenerator.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if canImport(Security)
12
import Dependencies
23
import Security
34

@@ -27,3 +28,4 @@ public struct SecureRandomNumberGenerator: RandomNumberGenerator, Sendable {
2728
return result
2829
}
2930
}
31+
#endif

Sources/DependenciesAdditionsBasics/TestSupport/WithTimeout.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Foundation
22
import XCTestDynamicOverlay
3+
#if os(Linux)
4+
public let NSEC_PER_MSEC: UInt64 = 1_000_000
5+
#endif
36

47
/// Performs an async operation that fails if it hasn't finished before a timeout expires.
58
///

Sources/DeviceDependency/DeviceCheckDependency.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if canImport(DeviceCheck)
12
import Dependencies
23
@_spi(Internals) import DependenciesAdditionsBasics
34
import DeviceCheck
@@ -73,3 +74,4 @@ extension DeviceCheckDevice {
7374
)
7475
}
7576
}
77+
#endif

0 commit comments

Comments
 (0)