Skip to content
Closed
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
12 changes: 10 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ jobs:
- name: Run Tests
run: CI=1 ./scripts/all-tests.sh "${{ matrix.environment }}"

linux:
name: "Test (Android)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "Test Swift Package on Android"
uses: skiptools/swift-android-action@v2

# We're having some issues with the Linux tests, so we're disabling them for now.
# Hopefully we'll be able to fix and re-enable them soon.
# Even more hopefully that I won't git blame this comment in the future and see it was 5 years ago :)
# Some more info on part of the breakage is here: https://forums.swift.org/t/swift-6-0-regression-cannot-inherit-from-some-foundation-classes-on-linux-because-it-has-overridable-members-that-could-not-be-loaded/74794

# linux:
# name: "Test (Linux)"
# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v3
# - name: Run tests
# run: CI=1 ./scripts/all-tests.sh "Unix"
# run: CI=1 ./scripts/all-tests.sh "Unix"

2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--ifdef no-indent
--wrap-arguments before-first
--exclude Sources/AllTestz/main.swift
--exclude Sources/AllTestz/main.swift,RxTest/HotObservable.swift,Tests/RxSwiftTests/BagTest.swift
66 changes: 54 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
// swift-tools-version:5.5

import Foundation
import PackageDescription

func isTargetingDarwin() -> Bool {
// Check if building for Android or other non-Darwin platforms
if (ProcessInfo.processInfo.environment["ANDROID_DATA"] != nil) ||
(ProcessInfo.processInfo.environment["ANDROID_ROOT"] != nil) {
return false
}

#if canImport(Darwin)
return true
#else
return false
#endif
}

let buildTests = false
let targetsDarwin = isTargetingDarwin()

extension Product {
static func allTests() -> [Product] {
Expand All @@ -12,6 +28,17 @@ extension Product {
[]
}
}

static func rxCocoaProducts() -> [Product] {
if targetsDarwin {
return [
.library(name: "RxCocoa", targets: ["RxCocoa"]),
.library(name: "RxCocoa-Dynamic", type: .dynamic, targets: ["RxCocoa"]),
]
} else {
return []
}
}
}

extension Target {
Expand All @@ -26,19 +53,35 @@ extension Target {

extension Target {
static func rxCocoa() -> [Target] {
#if os(Linux)
return [.rxTarget(name: "RxCocoa", dependencies: ["RxSwift", "RxRelay"])]
#else
return [.rxTarget(name: "RxCocoa", dependencies: ["RxSwift", "RxRelay", "RxCocoaRuntime"])]
#endif
if !targetsDarwin {
return []
} else {
return [
.target(
name: "RxCocoa",
dependencies: [
"RxSwift",
"RxRelay",
.target(name: "RxCocoaRuntime", condition: .when(platforms: [.iOS, .macOS, .tvOS, .watchOS]))
],
resources: [.copy("PrivacyInfo.xcprivacy")]
)
]
}
}

static func rxCocoaRuntime() -> [Target] {
#if os(Linux)
return []
#else
return [.rxTarget(name: "RxCocoaRuntime", dependencies: ["RxSwift"])]
#endif
if !targetsDarwin {
return []
} else {
return [
.target(
name: "RxCocoaRuntime",
dependencies: ["RxSwift"],
resources: [.copy("PrivacyInfo.xcprivacy")]
)
]
}
}

static func allTests() -> [Target] {
Expand All @@ -56,16 +99,15 @@ let package = Package(
products: ([
[
.library(name: "RxSwift", targets: ["RxSwift"]),
.library(name: "RxCocoa", targets: ["RxCocoa"]),
.library(name: "RxRelay", targets: ["RxRelay"]),
.library(name: "RxBlocking", targets: ["RxBlocking"]),
.library(name: "RxTest", targets: ["RxTest"]),
.library(name: "RxSwift-Dynamic", type: .dynamic, targets: ["RxSwift"]),
.library(name: "RxCocoa-Dynamic", type: .dynamic, targets: ["RxCocoa"]),
.library(name: "RxRelay-Dynamic", type: .dynamic, targets: ["RxRelay"]),
.library(name: "RxBlocking-Dynamic", type: .dynamic, targets: ["RxBlocking"]),
.library(name: "RxTest-Dynamic", type: .dynamic, targets: ["RxTest"]),
],
Product.rxCocoaProducts(),
Product.allTests(),
] as [[Product]]).flatMap(\.self),
targets: ([
Expand Down
66 changes: 54 additions & 12 deletions Package@swift-5.9.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
// swift-tools-version:5.9

import Foundation
import PackageDescription

func isTargetingDarwin() -> Bool {
// Check if building for Android or other non-Darwin platforms
if (ProcessInfo.processInfo.environment["ANDROID_DATA"] != nil) ||
(ProcessInfo.processInfo.environment["ANDROID_ROOT"] != nil) {
return false
}

#if canImport(Darwin)
return true
#else
return false
#endif
}

let buildTests = false
let targetsDarwin = isTargetingDarwin()

extension Product {
static func allTests() -> [Product] {
Expand All @@ -12,6 +28,17 @@ extension Product {
[]
}
}

static func rxCocoaProducts() -> [Product] {
if targetsDarwin {
return [
.library(name: "RxCocoa", targets: ["RxCocoa"]),
.library(name: "RxCocoa-Dynamic", type: .dynamic, targets: ["RxCocoa"]),
]
} else {
return []
}
}
}

extension Target {
Expand All @@ -26,19 +53,35 @@ extension Target {

extension Target {
static func rxCocoa() -> [Target] {
#if os(Linux)
return [.rxTarget(name: "RxCocoa", dependencies: ["RxSwift", "RxRelay"])]
#else
return [.rxTarget(name: "RxCocoa", dependencies: ["RxSwift", "RxRelay", "RxCocoaRuntime"])]
#endif
if !targetsDarwin {
return []
} else {
return [
.target(
name: "RxCocoa",
dependencies: [
"RxSwift",
"RxRelay",
.target(name: "RxCocoaRuntime", condition: .when(platforms: [.iOS, .macCatalyst, .macOS, .tvOS, .watchOS, .visionOS]))
],
resources: [.copy("PrivacyInfo.xcprivacy")]
)
]
}
}

static func rxCocoaRuntime() -> [Target] {
#if os(Linux)
return []
#else
return [.rxTarget(name: "RxCocoaRuntime", dependencies: ["RxSwift"])]
#endif
if !targetsDarwin {
return []
} else {
return [
.target(
name: "RxCocoaRuntime",
dependencies: ["RxSwift"],
resources: [.copy("PrivacyInfo.xcprivacy")]
)
]
}
}

static func allTests() -> [Target] {
Expand All @@ -56,16 +99,15 @@ let package = Package(
products: ([
[
.library(name: "RxSwift", targets: ["RxSwift"]),
.library(name: "RxCocoa", targets: ["RxCocoa"]),
.library(name: "RxRelay", targets: ["RxRelay"]),
.library(name: "RxBlocking", targets: ["RxBlocking"]),
.library(name: "RxTest", targets: ["RxTest"]),
.library(name: "RxSwift-Dynamic", type: .dynamic, targets: ["RxSwift"]),
.library(name: "RxCocoa-Dynamic", type: .dynamic, targets: ["RxCocoa"]),
.library(name: "RxRelay-Dynamic", type: .dynamic, targets: ["RxRelay"]),
.library(name: "RxBlocking-Dynamic", type: .dynamic, targets: ["RxBlocking"]),
.library(name: "RxTest-Dynamic", type: .dynamic, targets: ["RxTest"]),
],
Product.rxCocoaProducts(),
Product.allTests(),
] as [[Product]]).flatMap(\.self),
targets: ([
Expand Down
2 changes: 1 addition & 1 deletion Platform/Platform.Darwin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
#if canImport(Darwin)
import Darwin
import Foundation

Expand Down
2 changes: 1 addition & 1 deletion Platform/Platform.Linux.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if os(Linux)
#if !canImport(Darwin)

import Foundation

Expand Down
4 changes: 2 additions & 2 deletions RxBlocking/RunLoopLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CoreFoundation
import Foundation
import RxSwift

#if os(Linux)
#if !canImport(Darwin)
import Foundation

let runLoopMode: RunLoop.Mode = .default
Expand Down Expand Up @@ -61,7 +61,7 @@ final class RunLoopLock {
fatalError("Run can be only called once")
}
if let timeout {
#if os(Linux)
#if !canImport(Darwin)
let runLoopResult = CFRunLoopRunInMode(runLoopModeRaw, timeout, false)
#else
let runLoopResult = CFRunLoopRunInMode(runLoopMode, timeout, false)
Expand Down
2 changes: 1 addition & 1 deletion RxCocoa/Foundation/URLSession+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public extension Reactive where Base: URLSession {
if URLSession.rx.shouldLogRequest(request) {
let interval = Date().timeIntervalSince(d ?? Date())
print(convertURLRequestToCurlCommand(request))
#if os(Linux)
#if !canImport(Darwin)
print(convertResponseToString(response, error.flatMap { $0 as NSError }, interval))
#else
print(convertResponseToString(response, error.map { $0 as NSError }, interval))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public enum SharingScheduler {
}
}

#if os(Linux)
#if !canImport(Darwin)
import Glibc
#else
import Foundation
#endif

func _forceCompilerToStopDoingInsaneOptimizationsThatBreakCode(_ scheduler: () -> SchedulerType) {
let a: Int32 = 1
#if os(Linux)
#if !canImport(Darwin)
let b = 314 + Int32(Glibc.random() & 1)
#else
let b = 314 + Int32(arc4random() & 1)
Expand Down
4 changes: 2 additions & 2 deletions RxSwift/RxMutableBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if os(Linux)
#if !canImport(Darwin)
/// As Swift 5 was released, A patch to `Thread` for Linux
/// changed `threadDictionary` to a `NSMutableDictionary` instead of
/// a `Dictionary<String, Any>`: https://github.com/apple/swift-corelibs-foundation/pull/1762/files
///
/// This means that on Linux specifically, `RxMutableBox` must be a `NSObject`
/// This means that on non-Darwin platforms (Linux, Android, etc.), `RxMutableBox` must be a `NSObject`
/// or it won't be possible to store it in `Thread.threadDictionary`.
///
/// For more information, read the discussion at:
Expand Down
2 changes: 1 addition & 1 deletion RxSwift/Schedulers/CurrentThreadScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Dispatch
import Foundation

#if os(Linux)
#if !canImport(Darwin)
fileprivate enum CurrentThreadSchedulerQueueKey {
fileprivate static let instance = "RxSwift.CurrentThreadScheduler.Queue"
}
Expand Down
6 changes: 3 additions & 3 deletions RxTest/Event+Equatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
///
/// In case `Error` events are being compared, they are equal in case their `NSError` representations are equal (domain and code)
/// and their string representations are equal.
extension CompletableEvent: @retroactive Equatable {
extension CompletableEvent: Equatable {

Check warning on line 91 in RxTest/Event+Equatable.swift

View workflow job for this annotation

GitHub Actions / Xcode 26 (Unix)

extension declares a conformance of imported type 'CompletableEvent' to imported protocol 'Equatable'; this will not behave correctly if the owners of 'RxSwift' introduce this conformance in the future
public static func == (lhs: CompletableEvent, rhs: CompletableEvent) -> Bool {
switch (lhs, rhs) {
case (.completed, .completed): return true
Expand All @@ -108,13 +108,13 @@
}
}

extension Event: @retroactive Equatable where Element: Equatable {
extension Event: Equatable where Element: Equatable {
public static func == (lhs: Event<Element>, rhs: Event<Element>) -> Bool {
equals(lhs: lhs, rhs: rhs)
}
}

extension MaybeEvent: @retroactive Equatable where Element: Equatable {
extension MaybeEvent: Equatable where Element: Equatable {
public static func == (lhs: MaybeEvent<Element>, rhs: MaybeEvent<Element>) -> Bool {
equals(lhs: lhs, rhs: rhs)
}
Expand Down
Loading