diff --git a/Package.swift b/Package.swift index 26c61734a..2776f811f 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:6.1 +// swift-tools-version:6.2 // The swift-tools-version declares the minimum version of Swift required to build this package. import Foundation @@ -80,6 +80,9 @@ let package = Package( "Swift6Migration", "generatePerformanceReport.rb", "parsePerformanceTests.rb", + "Swift6ApprochableConcurrencyGRDBTests", + "Swift6DefaultGRDBTests", + "Swift6MainActorIsolationGRDBTests", ], resources: [ .copy("GRDBTests/Betty.jpeg"), @@ -92,7 +95,28 @@ let package = Package( .swiftLanguageMode(.v5), .enableUpcomingFeature("InferSendableFromCaptures"), .enableUpcomingFeature("GlobalActorIsolatedTypesUsability"), - ]) + ]), + .testTarget( + name: "Swift6ApprochableConcurrencyGRDBTests", + dependencies: ["GRDB"], + swiftSettings: [ + .enableUpcomingFeature("NonisolatedNonsendingByDefault"), + .enableUpcomingFeature("InferIsolatedConformances") + ] + ), + .testTarget( + name: "Swift6DefaultGRDBTests", + dependencies: ["GRDB"] + ), + .testTarget( + name: "Swift6MainActorIsolationGRDBTests", + dependencies: ["GRDB"], + swiftSettings: [ + .defaultIsolation(MainActor.self), + .enableUpcomingFeature("NonisolatedNonsendingByDefault"), + .enableUpcomingFeature("InferIsolatedConformances") + ] + ), ], swiftLanguageModes: [.v6] ) diff --git a/Package@swift-6.1.swift b/Package@swift-6.1.swift new file mode 100644 index 000000000..b3d4c51b3 --- /dev/null +++ b/Package@swift-6.1.swift @@ -0,0 +1,105 @@ +// swift-tools-version:6.1 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import Foundation +import PackageDescription + +let darwinPlatforms: [Platform] = [ + .iOS, + .macOS, + .macCatalyst, + .tvOS, + .visionOS, + .watchOS, +] +var swiftSettings: [SwiftSetting] = [ + .define("SQLITE_ENABLE_FTS5"), + .define("SQLITE_ENABLE_SNAPSHOT"), +] +var cSettings: [CSetting] = [] +var dependencies: [PackageDescription.Package.Dependency] = [] + +// Don't rely on those environment variables. They are ONLY testing conveniences: +// $ SQLITE_ENABLE_PREUPDATE_HOOK=1 make test_SPM +if ProcessInfo.processInfo.environment["SQLITE_ENABLE_PREUPDATE_HOOK"] == "1" { + swiftSettings.append(.define("SQLITE_ENABLE_PREUPDATE_HOOK")) + cSettings.append(.define("GRDB_SQLITE_ENABLE_PREUPDATE_HOOK")) +} + +// The SPI_BUILDER environment variable enables documentation building +// on . See +// +// for more information. +// +// SPI_BUILDER also enables the `make docs-localhost` command. +if ProcessInfo.processInfo.environment["SPI_BUILDER"] == "1" { + dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")) +} + +let package = Package( + name: "GRDB", + defaultLocalization: "en", // for tests + platforms: [ + .iOS(.v13), + .macOS(.v10_15), + .tvOS(.v13), + .watchOS(.v7), + ], + products: [ + .library(name: "GRDBSQLite", targets: ["GRDBSQLite"]), + .library(name: "GRDB", targets: ["GRDB"]), + .library(name: "GRDB-dynamic", type: .dynamic, targets: ["GRDB"]), + ], + dependencies: dependencies, + targets: [ + .systemLibrary( + name: "GRDBSQLite", + providers: [.apt(["libsqlite3-dev"])]), + .target( + name: "GRDB", + dependencies: [ + .target(name: "GRDBSQLite"), + ], + path: "GRDB", + resources: [.copy("PrivacyInfo.xcprivacy")], + cSettings: cSettings, + swiftSettings: swiftSettings), + .testTarget( + name: "GRDBTests", + dependencies: ["GRDB"], + path: "Tests", + exclude: [ + "CocoaPods", + "Crash", + "CustomSQLite", + "GRDBManualInstall", + "GRDBTests/getThreadsCount.c", + "Info.plist", + "Performance", + "SPM", + "Swift6Migration", + "generatePerformanceReport.rb", + "parsePerformanceTests.rb", + "Swift6ApprochableConcurrencyGRDBTests", + "Swift6DefaultGRDBTests", + "Swift6MainActorIsolationGRDBTests", + ], + resources: [ + .copy("GRDBTests/Betty.jpeg"), + .copy("GRDBTests/InflectionsTests.json"), + .copy("GRDBTests/Issue1383.sqlite"), + ], + cSettings: cSettings, + swiftSettings: swiftSettings + [ + // Tests still use the Swift 5 language mode. + .swiftLanguageMode(.v5), + .enableUpcomingFeature("InferSendableFromCaptures"), + .enableUpcomingFeature("GlobalActorIsolatedTypesUsability"), + ]), + .testTarget( + name: "Swift6DefaultGRDBTests", + dependencies: ["GRDB"] + ), + ], + swiftLanguageModes: [.v6] +) diff --git a/Tests/Swift6ApprochableConcurrencyGRDBTests/NonSendableTests.swift b/Tests/Swift6ApprochableConcurrencyGRDBTests/NonSendableTests.swift new file mode 100644 index 000000000..27b315605 --- /dev/null +++ b/Tests/Swift6ApprochableConcurrencyGRDBTests/NonSendableTests.swift @@ -0,0 +1,57 @@ +import GRDB +import Testing + +private class NonSendable { + var value: Int + + init(value: Int) { + self.value = value + } +} + +@Suite struct NonSendableTests { + @Test func non_sendable_type_sent_to_databaseReader_read() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.read { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseReader_unsafeRead() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.unsafeRead { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseWriter_barrierWriteWithoutTransaction() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.barrierWriteWithoutTransaction { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseWriter_write() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.write { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseWriter_writeWithoutTransaction() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.writeWithoutTransaction { _ in + nonSendable.value + } + #expect(value == 0) + } +} diff --git a/Tests/Swift6DefaultGRDBTests/NonSendableTests.swift b/Tests/Swift6DefaultGRDBTests/NonSendableTests.swift new file mode 100644 index 000000000..27b315605 --- /dev/null +++ b/Tests/Swift6DefaultGRDBTests/NonSendableTests.swift @@ -0,0 +1,57 @@ +import GRDB +import Testing + +private class NonSendable { + var value: Int + + init(value: Int) { + self.value = value + } +} + +@Suite struct NonSendableTests { + @Test func non_sendable_type_sent_to_databaseReader_read() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.read { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseReader_unsafeRead() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.unsafeRead { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseWriter_barrierWriteWithoutTransaction() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.barrierWriteWithoutTransaction { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseWriter_write() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.write { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseWriter_writeWithoutTransaction() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.writeWithoutTransaction { _ in + nonSendable.value + } + #expect(value == 0) + } +} diff --git a/Tests/Swift6MainActorIsolationGRDBTests/NonSendableTests.swift b/Tests/Swift6MainActorIsolationGRDBTests/NonSendableTests.swift new file mode 100644 index 000000000..b7c525f14 --- /dev/null +++ b/Tests/Swift6MainActorIsolationGRDBTests/NonSendableTests.swift @@ -0,0 +1,57 @@ +import GRDB +import Testing + +nonisolated private class NonSendable { + var value: Int + + init(value: Int) { + self.value = value + } +} + +@Suite struct NonSendableTests { + @Test func non_sendable_type_sent_to_databaseReader_read() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.read { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseReader_unsafeRead() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.unsafeRead { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseWriter_barrierWriteWithoutTransaction() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.barrierWriteWithoutTransaction { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseWriter_write() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.write { _ in + nonSendable.value + } + #expect(value == 0) + } + + @Test func non_sendable_type_sent_to_databaseWriter_writeWithoutTransaction() async throws { + let dbQueue = try DatabaseQueue() + let nonSendable = NonSendable(value: 0) + let value = try await dbQueue.writeWithoutTransaction { _ in + nonSendable.value + } + #expect(value == 0) + } +}