From d68f9d1f8ed3a8fa618bf356ba4d231efc8cc2a2 Mon Sep 17 00:00:00 2001 From: Johannes Weiss Date: Mon, 25 Mar 2019 14:49:35 +0000 Subject: [PATCH] make NIOTS compile on Linux (#29) Motivation: NIOTS will not work on Linux but we can at least make it not fail compilation when compiled on Linux. That way consumers of the API can depend on NIOTS but make sure they only use NIOTS when wrapped in a `#if canImport(Network)` block. Modification: Guard everything by `#if canImport(Network)` Result: This package will now build on Linux (without providing any useful code). --- Sources/NIOTSHTTPClient/main.swift | 3 +++ Sources/NIOTSHTTPServer/main.swift | 3 +++ Sources/NIOTransportServices/NIOTSConnectionBootstrap.swift | 4 +++- Sources/NIOTransportServices/NIOTSConnectionChannel.swift | 3 +++ Sources/NIOTransportServices/NIOTSEventLoop.swift | 2 ++ Sources/NIOTransportServices/NIOTSEventLoopGroup.swift | 3 +++ Sources/NIOTransportServices/NIOTSListenerBootstrap.swift | 3 +++ Sources/NIOTransportServices/NIOTSListenerChannel.swift | 3 +++ Sources/NIOTransportServices/NIOTSNetworkEvents.swift | 3 +++ Sources/NIOTransportServices/SocketAddress+NWEndpoint.swift | 3 +++ Sources/NIOTransportServices/StateManagedChannel.swift | 3 +++ .../NIOTransportServices/TCPOptions+SocketChannelOption.swift | 3 +++ .../NIOTSConnectionChannelTests.swift | 3 +++ Tests/NIOTransportServicesTests/NIOTSEndToEndTests.swift | 3 +++ Tests/NIOTransportServicesTests/NIOTSEventLoopTests.swift | 3 +++ .../NIOTransportServicesTests/NIOTSListenerChannelTests.swift | 3 +++ Tests/NIOTransportServicesTests/NIOTSSocketOptionTests.swift | 3 +++ .../NIOTSSocketOptionsOnChannelTests.swift | 4 +++- 18 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Sources/NIOTSHTTPClient/main.swift b/Sources/NIOTSHTTPClient/main.swift index 925dbd0..ad85abc 100644 --- a/Sources/NIOTSHTTPClient/main.swift +++ b/Sources/NIOTSHTTPClient/main.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import NIO import NIOTransportServices import NIOHTTP1 @@ -69,3 +71,4 @@ let channel = try! NIOTSConnectionBootstrap(group: group) // Wait for the request to complete try! channel.closeFuture.wait() +#endif diff --git a/Sources/NIOTSHTTPServer/main.swift b/Sources/NIOTSHTTPServer/main.swift index 8f4704f..df62ba9 100644 --- a/Sources/NIOTSHTTPServer/main.swift +++ b/Sources/NIOTSHTTPServer/main.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import NIO import NIOTransportServices import NIOHTTP1 @@ -48,3 +50,4 @@ print("Server listening on \(channel.localAddress!)") // Wait for the request to complete try! channel.closeFuture.wait() +#endif diff --git a/Sources/NIOTransportServices/NIOTSConnectionBootstrap.swift b/Sources/NIOTransportServices/NIOTSConnectionBootstrap.swift index d80a070..d438be8 100644 --- a/Sources/NIOTransportServices/NIOTSConnectionBootstrap.swift +++ b/Sources/NIOTransportServices/NIOTSConnectionBootstrap.swift @@ -13,11 +13,12 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import NIO import Dispatch import Network - public final class NIOTSConnectionBootstrap { private let group: NIOTSEventLoopGroup private var channelInitializer: ((Channel) -> EventLoopFuture)? @@ -219,3 +220,4 @@ internal struct ChannelOptionStorage { return applyPromise.futureResult } } +#endif diff --git a/Sources/NIOTransportServices/NIOTSConnectionChannel.swift b/Sources/NIOTransportServices/NIOTSConnectionChannel.swift index da15730..3669630 100644 --- a/Sources/NIOTransportServices/NIOTSConnectionChannel.swift +++ b/Sources/NIOTransportServices/NIOTSConnectionChannel.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import Foundation import NIO import NIOConcurrencyHelpers @@ -807,3 +809,4 @@ fileprivate extension ChannelState where ActiveSubstate == NIOTSConnectionChanne } } } +#endif diff --git a/Sources/NIOTransportServices/NIOTSEventLoop.swift b/Sources/NIOTransportServices/NIOTSEventLoop.swift index e3cdee5..eed1a9e 100644 --- a/Sources/NIOTransportServices/NIOTSEventLoop.swift +++ b/Sources/NIOTransportServices/NIOTSEventLoop.swift @@ -14,6 +14,7 @@ // //===----------------------------------------------------------------------===// +#if canImport(Network) import Dispatch import Foundation import Network @@ -220,3 +221,4 @@ extension NIOTSEventLoop { assert(oldChannel != nil) } } +#endif diff --git a/Sources/NIOTransportServices/NIOTSEventLoopGroup.swift b/Sources/NIOTransportServices/NIOTSEventLoopGroup.swift index db63e79..1d48a4e 100644 --- a/Sources/NIOTransportServices/NIOTSEventLoopGroup.swift +++ b/Sources/NIOTransportServices/NIOTSEventLoopGroup.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import Foundation import NIO import NIOConcurrencyHelpers @@ -82,3 +84,4 @@ public final class NIOTSEventLoopGroup: EventLoopGroup { return EventLoopIterator(self.eventLoops) } } +#endif diff --git a/Sources/NIOTransportServices/NIOTSListenerBootstrap.swift b/Sources/NIOTransportServices/NIOTSListenerBootstrap.swift index e99f432..14c15ea 100644 --- a/Sources/NIOTransportServices/NIOTSListenerBootstrap.swift +++ b/Sources/NIOTransportServices/NIOTSListenerBootstrap.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import NIO import Dispatch import Network @@ -308,3 +310,4 @@ private class AcceptHandler: ChannelInboundHandler { } } } +#endif diff --git a/Sources/NIOTransportServices/NIOTSListenerChannel.swift b/Sources/NIOTransportServices/NIOTSListenerChannel.swift index 0b5848c..04fa65c 100644 --- a/Sources/NIOTransportServices/NIOTSListenerChannel.swift +++ b/Sources/NIOTransportServices/NIOTSListenerChannel.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import Foundation import NIO import NIOFoundationCompat @@ -421,3 +423,4 @@ extension NIOTSListenerChannel { self.becomeActive0(promise: promise) } } +#endif diff --git a/Sources/NIOTransportServices/NIOTSNetworkEvents.swift b/Sources/NIOTransportServices/NIOTSNetworkEvents.swift index 5afccf1..90b4443 100644 --- a/Sources/NIOTransportServices/NIOTSNetworkEvents.swift +++ b/Sources/NIOTransportServices/NIOTSNetworkEvents.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import Network import NIO @@ -66,3 +68,4 @@ public enum NIOTSNetworkEvents { public let endpoint: NWEndpoint } } +#endif diff --git a/Sources/NIOTransportServices/SocketAddress+NWEndpoint.swift b/Sources/NIOTransportServices/SocketAddress+NWEndpoint.swift index 6420089..8b87de3 100644 --- a/Sources/NIOTransportServices/SocketAddress+NWEndpoint.swift +++ b/Sources/NIOTransportServices/SocketAddress+NWEndpoint.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import Darwin import Foundation import NIO @@ -121,3 +123,4 @@ internal extension SocketAddress { } } } +#endif diff --git a/Sources/NIOTransportServices/StateManagedChannel.swift b/Sources/NIOTransportServices/StateManagedChannel.swift index c2cee9c..e5a7cd3 100644 --- a/Sources/NIOTransportServices/StateManagedChannel.swift +++ b/Sources/NIOTransportServices/StateManagedChannel.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import Foundation import NIO import NIOFoundationCompat @@ -266,3 +268,4 @@ extension StateManagedChannel { self.beginActivating0(to: endpoint, promise: promise) } } +#endif diff --git a/Sources/NIOTransportServices/TCPOptions+SocketChannelOption.swift b/Sources/NIOTransportServices/TCPOptions+SocketChannelOption.swift index 023c9e7..db71e82 100644 --- a/Sources/NIOTransportServices/TCPOptions+SocketChannelOption.swift +++ b/Sources/NIOTransportServices/TCPOptions+SocketChannelOption.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import Foundation import NIO import Network @@ -82,3 +84,4 @@ internal extension NWProtocolTCP.Options { } } } +#endif diff --git a/Tests/NIOTransportServicesTests/NIOTSConnectionChannelTests.swift b/Tests/NIOTransportServicesTests/NIOTSConnectionChannelTests.swift index c40bfe6..e7a9d43 100644 --- a/Tests/NIOTransportServicesTests/NIOTSConnectionChannelTests.swift +++ b/Tests/NIOTransportServicesTests/NIOTSConnectionChannelTests.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import XCTest import Network import NIO @@ -638,3 +640,4 @@ class NIOTSConnectionChannelTests: XCTestCase { } } } +#endif diff --git a/Tests/NIOTransportServicesTests/NIOTSEndToEndTests.swift b/Tests/NIOTransportServicesTests/NIOTSEndToEndTests.swift index cea4f4e..f857293 100644 --- a/Tests/NIOTransportServicesTests/NIOTSEndToEndTests.swift +++ b/Tests/NIOTransportServicesTests/NIOTSEndToEndTests.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import XCTest import NIO import NIOTransportServices @@ -491,3 +493,4 @@ class NIOTSEndToEndTests: XCTestCase { } } } +#endif diff --git a/Tests/NIOTransportServicesTests/NIOTSEventLoopTests.swift b/Tests/NIOTransportServicesTests/NIOTSEventLoopTests.swift index a127c28..c490873 100644 --- a/Tests/NIOTransportServicesTests/NIOTSEventLoopTests.swift +++ b/Tests/NIOTransportServicesTests/NIOTSEventLoopTests.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import XCTest import NIO import NIOConcurrencyHelpers @@ -127,3 +129,4 @@ class NIOTSEventLoopTest: XCTestCase { XCTAssertNil(weakEL) } } +#endif diff --git a/Tests/NIOTransportServicesTests/NIOTSListenerChannelTests.swift b/Tests/NIOTransportServicesTests/NIOTSListenerChannelTests.swift index 3b67ecd..e86d70f 100644 --- a/Tests/NIOTransportServicesTests/NIOTSListenerChannelTests.swift +++ b/Tests/NIOTransportServicesTests/NIOTSListenerChannelTests.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import XCTest import Network import NIO @@ -219,3 +221,4 @@ class NIOTSListenerChannelTests: XCTestCase { } } } +#endif diff --git a/Tests/NIOTransportServicesTests/NIOTSSocketOptionTests.swift b/Tests/NIOTransportServicesTests/NIOTSSocketOptionTests.swift index 94d5969..f93fc87 100644 --- a/Tests/NIOTransportServicesTests/NIOTSSocketOptionTests.swift +++ b/Tests/NIOTransportServicesTests/NIOTSSocketOptionTests.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import XCTest import NIO import Network @@ -162,3 +164,4 @@ class NIOTSSocketOptionTests: XCTestCase { } } } +#endif diff --git a/Tests/NIOTransportServicesTests/NIOTSSocketOptionsOnChannelTests.swift b/Tests/NIOTransportServicesTests/NIOTSSocketOptionsOnChannelTests.swift index d0934be..def1500 100644 --- a/Tests/NIOTransportServicesTests/NIOTSSocketOptionsOnChannelTests.swift +++ b/Tests/NIOTransportServicesTests/NIOTSSocketOptionsOnChannelTests.swift @@ -13,6 +13,8 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// + +#if canImport(Network) import XCTest import NIO import Network @@ -121,4 +123,4 @@ class NIOTSSocketOptionsOnChannelTests: XCTestCase { try self.assertChannelOptionAfterCreation(option: SocketOption(level: SOL_SOCKET, name: SO_KEEPALIVE), initialValue: 0, testAlternativeValue: 1) } } - +#endif