From 0526853ddecab9c431c7d1ffa05daee3b1a34447 Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Thu, 2 Oct 2025 12:32:33 +0200 Subject: [PATCH 01/19] Fixed some linker errors caused by WAL absence on Linux. --- GRDB/Core/DispatchQueueActor.swift | 4 ++++ Package.swift | 2 ++ 2 files changed, 6 insertions(+) diff --git a/GRDB/Core/DispatchQueueActor.swift b/GRDB/Core/DispatchQueueActor.swift index 3a51d8897..93f054a30 100644 --- a/GRDB/Core/DispatchQueueActor.swift +++ b/GRDB/Core/DispatchQueueActor.swift @@ -1,4 +1,8 @@ +#if os(Linux) +@preconcurrency import Dispatch +#else import Dispatch +#endif /// An actor that runs in a DispatchQueue. /// diff --git a/Package.swift b/Package.swift index 9d0c79554..680d1c913 100644 --- a/Package.swift +++ b/Package.swift @@ -21,6 +21,8 @@ var swiftSettings: [SwiftSetting] = [ // TODO: when Xcode support traits, remove all mentions of SQLITE_DISABLE_SNAPSHOT and update as below: // .define("SQLITE_ENABLE_SNAPSHOT", .when(platforms: darwinPlatforms, traits: ["GRDBSQLite"])), .define("SQLITE_ENABLE_SNAPSHOT"), + // Not all Linux distributions have support for WAL snapshots. + .define("SQLITE_DISABLE_SNAPSHOT", .when(platforms: [.linux])), ] var cSettings: [CSetting] = [] var dependencies: [PackageDescription.Package.Dependency] = [] From 2d6fe172c35a9b40dd520adb9961396b0f2ba8bd Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 16:57:26 +0200 Subject: [PATCH 02/19] Import Foundation for CGFloat on non-Darwin platforms --- GRDB/Core/Support/CoreGraphics/CGFloat.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GRDB/Core/Support/CoreGraphics/CGFloat.swift b/GRDB/Core/Support/CoreGraphics/CGFloat.swift index 6b0fb6053..11487c6b4 100644 --- a/GRDB/Core/Support/CoreGraphics/CGFloat.swift +++ b/GRDB/Core/Support/CoreGraphics/CGFloat.swift @@ -1,5 +1,8 @@ #if canImport(CoreGraphics) import CoreGraphics +#elseif !os(Darwin) +import Foundation +#endif /// CGFloat adopts DatabaseValueConvertible extension CGFloat: DatabaseValueConvertible { @@ -15,4 +18,3 @@ extension CGFloat: DatabaseValueConvertible { return CGFloat(double) } } -#endif From 7477e1cff86d9be17fe3c30093c809c907a7839e Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Thu, 2 Oct 2025 12:42:58 +0200 Subject: [PATCH 03/19] Removed the `#if !os(Linux)` compiler directive in the `Decimal` extension, as it compiles fine under swift 6 --- GRDB/Core/Support/Foundation/Decimal.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/GRDB/Core/Support/Foundation/Decimal.swift b/GRDB/Core/Support/Foundation/Decimal.swift index 70d84f3ab..d315fb6d4 100644 --- a/GRDB/Core/Support/Foundation/Decimal.swift +++ b/GRDB/Core/Support/Foundation/Decimal.swift @@ -1,4 +1,3 @@ -#if !os(Linux) // Import C SQLite functions #if GRDBCIPHER // CocoaPods (SQLCipher subspec) import SQLCipher @@ -68,4 +67,3 @@ extension Decimal: StatementColumnConvertible { @usableFromInline let _posixLocale = Locale(identifier: "en_US_POSIX") -#endif From e758fde94161dc48e70a660ce481544ad07b2d91 Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Thu, 2 Oct 2025 12:44:43 +0200 Subject: [PATCH 04/19] Removed #if !os(Linux) in NSString.swift, NSData.swift and Date.swift. --- GRDB/Core/Support/Foundation/Date.swift | 2 -- GRDB/Core/Support/Foundation/NSData.swift | 2 -- GRDB/Core/Support/Foundation/NSString.swift | 2 -- 3 files changed, 6 deletions(-) diff --git a/GRDB/Core/Support/Foundation/Date.swift b/GRDB/Core/Support/Foundation/Date.swift index dadc00fd6..379e3ff5b 100644 --- a/GRDB/Core/Support/Foundation/Date.swift +++ b/GRDB/Core/Support/Foundation/Date.swift @@ -12,7 +12,6 @@ import GRDBSQLite import Foundation -#if !os(Linux) /// NSDate is stored in the database using the format /// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone. extension NSDate: DatabaseValueConvertible { @@ -41,7 +40,6 @@ extension NSDate: DatabaseValueConvertible { return cast(date) } } -#endif /// Date is stored in the database using the format /// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone. diff --git a/GRDB/Core/Support/Foundation/NSData.swift b/GRDB/Core/Support/Foundation/NSData.swift index 72861ac02..12cba1a3c 100644 --- a/GRDB/Core/Support/Foundation/NSData.swift +++ b/GRDB/Core/Support/Foundation/NSData.swift @@ -1,4 +1,3 @@ -#if !os(Linux) import Foundation /// NSData is convertible to and from DatabaseValue. @@ -24,4 +23,3 @@ extension NSData: DatabaseValueConvertible { return cast(data) } } -#endif diff --git a/GRDB/Core/Support/Foundation/NSString.swift b/GRDB/Core/Support/Foundation/NSString.swift index acddddb35..3f019ad40 100644 --- a/GRDB/Core/Support/Foundation/NSString.swift +++ b/GRDB/Core/Support/Foundation/NSString.swift @@ -1,4 +1,3 @@ -#if !os(Linux) import Foundation /// NSString adopts DatabaseValueConvertible @@ -24,4 +23,3 @@ extension NSString: DatabaseValueConvertible { return self.init(string: string) } } -#endif From 14f60ad48f311476c8bb65f7d5fceb2300a1001d Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 17:42:25 +0200 Subject: [PATCH 05/19] Fixed fromDatabaseValue build under non-Darwin platforms --- GRDB/Core/Support/Foundation/NSNumber.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/GRDB/Core/Support/Foundation/NSNumber.swift b/GRDB/Core/Support/Foundation/NSNumber.swift index 1c5778c19..3b5076fd3 100644 --- a/GRDB/Core/Support/Foundation/NSNumber.swift +++ b/GRDB/Core/Support/Foundation/NSNumber.swift @@ -1,4 +1,4 @@ -#if !os(Linux) && !os(Windows) +#if !os(Windows) import Foundation private let integerRoundingBehavior = NSDecimalNumberHandler( @@ -81,10 +81,18 @@ extension NSNumber: DatabaseValueConvertible { /// Otherwise, returns nil. public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? { switch dbValue.storage { + case .int64(let int64) where self is NSDecimalNumber.Type: + let number = NSDecimalNumber(value: int64) + return number as? Self case .int64(let int64): - return self.init(value: int64) + let number = NSNumber(value: int64) + return number as? Self + case .double(let double) where self is NSDecimalNumber.Type: + let number = NSDecimalNumber(value: double) + return number as? Self case .double(let double): - return self.init(value: double) + let number = NSNumber(value: double) + return number as? Self case let .string(string): // Must match Decimal.fromDatabaseValue(_:) guard let decimal = Decimal(string: string, locale: posixLocale) else { return nil } From dc7d47c06620b50dff921c7afc295a79ad1ca238 Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 17:00:58 +0200 Subject: [PATCH 06/19] Fixed databaseValue build for non-Darwin platforms. --- GRDB/Core/Support/Foundation/URL.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/GRDB/Core/Support/Foundation/URL.swift b/GRDB/Core/Support/Foundation/URL.swift index 6db66ec3b..d8a8b1c80 100644 --- a/GRDB/Core/Support/Foundation/URL.swift +++ b/GRDB/Core/Support/Foundation/URL.swift @@ -1,12 +1,16 @@ import Foundation -#if !os(Linux) && !os(Windows) +#if !os(Windows) /// NSURL stores its absoluteString in the database. extension NSURL: DatabaseValueConvertible { /// Returns a TEXT database value containing the absolute URL. public var databaseValue: DatabaseValue { - absoluteString?.databaseValue ?? .null + #if !os(Darwin) + absoluteString.databaseValue + #else + absoluteString?.databaseValue ?? .null + #endif } public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? { From 8e5b9ca9bd5a51afc99eb7a101fd8e52bd8651be Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Thu, 2 Oct 2025 12:48:10 +0200 Subject: [PATCH 07/19] Fixed UUID fromDatabaseValue for non-Darwin platforms --- GRDB/Core/Support/Foundation/UUID.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/GRDB/Core/Support/Foundation/UUID.swift b/GRDB/Core/Support/Foundation/UUID.swift index 54b18b2c8..92d4e1fcb 100644 --- a/GRDB/Core/Support/Foundation/UUID.swift +++ b/GRDB/Core/Support/Foundation/UUID.swift @@ -12,7 +12,7 @@ import GRDBSQLite import Foundation -#if !os(Linux) && !os(Windows) +#if !os(Windows) /// NSUUID adopts DatabaseValueConvertible extension NSUUID: DatabaseValueConvertible { /// Returns a BLOB database value containing the uuid bytes. @@ -36,10 +36,17 @@ extension NSUUID: DatabaseValueConvertible { switch dbValue.storage { case .blob(let data) where data.count == 16: return data.withUnsafeBytes { - self.init(uuidBytes: $0.bindMemory(to: UInt8.self).baseAddress) + #if canImport(Darwin) + self.init(uuidBytes: $0.bindMemory(to: UInt8.self).baseAddress) + #else + guard let uuidBytes = $0.bindMemory(to: UInt8.self).baseAddress else { + return nil as Self? + } + return NSUUID(uuidBytes: uuidBytes) as? Self + #endif } case .string(let string): - return self.init(uuidString: string) + return NSUUID(uuidString: string) as? Self default: return nil } @@ -91,8 +98,8 @@ extension UUID: StatementColumnConvertible { self.init(uuid: uuid.uuid) case SQLITE_BLOB: guard sqlite3_column_bytes(sqliteStatement, index) == 16, - let blob = sqlite3_column_blob(sqliteStatement, index) else - { + let blob = sqlite3_column_blob(sqliteStatement, index) + else { return nil } self.init(uuid: blob.assumingMemoryBound(to: uuid_t.self).pointee) From c7f1dd74705a736e712cf5ee080f8315506a090f Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 17:02:54 +0200 Subject: [PATCH 08/19] Fixed import in CGFloatTests.swift to work under non-Darwin platforms. --- Tests/GRDBTests/CGFloatTests.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Tests/GRDBTests/CGFloatTests.swift b/Tests/GRDBTests/CGFloatTests.swift index 1bcfaaa58..3e0bd21c8 100644 --- a/Tests/GRDBTests/CGFloatTests.swift +++ b/Tests/GRDBTests/CGFloatTests.swift @@ -1,7 +1,12 @@ import XCTest -import CoreGraphics import GRDB +#if canImport(CoreGraphics) +import CoreGraphics +#elseif !os(Darwin) +import Foundation +#endif + class CGFloatTests: GRDBTestCase { func testCGFLoat() throws { From 691207567a6816b910570835dbf64f1a988df1ec Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 17:04:23 +0200 Subject: [PATCH 09/19] Ignore FailureTestCase.swift entirely on non-Darwin platforms for now. --- Tests/GRDBTests/FailureTestCase.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/GRDBTests/FailureTestCase.swift b/Tests/GRDBTests/FailureTestCase.swift index 9dfb9770b..7b552aaa0 100644 --- a/Tests/GRDBTests/FailureTestCase.swift +++ b/Tests/GRDBTests/FailureTestCase.swift @@ -1,3 +1,4 @@ +#if canImport(Darwin) // Inspired by https://github.com/groue/CombineExpectations import XCTest @@ -207,3 +208,4 @@ class FailureTestCaseTests: FailureTestCase { } } } +#endif From dd90fe6e62daa8cad14c65d1e9f9a5a05b394f52 Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 17:05:35 +0200 Subject: [PATCH 10/19] Ignore ValueObservationRecorderTests.swift on non-Darwin platforms. --- Tests/GRDBTests/ValueObservationRecorderTests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/GRDBTests/ValueObservationRecorderTests.swift b/Tests/GRDBTests/ValueObservationRecorderTests.swift index 4b8e8a2ae..134543db4 100644 --- a/Tests/GRDBTests/ValueObservationRecorderTests.swift +++ b/Tests/GRDBTests/ValueObservationRecorderTests.swift @@ -1,3 +1,4 @@ +#if canImport(Darwin) import Dispatch import XCTest @@ -781,3 +782,4 @@ class ValueObservationRecorderTests: FailureTestCase { } } } +#endif From 2ad2d20a89e3e1feeb7de69a5aa92956a4ad6f6f Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 17:11:26 +0200 Subject: [PATCH 11/19] Fixed the unit tests in DatabasePoolConcurrencyTests. --- .../DatabasePoolConcurrencyTests.swift | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift b/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift index 7d2478545..bbdf523d4 100644 --- a/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift +++ b/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift @@ -877,10 +877,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, nil) XCTAssertEqual(db.description, "GRDB.DatabasePool.writer") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "GRDB.DatabasePool.writer") +#endif } let s1 = DispatchSemaphore(value: 0) @@ -890,10 +892,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, nil) XCTAssertEqual(db.description, "GRDB.DatabasePool.reader.1") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "GRDB.DatabasePool.reader.1") +#endif _ = s1.signal() _ = s2.wait(timeout: .distantFuture) @@ -906,10 +910,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, nil) XCTAssertEqual(db.description, "GRDB.DatabasePool.reader.2") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "GRDB.DatabasePool.reader.2") +#endif } } let blocks = [block1, block2] @@ -925,10 +931,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, "Toreador") XCTAssertEqual(db.description, "Toreador.writer") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "Toreador.writer") +#endif } let s1 = DispatchSemaphore(value: 0) @@ -938,10 +946,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, "Toreador") XCTAssertEqual(db.description, "Toreador.reader.1") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "Toreador.reader.1") +#endif _ = s1.signal() _ = s2.wait(timeout: .distantFuture) @@ -954,10 +964,12 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, "Toreador") XCTAssertEqual(db.description, "Toreador.reader.2") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "Toreador.reader.2") +#endif } } let blocks = [block1, block2] @@ -1037,6 +1049,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { } func testQoS() throws { +#if !canImport(Darwin) + throw XCTSkip("__dispatch_get_global_queue unavailable") +#else func test(qos: DispatchQoS) throws { // https://forums.swift.org/t/what-is-the-default-target-queue-for-a-serial-queue/18094/5 // @@ -1072,6 +1087,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { try test(qos: .background) try test(qos: .userInitiated) +#endif } // MARK: - AsyncConcurrentRead @@ -1254,6 +1270,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { // MARK: - Concurrent opening func testConcurrentOpening() throws { +#if !canImport(Darwin) + throw XCTSkip("NSFileCoordinator unavailable") +#else for _ in 0..<50 { let dbDirectoryName = "DatabasePoolConcurrencyTests-\(ProcessInfo.processInfo.globallyUniqueString)" let directoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) @@ -1277,6 +1296,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { XCTAssert(poolError ?? coordinatorError == nil) } } +#endif } // MARK: - NSFileCoordinator sample code tests @@ -1284,6 +1304,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { // Test for sample code in Documentation.docc/DatabaseSharing.md. // This test passes if this method compiles private func openSharedDatabase(at databaseURL: URL) throws -> DatabasePool { +#if !canImport(Darwin) + throw XCTSkip("NSFileCoordinator unavailable") +#else let coordinator = NSFileCoordinator(filePresenter: nil) var coordinatorError: NSError? var dbPool: DatabasePool? @@ -1299,6 +1322,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { throw error } return dbPool! +#endif } // Test for sample code in Documentation.docc/DatabaseSharing.md. @@ -1313,6 +1337,9 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { // Test for sample code in Documentation.docc/DatabaseSharing.md. // This test passes if this method compiles private func openSharedReadOnlyDatabase(at databaseURL: URL) throws -> DatabasePool? { +#if !canImport(Darwin) + throw XCTSkip("NSFileCoordinator unavailable") +#else let coordinator = NSFileCoordinator(filePresenter: nil) var coordinatorError: NSError? var dbPool: DatabasePool? @@ -1328,6 +1355,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { throw error } return dbPool +#endif } // Test for sample code in Documentation.docc/DatabaseSharing.md. From 5513eab099a3ec2587fa3f543de72a899e9ecc15 Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 17:13:46 +0200 Subject: [PATCH 12/19] Fixed the tests in DatabaseQueueTests.swift --- Tests/GRDBTests/DatabaseQueueTests.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/GRDBTests/DatabaseQueueTests.swift b/Tests/GRDBTests/DatabaseQueueTests.swift index c22be8326..0372d9777 100644 --- a/Tests/GRDBTests/DatabaseQueueTests.swift +++ b/Tests/GRDBTests/DatabaseQueueTests.swift @@ -129,10 +129,12 @@ class DatabaseQueueTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, nil) XCTAssertEqual(db.description, "GRDB.DatabaseQueue") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "GRDB.DatabaseQueue") +#endif } } @@ -144,10 +146,12 @@ class DatabaseQueueTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, "Toreador") XCTAssertEqual(db.description, "Toreador") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "Toreador") +#endif } } @@ -221,6 +225,9 @@ class DatabaseQueueTests: GRDBTestCase { } func testQoS() throws { +#if !canImport(Darwin) + throw XCTSkip("__dispatch_get_global_queue not available on non-Darwin platforms") +#else func test(qos: DispatchQoS) throws { // https://forums.swift.org/t/what-is-the-default-target-queue-for-a-serial-queue/18094/5 // @@ -256,6 +263,7 @@ class DatabaseQueueTests: GRDBTestCase { try test(qos: .background) try test(qos: .userInitiated) +#endif } // MARK: - SQLITE_BUSY prevention From 2f108508fa3f32e05aabce1fc928f0af999c4131 Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 17:15:32 +0200 Subject: [PATCH 13/19] Fixed DatabaseSnapshotTests on non-darwin platforms --- Tests/GRDBTests/DatabaseSnapshotTests.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/GRDBTests/DatabaseSnapshotTests.swift b/Tests/GRDBTests/DatabaseSnapshotTests.swift index 1cb422ecd..b31ccea69 100644 --- a/Tests/GRDBTests/DatabaseSnapshotTests.swift +++ b/Tests/GRDBTests/DatabaseSnapshotTests.swift @@ -230,10 +230,12 @@ class DatabaseSnapshotTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, nil) XCTAssertEqual(db.description, "GRDB.DatabasePool.snapshot.1") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "GRDB.DatabasePool.snapshot.1") +#endif } let snapshot2 = try dbPool.makeSnapshot() @@ -241,10 +243,12 @@ class DatabaseSnapshotTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, nil) XCTAssertEqual(db.description, "GRDB.DatabasePool.snapshot.2") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "GRDB.DatabasePool.snapshot.2") +#endif } } @@ -257,10 +261,12 @@ class DatabaseSnapshotTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, "Toreador") XCTAssertEqual(db.description, "Toreador.snapshot.1") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "Toreador.snapshot.1") +#endif } let snapshot2 = try dbPool.makeSnapshot() @@ -268,10 +274,12 @@ class DatabaseSnapshotTests: GRDBTestCase { XCTAssertEqual(db.configuration.label, "Toreador") XCTAssertEqual(db.description, "Toreador.snapshot.2") +#if canImport(Darwin) // This test CAN break in future releases: the dispatch queue labels // are documented to be a debug-only tool. let label = String(utf8String: __dispatch_queue_get_label(nil)) XCTAssertEqual(label, "Toreador.snapshot.2") +#endif } } From 65186104cce3457f2a2912857b0637a66175203a Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 17:16:06 +0200 Subject: [PATCH 14/19] Integrated upstream changes. Some tests depend on Combine which is not available on non-Darwin platforms. Fix this. --- Tests/GRDBTests/DatabaseMigratorTests.swift | 2 ++ Tests/GRDBTests/DatabaseRegionObservationTests.swift | 2 ++ Tests/GRDBTests/ValueObservationTests.swift | 2 ++ 3 files changed, 6 insertions(+) diff --git a/Tests/GRDBTests/DatabaseMigratorTests.swift b/Tests/GRDBTests/DatabaseMigratorTests.swift index da0922508..73d873020 100644 --- a/Tests/GRDBTests/DatabaseMigratorTests.swift +++ b/Tests/GRDBTests/DatabaseMigratorTests.swift @@ -9,6 +9,7 @@ class DatabaseMigratorTests : GRDBTestCase { try migrator.migrate(writer) } + #if canImport(Combine) func testEmptyMigratorSync() throws { func test(writer: some DatabaseWriter) throws { let migrator = DatabaseMigrator() @@ -347,6 +348,7 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } } + #endif func testMigrationFailureTriggersRollback() throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in diff --git a/Tests/GRDBTests/DatabaseRegionObservationTests.swift b/Tests/GRDBTests/DatabaseRegionObservationTests.swift index 3ffdfc39e..6338a7605 100644 --- a/Tests/GRDBTests/DatabaseRegionObservationTests.swift +++ b/Tests/GRDBTests/DatabaseRegionObservationTests.swift @@ -4,12 +4,14 @@ import GRDB class DatabaseRegionObservationTests: GRDBTestCase { // Test passes if it compiles. // See + #if canImport(Combine) func testAnyDatabaseWriter(writer: any DatabaseWriter) throws { let observation = DatabaseRegionObservation(tracking: .fullDatabase) _ = observation.start(in: writer, onError: { _ in }, onChange: { _ in }) _ = observation.publisher(in: writer) } + #endif func testDatabaseRegionObservation_FullDatabase() throws { let dbQueue = try makeDatabaseQueue() diff --git a/Tests/GRDBTests/ValueObservationTests.swift b/Tests/GRDBTests/ValueObservationTests.swift index 6134d8453..e884fc2a0 100644 --- a/Tests/GRDBTests/ValueObservationTests.swift +++ b/Tests/GRDBTests/ValueObservationTests.swift @@ -926,6 +926,7 @@ class ValueObservationTests: GRDBTestCase { } // MARK: - Async Await +#if canImport(Combine) func testAsyncAwait_values_prefix() async throws { func test(_ writer: some DatabaseWriter) async throws { @@ -1238,6 +1239,7 @@ class ValueObservationTests: GRDBTestCase { try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } } +#endif // Regression test for func testIssue1383() throws { From a212bf9e8993fceccbca4ace7dc7902c7f1cd324 Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Thu, 2 Oct 2025 17:06:58 +0200 Subject: [PATCH 15/19] It should be canImport(Darwin) not os(Darwin) --- GRDB/Core/Support/CoreGraphics/CGFloat.swift | 2 +- GRDB/Core/Support/Foundation/URL.swift | 2 +- Tests/GRDBTests/CGFloatTests.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/GRDB/Core/Support/CoreGraphics/CGFloat.swift b/GRDB/Core/Support/CoreGraphics/CGFloat.swift index 11487c6b4..99d615350 100644 --- a/GRDB/Core/Support/CoreGraphics/CGFloat.swift +++ b/GRDB/Core/Support/CoreGraphics/CGFloat.swift @@ -1,6 +1,6 @@ #if canImport(CoreGraphics) import CoreGraphics -#elseif !os(Darwin) +#elseif !canImport(Darwin) import Foundation #endif diff --git a/GRDB/Core/Support/Foundation/URL.swift b/GRDB/Core/Support/Foundation/URL.swift index d8a8b1c80..b3630b14a 100644 --- a/GRDB/Core/Support/Foundation/URL.swift +++ b/GRDB/Core/Support/Foundation/URL.swift @@ -6,7 +6,7 @@ extension NSURL: DatabaseValueConvertible { /// Returns a TEXT database value containing the absolute URL. public var databaseValue: DatabaseValue { - #if !os(Darwin) + #if !canImport(Darwin) absoluteString.databaseValue #else absoluteString?.databaseValue ?? .null diff --git a/Tests/GRDBTests/CGFloatTests.swift b/Tests/GRDBTests/CGFloatTests.swift index 3e0bd21c8..4c9ebd93b 100644 --- a/Tests/GRDBTests/CGFloatTests.swift +++ b/Tests/GRDBTests/CGFloatTests.swift @@ -3,7 +3,7 @@ import GRDB #if canImport(CoreGraphics) import CoreGraphics -#elseif !os(Darwin) +#elseif !canImport(Darwin) import Foundation #endif From 389c3e0d4a255eaec3b152cff4ed851bfcdc4f67 Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Fri, 3 Oct 2025 09:30:54 +0200 Subject: [PATCH 16/19] Use #if !canImport(Combine) per test case (as done by @marcprux) and throw an XCTSkip for these test cases. This gives a better impression how many tests are skipped on Linux/non-Darwin platforms. --- Tests/GRDBTests/DatabaseMigratorTests.swift | 46 ++++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/Tests/GRDBTests/DatabaseMigratorTests.swift b/Tests/GRDBTests/DatabaseMigratorTests.swift index 73d873020..1b053e258 100644 --- a/Tests/GRDBTests/DatabaseMigratorTests.swift +++ b/Tests/GRDBTests/DatabaseMigratorTests.swift @@ -9,8 +9,10 @@ class DatabaseMigratorTests : GRDBTestCase { try migrator.migrate(writer) } - #if canImport(Combine) func testEmptyMigratorSync() throws { +#if !canImport(Combine) + throw XCTSkip("Combine not supported on this platform") +#else func test(writer: some DatabaseWriter) throws { let migrator = DatabaseMigrator() try migrator.migrate(writer) @@ -19,9 +21,13 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).run { try DatabaseQueue() } try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) } try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } +#endif } func testEmptyMigratorAsync() throws { +#if !canImport(Combine) + throw XCTSkip("Combine not supported on this platform") +#else func test(writer: some DatabaseWriter) throws { let expectation = self.expectation(description: "") let migrator = DatabaseMigrator() @@ -39,9 +45,13 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).run { try DatabaseQueue() } try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) } try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } +#endif } func testEmptyMigratorPublisher() throws { +#if !canImport(Combine) + throw XCTSkip("Combine not supported on this platform") +#else func test(writer: some DatabaseWriter) throws { let migrator = DatabaseMigrator() let publisher = migrator.migratePublisher(writer) @@ -52,9 +62,13 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).run { try DatabaseQueue() } try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) } try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } +#endif } func testNonEmptyMigratorSync() throws { +#if !canImport(Combine) + throw XCTSkip("Combine not supported on this platform") +#else func test(writer: some DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in @@ -96,9 +110,13 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).run { try DatabaseQueue() } try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) } try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } +#endif } func testNonEmptyMigratorAsync() throws { +#if !canImport(Combine) + throw XCTSkip("Combine not supported on this platform") +#else func test(writer: some DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in @@ -147,9 +165,13 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).run { try DatabaseQueue() } try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) } try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } +#endif } func testNonEmptyMigratorPublisher() throws { +#if !canImport(Combine) + throw XCTSkip("Combine not supported on this platform") +#else func test(writer: some DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in @@ -199,9 +221,13 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).run { try DatabaseQueue() } try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) } try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } +#endif } func testEmptyMigratorPublisherIsAsynchronous() throws { +#if !canImport(Combine) + throw XCTSkip("Combine not supported on this platform") +#else func test(writer: some DatabaseWriter) throws { let migrator = DatabaseMigrator() let expectation = self.expectation(description: "") @@ -221,9 +247,13 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).run { try DatabaseQueue() } try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) } try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } +#endif } func testNonEmptyMigratorPublisherIsAsynchronous() throws { +#if !canImport(Combine) + throw XCTSkip("Combine not supported on this platform") +#else func test(writer: some DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("first", migrate: { _ in }) @@ -244,9 +274,13 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).run { try DatabaseQueue() } try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) } try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } +#endif } func testMigratorPublisherDefaultScheduler() throws { +#if !canImport(Combine) + throw XCTSkip("Combine not supported on this platform") +#else func test(writer: Writer) { var migrator = DatabaseMigrator() migrator.registerMigration("first", migrate: { _ in }) @@ -269,9 +303,13 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).run { try DatabaseQueue() } try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) } try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } +#endif } func testMigratorPublisherCustomScheduler() throws { +#if !canImport(Combine) + throw XCTSkip("Combine not supported on this platform") +#else func test(writer: Writer) { var migrator = DatabaseMigrator() migrator.registerMigration("first", migrate: { _ in }) @@ -295,9 +333,13 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).run { try DatabaseQueue() } try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) } try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } +#endif } func testMigrateUpTo() throws { +#if !canImport(Combine) + throw XCTSkip("Combine not supported on this platform") +#else func test(writer: some DatabaseWriter) throws { var migrator = DatabaseMigrator() migrator.registerMigration("a") { db in @@ -346,9 +388,9 @@ class DatabaseMigratorTests : GRDBTestCase { try Test(test).run { try DatabaseQueue() } try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) } try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) } +#endif } - #endif func testMigrationFailureTriggersRollback() throws { var migrator = DatabaseMigrator() migrator.registerMigration("createPersons") { db in From d7cf0f9e59c46054d1dcbbe1b145c19c8ed8de30 Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 17:17:47 +0200 Subject: [PATCH 17/19] NSError bridging is not available, or doesn't work the same on non-Darwin platforms. Skip testNSErrorBridging on these platforms. --- Tests/GRDBTests/DatabaseErrorTests.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/GRDBTests/DatabaseErrorTests.swift b/Tests/GRDBTests/DatabaseErrorTests.swift index e968b4407..d0106ad64 100644 --- a/Tests/GRDBTests/DatabaseErrorTests.swift +++ b/Tests/GRDBTests/DatabaseErrorTests.swift @@ -216,6 +216,9 @@ class DatabaseErrorTests: GRDBTestCase { } func testNSErrorBridging() throws { +#if !canImport(Darwin) + throw XCTSkip("NSError bridging not available on non-Darwin platforms") +#else let dbQueue = try makeDatabaseQueue() try dbQueue.inDatabase { db in try db.create(table: "parents") { $0.column("id", .integer).primaryKey() } @@ -229,5 +232,6 @@ class DatabaseErrorTests: GRDBTestCase { XCTAssertNotNil(error.localizedFailureReason) } } +#endif } } From 3dd3bbf0c5ab23fb8576f380d9a5564bc83ca846 Mon Sep 17 00:00:00 2001 From: Tim De Jong Date: Sun, 12 Oct 2025 16:43:31 +0200 Subject: [PATCH 18/19] vscode config --- .vscode/settings.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..35164a22f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "editor.formatOnSave": false, + "editor.insertSpaces": true, + "editor.tabSize": 4, + "editor.detectIndentation": false, + "editor.trimAutoWhitespace": false +} \ No newline at end of file From c229891b6db050a6997b761cff156aab3354ef1c Mon Sep 17 00:00:00 2001 From: leejungyeob Date: Fri, 16 Jan 2026 18:20:56 +0900 Subject: [PATCH 19/19] Fix typo in usage examples --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 60c79359a..91a710a7b 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ try dbQueue.write { db in } try dbQueue.read { db in - let player = try Player.find(db, id: "1")) + let player = try Player.find(db, id: "1") let bestPlayers = try Player .order(\.score.desc)