From fae0977f89dd09aaaa064eba0ed37e98ca22f8ca Mon Sep 17 00:00:00 2001 From: Peter Adams <63288215+PeterAdams-A@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:21:52 +0000 Subject: [PATCH] Drop support for Swift < 5.9 (#39) Motivation: Consistent support model with other libraries. Modifications: Drop old Package.swifts and set tools version. Remove unnecessary compiler guards Result: Swift < 5.9 not supported any more --- Package.swift | 2 +- Package@swift-5.4.swift | 168 ------------------ Package@swift-5.5.swift | 168 ------------------ Sources/CassandraClient/CassandraClient.swift | 2 - Sources/CassandraClient/Configuration.swift | 2 - .../CassandraClient/Data+PaginatedRows.swift | 4 - Sources/CassandraClient/Session.swift | 10 -- .../CassandraClientTests.swift | 18 -- 8 files changed, 1 insertion(+), 373 deletions(-) delete mode 100644 Package@swift-5.4.swift delete mode 100644 Package@swift-5.5.swift diff --git a/Package.swift b/Package.swift index 8e9b032..03054e9 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.6 +// swift-tools-version:5.9 import PackageDescription diff --git a/Package@swift-5.4.swift b/Package@swift-5.4.swift deleted file mode 100644 index 65b8c17..0000000 --- a/Package@swift-5.4.swift +++ /dev/null @@ -1,168 +0,0 @@ -// swift-tools-version:5.4 - -import PackageDescription - -import class Foundation.FileManager - -// Compute libuv sources to exclude -var libuvExclude = [ - "./libuv/src/unix/aix-common.c", - "./libuv/src/unix/aix.c", - "./libuv/src/unix/bsd-proctitle.c", - "./libuv/src/unix/cygwin.c", - "./libuv/src/unix/freebsd.c", - "./libuv/src/unix/haiku.c", - "./libuv/src/unix/hurd.c", - "./libuv/src/unix/ibmi.c", - "./libuv/src/unix/netbsd.c", - "./libuv/src/unix/no-fsevents.c", - "./libuv/src/unix/no-proctitle.c", - "./libuv/src/unix/openbsd.c", - "./libuv/src/unix/os390-proctitle.c", - "./libuv/src/unix/os390-syscalls.c", - "./libuv/src/unix/os390.c", - "./libuv/src/unix/posix-hrtime.c", - "./libuv/src/unix/posix-poll.c", - "./libuv/src/unix/pthread-fixes.c", - "./libuv/src/unix/qnx.c", - "./libuv/src/unix/sunos.c", - "./libuv/src/unix/sysinfo-loadavg.c", - "./libuv/src/unix/sysinfo-memory.c", -] - -#if !os(macOS) -libuvExclude += [ - "./libuv/src/unix/bsd-ifaddrs.c", - "./libuv/src/unix/darwin-proctitle.c", - "./libuv/src/unix/darwin.c", - "./libuv/src/unix/fsevents.c", - "./libuv/src/unix/kqueue.c", - "./libuv/src/unix/random-getentropy.c", -] -#endif - -#if !os(Linux) -libuvExclude += [ - "./libuv/src/unix/epoll.c", - "./libuv/src/unix/linux-core.c", - "./libuv/src/unix/linux-inotify.c", - "./libuv/src/unix/linux-syscalls.c", - "./libuv/src/unix/procfs-exepath.c", - "./libuv/src/unix/random-getrandom.c", - "./libuv/src/unix/random-sysctl-linux.c", -] -#endif - -var datastaxExclude = [ - "./datastax-cpp-driver/src/CMakeLists.txt", - "./datastax-cpp-driver/src/fixnl.sh", - "./datastax-cpp-driver/src/wkt.rl", - "./datastax-cpp-driver/src/wktgen.sh", - "./datastax-cpp-driver/src/gssapi", - "./datastax-cpp-driver/src/ssl/ssl_no_impl.cpp", - // See ./custom/src/ssl/ssl_openssl_impl.cpp - "./datastax-cpp-driver/src/ssl/ssl_openssl_impl.cpp", - "./datastax-cpp-driver/src/third_party/curl/CMakeLists.txt", - "./datastax-cpp-driver/src/third_party/curl/COPYING", - "./datastax-cpp-driver/src/third_party/hdr_histogram/CMakeLists.txt", - "./datastax-cpp-driver/src/third_party/hdr_histogram/LICENSE.txt", - "./datastax-cpp-driver/src/third_party/http-parser/AUTHORS", - "./datastax-cpp-driver/src/third_party/http-parser/bench.c", - "./datastax-cpp-driver/src/third_party/http-parser/CMakeLists.txt", - "./datastax-cpp-driver/src/third_party/http-parser/http_parser.gyp", - "./datastax-cpp-driver/src/third_party/http-parser/LICENSE-MIT", - "./datastax-cpp-driver/src/third_party/http-parser/README", - "./datastax-cpp-driver/src/third_party/http-parser/README.md", - "./datastax-cpp-driver/src/third_party/http-parser/test.c", - "./datastax-cpp-driver/src/third_party/http-parser/contrib/parsertrace.c", - "./datastax-cpp-driver/src/third_party/http-parser/contrib/url_parser.c", - "./datastax-cpp-driver/src/third_party/minizip", - "./datastax-cpp-driver/src/third_party/mt19937_64", - "./datastax-cpp-driver/src/third_party/rapidjson", - "./datastax-cpp-driver/src/third_party/sparsehash", - "./datastax-cpp-driver/tests", - "./datastax-cpp-driver/examples", -] - -do { - if !(try FileManager.default.contentsOfDirectory( - atPath: "./Sources/CDataStaxDriver/datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles" - ).isEmpty) { - datastaxExclude.append("./datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles/") - } -} catch { - // Assume CMakeFiles does not exist so no need to exclude it -} - -let package = Package( - name: "swift-cassandra-client", - products: [ - .library(name: "CassandraClient", targets: ["CassandraClient"]) - ], - dependencies: [ - .package(url: "https://github.com/apple/swift-nio", .upToNextMinor(from: "2.41.1")), - .package(url: "https://github.com/apple/swift-nio-ssl", .upToNextMinor(from: "2.21.0")), - .package(url: "https://github.com/apple/swift-atomics", from: "1.0.2"), - .package(url: "https://github.com/apple/swift-log", .upToNextMajor(from: "1.0.0")), - ], - targets: [ - .target( - name: "Clibuv", - dependencies: [], - exclude: libuvExclude, - sources: [ - "./libuv/src/fs-poll.c", - "./libuv/src/idna.c", - "./libuv/src/inet.c", - "./libuv/src/random.c", - "./libuv/src/strscpy.c", - "./libuv/src/strtok.c", - "./libuv/src/threadpool.c", - "./libuv/src/timer.c", - "./libuv/src/uv-common.c", - "./libuv/src/uv-data-getter-setters.c", - "./libuv/src/version.c", - "./libuv/src/unix", - ], - cSettings: [ - .headerSearchPath("./libuv/src"), - .define("_GNU_SOURCE", to: "1"), // required to fix "undefined CPU_COUNT" error - ] - ), - - .target( - name: "CDataStaxDriver", - dependencies: [ - "Clibuv", - .product(name: "NIOSSL", package: "swift-nio-ssl"), - ], - exclude: datastaxExclude, - sources: [ - "./datastax-cpp-driver/src", - "./custom/src", - ], - publicHeadersPath: "./datastax-cpp-driver/include", - cxxSettings: [ - .headerSearchPath("./custom/include"), - .headerSearchPath("./extras"), - .headerSearchPath("./datastax-cpp-driver/src"), - .headerSearchPath("./datastax-cpp-driver/src/third_party/http-parser"), - .headerSearchPath("./datastax-cpp-driver/src/third_party/sparsehash/src/"), - ] - ), - - .target( - name: "CassandraClient", - dependencies: [ - "CDataStaxDriver", - .product(name: "NIO", package: "swift-nio"), - .product(name: "NIOCore", package: "swift-nio"), - .product(name: "Atomics", package: "swift-atomics"), - .product(name: "Logging", package: "swift-log"), - ] - ), - - .testTarget(name: "CassandraClientTests", dependencies: ["CassandraClient"]), - ], - cxxLanguageStandard: .cxx14 -) diff --git a/Package@swift-5.5.swift b/Package@swift-5.5.swift deleted file mode 100644 index 65b8c17..0000000 --- a/Package@swift-5.5.swift +++ /dev/null @@ -1,168 +0,0 @@ -// swift-tools-version:5.4 - -import PackageDescription - -import class Foundation.FileManager - -// Compute libuv sources to exclude -var libuvExclude = [ - "./libuv/src/unix/aix-common.c", - "./libuv/src/unix/aix.c", - "./libuv/src/unix/bsd-proctitle.c", - "./libuv/src/unix/cygwin.c", - "./libuv/src/unix/freebsd.c", - "./libuv/src/unix/haiku.c", - "./libuv/src/unix/hurd.c", - "./libuv/src/unix/ibmi.c", - "./libuv/src/unix/netbsd.c", - "./libuv/src/unix/no-fsevents.c", - "./libuv/src/unix/no-proctitle.c", - "./libuv/src/unix/openbsd.c", - "./libuv/src/unix/os390-proctitle.c", - "./libuv/src/unix/os390-syscalls.c", - "./libuv/src/unix/os390.c", - "./libuv/src/unix/posix-hrtime.c", - "./libuv/src/unix/posix-poll.c", - "./libuv/src/unix/pthread-fixes.c", - "./libuv/src/unix/qnx.c", - "./libuv/src/unix/sunos.c", - "./libuv/src/unix/sysinfo-loadavg.c", - "./libuv/src/unix/sysinfo-memory.c", -] - -#if !os(macOS) -libuvExclude += [ - "./libuv/src/unix/bsd-ifaddrs.c", - "./libuv/src/unix/darwin-proctitle.c", - "./libuv/src/unix/darwin.c", - "./libuv/src/unix/fsevents.c", - "./libuv/src/unix/kqueue.c", - "./libuv/src/unix/random-getentropy.c", -] -#endif - -#if !os(Linux) -libuvExclude += [ - "./libuv/src/unix/epoll.c", - "./libuv/src/unix/linux-core.c", - "./libuv/src/unix/linux-inotify.c", - "./libuv/src/unix/linux-syscalls.c", - "./libuv/src/unix/procfs-exepath.c", - "./libuv/src/unix/random-getrandom.c", - "./libuv/src/unix/random-sysctl-linux.c", -] -#endif - -var datastaxExclude = [ - "./datastax-cpp-driver/src/CMakeLists.txt", - "./datastax-cpp-driver/src/fixnl.sh", - "./datastax-cpp-driver/src/wkt.rl", - "./datastax-cpp-driver/src/wktgen.sh", - "./datastax-cpp-driver/src/gssapi", - "./datastax-cpp-driver/src/ssl/ssl_no_impl.cpp", - // See ./custom/src/ssl/ssl_openssl_impl.cpp - "./datastax-cpp-driver/src/ssl/ssl_openssl_impl.cpp", - "./datastax-cpp-driver/src/third_party/curl/CMakeLists.txt", - "./datastax-cpp-driver/src/third_party/curl/COPYING", - "./datastax-cpp-driver/src/third_party/hdr_histogram/CMakeLists.txt", - "./datastax-cpp-driver/src/third_party/hdr_histogram/LICENSE.txt", - "./datastax-cpp-driver/src/third_party/http-parser/AUTHORS", - "./datastax-cpp-driver/src/third_party/http-parser/bench.c", - "./datastax-cpp-driver/src/third_party/http-parser/CMakeLists.txt", - "./datastax-cpp-driver/src/third_party/http-parser/http_parser.gyp", - "./datastax-cpp-driver/src/third_party/http-parser/LICENSE-MIT", - "./datastax-cpp-driver/src/third_party/http-parser/README", - "./datastax-cpp-driver/src/third_party/http-parser/README.md", - "./datastax-cpp-driver/src/third_party/http-parser/test.c", - "./datastax-cpp-driver/src/third_party/http-parser/contrib/parsertrace.c", - "./datastax-cpp-driver/src/third_party/http-parser/contrib/url_parser.c", - "./datastax-cpp-driver/src/third_party/minizip", - "./datastax-cpp-driver/src/third_party/mt19937_64", - "./datastax-cpp-driver/src/third_party/rapidjson", - "./datastax-cpp-driver/src/third_party/sparsehash", - "./datastax-cpp-driver/tests", - "./datastax-cpp-driver/examples", -] - -do { - if !(try FileManager.default.contentsOfDirectory( - atPath: "./Sources/CDataStaxDriver/datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles" - ).isEmpty) { - datastaxExclude.append("./datastax-cpp-driver/src/third_party/sparsehash/CMakeFiles/") - } -} catch { - // Assume CMakeFiles does not exist so no need to exclude it -} - -let package = Package( - name: "swift-cassandra-client", - products: [ - .library(name: "CassandraClient", targets: ["CassandraClient"]) - ], - dependencies: [ - .package(url: "https://github.com/apple/swift-nio", .upToNextMinor(from: "2.41.1")), - .package(url: "https://github.com/apple/swift-nio-ssl", .upToNextMinor(from: "2.21.0")), - .package(url: "https://github.com/apple/swift-atomics", from: "1.0.2"), - .package(url: "https://github.com/apple/swift-log", .upToNextMajor(from: "1.0.0")), - ], - targets: [ - .target( - name: "Clibuv", - dependencies: [], - exclude: libuvExclude, - sources: [ - "./libuv/src/fs-poll.c", - "./libuv/src/idna.c", - "./libuv/src/inet.c", - "./libuv/src/random.c", - "./libuv/src/strscpy.c", - "./libuv/src/strtok.c", - "./libuv/src/threadpool.c", - "./libuv/src/timer.c", - "./libuv/src/uv-common.c", - "./libuv/src/uv-data-getter-setters.c", - "./libuv/src/version.c", - "./libuv/src/unix", - ], - cSettings: [ - .headerSearchPath("./libuv/src"), - .define("_GNU_SOURCE", to: "1"), // required to fix "undefined CPU_COUNT" error - ] - ), - - .target( - name: "CDataStaxDriver", - dependencies: [ - "Clibuv", - .product(name: "NIOSSL", package: "swift-nio-ssl"), - ], - exclude: datastaxExclude, - sources: [ - "./datastax-cpp-driver/src", - "./custom/src", - ], - publicHeadersPath: "./datastax-cpp-driver/include", - cxxSettings: [ - .headerSearchPath("./custom/include"), - .headerSearchPath("./extras"), - .headerSearchPath("./datastax-cpp-driver/src"), - .headerSearchPath("./datastax-cpp-driver/src/third_party/http-parser"), - .headerSearchPath("./datastax-cpp-driver/src/third_party/sparsehash/src/"), - ] - ), - - .target( - name: "CassandraClient", - dependencies: [ - "CDataStaxDriver", - .product(name: "NIO", package: "swift-nio"), - .product(name: "NIOCore", package: "swift-nio"), - .product(name: "Atomics", package: "swift-atomics"), - .product(name: "Logging", package: "swift-log"), - ] - ), - - .testTarget(name: "CassandraClientTests", dependencies: ["CassandraClient"]), - ], - cxxLanguageStandard: .cxx14 -) diff --git a/Sources/CassandraClient/CassandraClient.swift b/Sources/CassandraClient/CassandraClient.swift index 667397d..f08fbf8 100644 --- a/Sources/CassandraClient/CassandraClient.swift +++ b/Sources/CassandraClient/CassandraClient.swift @@ -217,7 +217,6 @@ public class CassandraClient: CassandraSession { } } -#if compiler(>=5.5) && canImport(_Concurrency) extension CassandraClient { /// Execute a ``Statement`` using the default ``CassandraSession``. /// @@ -306,6 +305,5 @@ extension CassandraClient { return try await handler(session) } } -#endif internal typealias EventLoopGroupConainer = (value: EventLoopGroup, managed: Bool) diff --git a/Sources/CassandraClient/Configuration.swift b/Sources/CassandraClient/Configuration.swift index 051bfc4..51d5617 100644 --- a/Sources/CassandraClient/Configuration.swift +++ b/Sources/CassandraClient/Configuration.swift @@ -98,7 +98,6 @@ extension CassandraClient { return clusterPromise.futureResult } - #if compiler(>=5.5) && canImport(_Concurrency) @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) internal func makeCluster() async throws -> Cluster { try await withCheckedThrowingContinuation { continuation in @@ -117,7 +116,6 @@ extension CassandraClient { } } } - #endif private func makeCluster(contactPoints: ContactPoints) throws -> Cluster { let cluster = Cluster() diff --git a/Sources/CassandraClient/Data+PaginatedRows.swift b/Sources/CassandraClient/Data+PaginatedRows.swift index 11584c1..f2db99b 100644 --- a/Sources/CassandraClient/Data+PaginatedRows.swift +++ b/Sources/CassandraClient/Data+PaginatedRows.swift @@ -121,7 +121,6 @@ extension CassandraClient { return _map([]) } - #if compiler(>=5.5) && canImport(_Concurrency) @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) internal init(session: Session, statement: Statement, logger: Logger?) { self.session = session @@ -192,11 +191,9 @@ extension CassandraClient { } return try await _map([]) } - #endif } } -#if compiler(>=5.5) && canImport(_Concurrency) @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) extension CassandraClient.PaginatedRows: AsyncSequence { public typealias Element = CassandraClient.Row @@ -258,4 +255,3 @@ extension CassandraClient.PaginatedRows: AsyncSequence { } } } -#endif diff --git a/Sources/CassandraClient/Session.swift b/Sources/CassandraClient/Session.swift index d18fa9a..e69df5c 100644 --- a/Sources/CassandraClient/Session.swift +++ b/Sources/CassandraClient/Session.swift @@ -58,7 +58,6 @@ public protocol CassandraSession { logger: Logger? ) -> EventLoopFuture - #if compiler(>=5.5) && canImport(_Concurrency) /// Execute a prepared statement. /// /// **All** rows are returned. @@ -92,7 +91,6 @@ public protocol CassandraSession { logger: Logger? ) async throws -> CassandraClient.PaginatedRows - #endif /// Terminate the session and free resources. func shutdown() throws @@ -239,9 +237,7 @@ extension CassandraClient { private enum State { case idle case connectingFuture(EventLoopFuture) - #if compiler(>=5.5) && canImport(_Concurrency) case connecting(ConnectionTask) - #endif case connected case disconnected } @@ -307,7 +303,6 @@ extension CassandraClient { return future.flatMap { _ in self.execute(statement: statement, on: eventLoop, logger: logger) } - #if compiler(>=5.5) && canImport(_Concurrency) case .connecting(let task): self.lock.unlock() let promise = eventLoop.makePromise(of: Rows.self) @@ -318,7 +313,6 @@ extension CassandraClient { } } return promise.futureResult - #endif case .connected: self.lock.unlock() logger.debug("executing: \(statement.query)") @@ -402,7 +396,6 @@ extension CassandraClient { return CassandraMetrics(metrics: metrics) } - #if compiler(>=5.5) && canImport(_Concurrency) private struct ConnectionTask { private let _task: Any @@ -416,13 +409,11 @@ extension CassandraClient { self._task = task } } - #endif } } // MARK: - Cassandra session with async-await support -#if compiler(>=5.5) && canImport(_Concurrency) extension CassandraSession { /// Run insert / update / delete or DDL commands where no result is expected @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) @@ -594,7 +585,6 @@ extension CassandraClient.Session { } } } -#endif // MARK: - Helpers diff --git a/Tests/CassandraClientTests/CassandraClientTests.swift b/Tests/CassandraClientTests/CassandraClientTests.swift index 1b89f0d..8497587 100644 --- a/Tests/CassandraClientTests/CassandraClientTests.swift +++ b/Tests/CassandraClientTests/CassandraClientTests.swift @@ -81,9 +81,6 @@ final class Tests: XCTestCase { @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) func testAsyncSession() throws { - #if !(compiler(>=5.5) && canImport(_Concurrency)) - try XCTSkipIf(true) - #else runAsyncAndWaitFor { let session = self.cassandraClient.makeSession(keyspace: self.configuration.keyspace) defer { XCTAssertNoThrow(try session.shutdown()) } @@ -103,7 +100,6 @@ final class Tests: XCTestCase { let result = try await session.query("select * from \(tableName);") XCTAssertEqual(Array(result).count, count) } - #endif } func testWithSessionBlocking() { @@ -124,9 +120,6 @@ final class Tests: XCTestCase { @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) func testWithAsyncSession() throws { - #if !(compiler(>=5.5) && canImport(_Concurrency)) - try XCTSkipIf(true) - #else runAsyncAndWaitFor { var configuration = self.configuration! configuration.keyspace = "test_\(DispatchTime.now().uptimeNanoseconds)" @@ -140,7 +133,6 @@ final class Tests: XCTestCase { } try await cassandraClient.run("create table test (data bigint primary key);") } - #endif } func testWithSessionChaining() { @@ -325,9 +317,6 @@ final class Tests: XCTestCase { @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) func testQueryAsyncIterator() throws { - #if !(compiler(>=5.5) && canImport(_Concurrency)) - try XCTSkipIf(true) - #else runAsyncAndWaitFor( { let tableName = "test_\(DispatchTime.now().uptimeNanoseconds)" @@ -377,7 +366,6 @@ final class Tests: XCTestCase { }, 5.0 ) - #endif } func testQueryBuffered() { @@ -415,9 +403,6 @@ final class Tests: XCTestCase { @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) func testQueryAsyncBuffered() throws { - #if !(compiler(>=5.5) && canImport(_Concurrency)) - try XCTSkipIf(true) - #else runAsyncAndWaitFor( { let tableName = "test_\(DispatchTime.now().uptimeNanoseconds)" @@ -449,7 +434,6 @@ final class Tests: XCTestCase { }, 5.0 ) - #endif } func testSelectIn() throws { @@ -843,7 +827,6 @@ final class Tests: XCTestCase { } } -#if compiler(>=5.5) && canImport(_Concurrency) extension XCTestCase { // TODO: remove once XCTest supports async functions @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) @@ -859,4 +842,3 @@ extension XCTestCase { wait(for: [finished], timeout: timeout) } } -#endif