Skip to content

Commit

Permalink
Fixes compilation of RxCocoa on Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
kzaher committed Oct 9, 2016
1 parent 77469a7 commit 5e9b1ff
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 40 deletions.
42 changes: 42 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PackageDescription

#if !os(Linux)
let package = Package(
name: "RxSwift",
targets: [
Expand Down Expand Up @@ -45,3 +46,44 @@ let package = Package(
"Tests"
]
)
#else
let package = Package(
name: "RxSwift",
targets: [
Target(
name: "RxSwift"
),
Target(
name: "RxBlocking",
dependencies: [
.Target(name: "RxSwift")
]
),
Target(
name: "RxCocoa",
dependencies: [
.Target(name: "RxSwift")
]
),
Target(
name: "RxTest",
dependencies: [
.Target(name: "RxSwift")
]
),
Target(
name: "AllTestz",
dependencies: [
.Target(name: "RxSwift"),
.Target(name: "RxBlocking"),
.Target(name: "RxTest"),
.Target(name: "RxCocoa")
]
)
],
exclude: [
"Tests",
"Sources/RxCocoaRuntime"
]
)
#endif
8 changes: 8 additions & 0 deletions RxCocoa/CocoaUnits/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,17 @@ public func driveOnScheduler(_ scheduler: SchedulerType, action: () -> ()) {
driverObserveOnScheduler = originalObserveOnScheduler
}

#if os(Linux)
import Glibc
#endif

func _forceCompilerToStopDoingInsaneOptimizationsThatBreakCode(_ scheduler: SchedulerType) {
let a: Int32 = 1
#if os(Linux)
let b = 314 + Int32(Glibc.random() & 1)
#else
let b = 314 + Int32(arc4random() & 1)
#endif
if a == b {
print(scheduler)
}
Expand Down
7 changes: 6 additions & 1 deletion RxCocoa/Common/DelegateProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if DELEGATE_PROXY_ON

import Foundation
#if !RX_NO_MODULE
import RxSwift
#if SWIFT_PACKAGE
#if SWIFT_PACKAGE && !os(Linux)
import RxCocoaRuntime
#endif
#endif
Expand Down Expand Up @@ -274,3 +276,6 @@ open class DelegateProxy : _RXDelegateProxy {
return p
}
}

#endif

4 changes: 4 additions & 0 deletions RxCocoa/Common/DelegateProxyType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if DELEGATE_PROXY_ON

import Foundation
#if !RX_NO_MODULE
import RxSwift
Expand Down Expand Up @@ -278,3 +280,5 @@ extension ObservableType {
return Disposables.create(subscription, disposable)
}
}

#endif
4 changes: 4 additions & 0 deletions RxCocoa/Common/NSLayoutConstraint+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if os(OSX)

import Foundation

#if os(OSX)
Expand Down Expand Up @@ -41,3 +43,5 @@ extension Reactive where Base: NSLayoutConstraint {
}

#endif

#endif
4 changes: 2 additions & 2 deletions RxCocoa/Common/RxCocoaObjCRuntimeError+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import Foundation
#if !RX_NO_MODULE
#if SWIFT_PACKAGE
#if SWIFT_PACKAGE && SWIZZLING_ON
import RxCocoaRuntime
#endif
#endif

#if !DISABLE_SWIZZLING
#if SWIZZLING_ON
/**
RxCocoa ObjC runtime interception mechanism.
*/
Expand Down
6 changes: 5 additions & 1 deletion RxCocoa/Foundation/KVORepresentable+CoreGraphics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if os(OSX)

import Foundation
#if !RX_NO_MODULE
import RxSwift
Expand Down Expand Up @@ -68,4 +70,6 @@ extension CGSize : KVORepresentable {
KVOValue.getValue(&typedValue)
self = typedValue
}
}
}

#endif
6 changes: 5 additions & 1 deletion RxCocoa/Foundation/NSObject+Rx+KVORepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if KVO_ON

import Foundation
#if !RX_NO_MODULE
import RxSwift
Expand All @@ -28,7 +30,7 @@ extension Reactive where Base: NSObject {
}
}

#if !DISABLE_SWIZZLING
#if SWIZZLING_ON
// KVO
extension Reactive where Base: NSObject {
/**
Expand All @@ -43,3 +45,5 @@ extension Reactive where Base: NSObject {
}
}
#endif

#endif
4 changes: 4 additions & 0 deletions RxCocoa/Foundation/NSObject+Rx+RawRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if KVO_ON

import Foundation
#if !RX_NO_MODULE
import RxSwift
Expand Down Expand Up @@ -49,3 +51,5 @@ extension Reactive where Base: NSObject {
}
}
#endif

#endif
24 changes: 18 additions & 6 deletions RxCocoa/Foundation/NSObject+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if !os(Linux)

import Foundation
#if !RX_NO_MODULE
import RxSwift
#if SWIFT_PACKAGE
#if SWIFT_PACKAGE && SWIZZLING_ON
import RxCocoaRuntime
#endif
#endif

#if !DISABLE_SWIZZLING
#if SWIZZLING_ON
var deallocatingSubjectTriggerContext: UInt8 = 0
var deallocatingSubjectContext: UInt8 = 0
#endif
var deallocatedSubjectTriggerContext: UInt8 = 0
var deallocatedSubjectContext: UInt8 = 0

#if KVO_ON

/**
KVO is a tricky mechanism.
Expand Down Expand Up @@ -67,7 +71,9 @@ extension Reactive where Base: NSObject {
}
}

#if !DISABLE_SWIZZLING
#endif

#if SWIZZLING_ON
// KVO
extension Reactive where Base: NSObject {
/**
Expand Down Expand Up @@ -117,7 +123,7 @@ extension Reactive where Base: AnyObject {
}
}

#if !DISABLE_SWIZZLING
#if SWIZZLING_ON

/**
Observable sequence of message arguments that completes when object is deallocated.
Expand Down Expand Up @@ -237,7 +243,7 @@ extension Reactive where Base: AnyObject {

// MARK: Message interceptors

#if !DISABLE_SWIZZLING
#if SWIZZLING_ON

fileprivate protocol MessageInterceptorSubject: class {
init()
Expand Down Expand Up @@ -322,6 +328,8 @@ fileprivate class DeallocObservable {

// MARK: KVO

#if KVO_ON

fileprivate protocol KVOObservableProtocol {
var target: AnyObject { get }
var keyPath: String { get }
Expand Down Expand Up @@ -393,7 +401,9 @@ fileprivate class KVOObservable<Element>

}

#if !DISABLE_SWIZZLING
#endif

#if SWIZZLING_ON

fileprivate func observeWeaklyKeyPathFor(_ target: NSObject, keyPath: String, options: NSKeyValueObservingOptions) -> Observable<AnyObject?> {
let components = keyPath.components(separatedBy: ".").filter { $0 != "self" }
Expand Down Expand Up @@ -520,3 +530,5 @@ extension Reactive where Base: AnyObject {
return observable
}
}

#endif
18 changes: 11 additions & 7 deletions RxCocoa/Foundation/NSURLSession+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func convertURLRequestToCurlCommand(_ request: URLRequest) -> String {
let method = request.httpMethod ?? "GET"
var returnValue = "curl -X \(method) "

if request.httpMethod == "POST" && request.httpBody != nil {
let maybeBody = NSString(data: request.httpBody!, encoding: String.Encoding.utf8.rawValue) as? String
if let httpBody = request.httpBody, request.httpMethod == "POST" {
let maybeBody = String(data: httpBody, encoding: String.Encoding.utf8)
if let body = maybeBody {
returnValue += "-d \"\(escapeTerminalString(body))\" "
}
Expand Down Expand Up @@ -123,11 +123,14 @@ extension Reactive where Base: URLSession {
return Observable.create { observer in

// smart compiler should be able to optimize this out
var d: Date?
let d: Date?

if Logging.URLRequests(request) {
d = Date()
}
else {
d = nil
}

let task = self.base.dataTask(with: request) { (data, response, error) in

Expand Down Expand Up @@ -204,10 +207,10 @@ extension Reactive where Base: URLSession {
- returns: Observable sequence of response JSON.
*/
// @warn_unused_result(message:"http://git.io/rxs.uo")
public func JSON(_ request: URLRequest) -> Observable<AnyObject> {
return data(request).map { (data) -> AnyObject in
public func JSON(_ request: URLRequest) -> Observable<Any> {
return data(request).map { (data) -> Any in
do {
return try JSONSerialization.jsonObject(with: data, options: []) as AnyObject
return try JSONSerialization.jsonObject(with: data, options: [])
} catch let error {
throw RxCocoaURLError.deserializationError(error: error)
}
Expand All @@ -232,7 +235,8 @@ extension Reactive where Base: URLSession {
- returns: Observable sequence of response JSON.
*/
// @warn_unused_result(message:"http://git.io/rxs.uo")
public func JSON(_ URL: Foundation.URL) -> Observable<AnyObject> {
public func JSON(_ URL: Foundation.URL) -> Observable<Any> {
return JSON(URLRequest(url: URL))
}
}

4 changes: 4 additions & 0 deletions RxCocoa/OSX/NSButton+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if os(OSX)

import Foundation
#if !RX_NO_MODULE
import RxSwift
Expand Down Expand Up @@ -35,3 +37,5 @@ extension Reactive where Base: NSButton {
)
}
}

#endif
4 changes: 4 additions & 0 deletions RxCocoa/OSX/NSControl+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if os(OSX)

import Foundation
import Cocoa
#if !RX_NO_MODULE
Expand Down Expand Up @@ -85,3 +87,5 @@ extension Reactive where Base: NSControl {
}.asObserver()
}
}

#endif
4 changes: 4 additions & 0 deletions RxCocoa/OSX/NSImageView+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if os(OSX)

import Foundation
#if !RX_NO_MODULE
import RxSwift
Expand Down Expand Up @@ -68,3 +70,5 @@ extension Reactive where Base: NSImageView {
}.asObserver()
}
}

#endif
4 changes: 4 additions & 0 deletions RxCocoa/OSX/NSSlider+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//

#if os(OSX)

import Foundation
#if !RX_NO_MODULE
import RxSwift
Expand All @@ -30,3 +32,5 @@ extension Reactive where Base: NSSlider {
}

}

#endif
Loading

0 comments on commit 5e9b1ff

Please sign in to comment.