Skip to content

Commit 7266b64

Browse files
authored
fix: issue with MainActor isolated property on Swift 5.9 (#577)
* fix: build for Swift 5.9 * temp * wip * rollback ci xcode versions
1 parent 8f5b94f commit 7266b64

File tree

5 files changed

+83
-48
lines changed

5 files changed

+83
-48
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
matrix:
2222
command: [test, ""]
2323
platform: [IOS, MAC_CATALYST, MACOS, TVOS, VISIONOS, WATCHOS]
24-
xcode: [15.4, "16.0"]
24+
xcode: ["15.4", "16.0"]
2525
exclude:
2626
- { platform: VISIONOS }
2727
include:

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ test-docs:
8181
format:
8282
@swift format -i -r --ignore-unparsable-files .
8383

84+
85+
test-linux:
86+
docker run \
87+
--rm \
88+
-v "$(PWD):$(PWD)" \
89+
-w "$(PWD)" \
90+
swift:5.10 \
91+
bash -c 'swift test -c $(CONFIG)'
92+
93+
build-linux:
94+
docker run \
95+
--rm \
96+
-v "$(PWD):$(PWD)" \
97+
-w "$(PWD)" \
98+
swift:5.9 \
99+
bash -c 'swift build -c $(CONFIG)'
84100
.PHONY: build-for-library-evolution format xcodebuild test-docs test-integration
85101

86102
define udid_for

Sources/Auth/AuthClient.swift

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ public final class AuthClient: Sendable {
2121

2222
private var api: APIClient { Dependencies[clientID].api }
2323
var configuration: AuthClient.Configuration { Dependencies[clientID].configuration }
24-
private var codeVerifierStorage: CodeVerifierStorage { Dependencies[clientID].codeVerifierStorage }
24+
private var codeVerifierStorage: CodeVerifierStorage {
25+
Dependencies[clientID].codeVerifierStorage
26+
}
2527
private var date: @Sendable () -> Date { Dependencies[clientID].date }
2628
private var sessionManager: SessionManager { Dependencies[clientID].sessionManager }
2729
private var eventEmitter: AuthStateChangeEventEmitter { Dependencies[clientID].eventEmitter }
@@ -77,10 +79,11 @@ public final class AuthClient: Sendable {
7779
sessionManager: .live(clientID: clientID)
7880
)
7981

80-
observeAppLifecycleChanges()
82+
Task { @MainActor in observeAppLifecycleChanges() }
8183
}
8284

8385
#if canImport(ObjectiveC)
86+
@MainActor
8487
private func observeAppLifecycleChanges() {
8588
#if canImport(UIKit)
8689
#if canImport(WatchKit)
@@ -165,14 +168,20 @@ public final class AuthClient: Sendable {
165168
/// Listen for auth state changes.
166169
///
167170
/// An `.initialSession` is always emitted when this method is called.
168-
public var authStateChanges: AsyncStream<(
169-
event: AuthChangeEvent,
170-
session: Session?
171-
)> {
172-
let (stream, continuation) = AsyncStream<(
173-
event: AuthChangeEvent,
174-
session: Session?
175-
)>.makeStream()
171+
public var authStateChanges:
172+
AsyncStream<
173+
(
174+
event: AuthChangeEvent,
175+
session: Session?
176+
)
177+
>
178+
{
179+
let (stream, continuation) = AsyncStream<
180+
(
181+
event: AuthChangeEvent,
182+
session: Session?
183+
)
184+
>.makeStream()
176185

177186
Task {
178187
let handle = await onAuthStateChange { event, session in
@@ -209,10 +218,12 @@ public final class AuthClient: Sendable {
209218
url: configuration.url.appendingPathComponent("signup"),
210219
method: .post,
211220
query: [
212-
(redirectTo ?? configuration.redirectToURL).map { URLQueryItem(
213-
name: "redirect_to",
214-
value: $0.absoluteString
215-
) },
221+
(redirectTo ?? configuration.redirectToURL).map {
222+
URLQueryItem(
223+
name: "redirect_to",
224+
value: $0.absoluteString
225+
)
226+
}
216227
].compactMap { $0 },
217228
body: configuration.encoder.encode(
218229
SignUpRequest(
@@ -401,10 +412,12 @@ public final class AuthClient: Sendable {
401412
url: configuration.url.appendingPathComponent("otp"),
402413
method: .post,
403414
query: [
404-
(redirectTo ?? configuration.redirectToURL).map { URLQueryItem(
405-
name: "redirect_to",
406-
value: $0.absoluteString
407-
) },
415+
(redirectTo ?? configuration.redirectToURL).map {
416+
URLQueryItem(
417+
name: "redirect_to",
418+
value: $0.absoluteString
419+
)
420+
}
408421
].compactMap { $0 },
409422
body: configuration.encoder.encode(
410423
OTPParams(
@@ -524,7 +537,8 @@ public final class AuthClient: Sendable {
524537
let codeVerifier = codeVerifierStorage.get()
525538

526539
if codeVerifier == nil {
527-
logger?.error("code verifier not found, a code verifier should exist when calling this method.")
540+
logger?.error(
541+
"code verifier not found, a code verifier should exist when calling this method.")
528542
}
529543

530544
let session: Session = try await api.execute(
@@ -878,7 +892,9 @@ public final class AuthClient: Sendable {
878892
headers: [.authorization: "Bearer \(accessToken)"]
879893
)
880894
)
881-
} catch let AuthError.api(_, _, _, response) where [404, 403, 401].contains(response.statusCode) {
895+
} catch let AuthError.api(_, _, _, response)
896+
where [404, 403, 401].contains(response.statusCode)
897+
{
882898
// ignore 404s since user might not exist anymore
883899
// ignore 401s, and 403s since an invalid or expired JWT should sign out the current session.
884900
}
@@ -898,10 +914,12 @@ public final class AuthClient: Sendable {
898914
url: configuration.url.appendingPathComponent("verify"),
899915
method: .post,
900916
query: [
901-
(redirectTo ?? configuration.redirectToURL).map { URLQueryItem(
902-
name: "redirect_to",
903-
value: $0.absoluteString
904-
) },
917+
(redirectTo ?? configuration.redirectToURL).map {
918+
URLQueryItem(
919+
name: "redirect_to",
920+
value: $0.absoluteString
921+
)
922+
}
905923
].compactMap { $0 },
906924
body: configuration.encoder.encode(
907925
VerifyOTPParams.email(
@@ -991,10 +1009,12 @@ public final class AuthClient: Sendable {
9911009
url: configuration.url.appendingPathComponent("resend"),
9921010
method: .post,
9931011
query: [
994-
(emailRedirectTo ?? configuration.redirectToURL).map { URLQueryItem(
995-
name: "redirect_to",
996-
value: $0.absoluteString
997-
) },
1012+
(emailRedirectTo ?? configuration.redirectToURL).map {
1013+
URLQueryItem(
1014+
name: "redirect_to",
1015+
value: $0.absoluteString
1016+
)
1017+
}
9981018
].compactMap { $0 },
9991019
body: configuration.encoder.encode(
10001020
ResendEmailParams(
@@ -1078,10 +1098,12 @@ public final class AuthClient: Sendable {
10781098
url: configuration.url.appendingPathComponent("user"),
10791099
method: .put,
10801100
query: [
1081-
(redirectTo ?? configuration.redirectToURL).map { URLQueryItem(
1082-
name: "redirect_to",
1083-
value: $0.absoluteString
1084-
) },
1101+
(redirectTo ?? configuration.redirectToURL).map {
1102+
URLQueryItem(
1103+
name: "redirect_to",
1104+
value: $0.absoluteString
1105+
)
1106+
}
10851107
].compactMap { $0 },
10861108
body: configuration.encoder.encode(user)
10871109
)
@@ -1213,10 +1235,12 @@ public final class AuthClient: Sendable {
12131235
url: configuration.url.appendingPathComponent("recover"),
12141236
method: .post,
12151237
query: [
1216-
(redirectTo ?? configuration.redirectToURL).map { URLQueryItem(
1217-
name: "redirect_to",
1218-
value: $0.absoluteString
1219-
) },
1238+
(redirectTo ?? configuration.redirectToURL).map {
1239+
URLQueryItem(
1240+
name: "redirect_to",
1241+
value: $0.absoluteString
1242+
)
1243+
}
12201244
].compactMap { $0 },
12211245
body: configuration.encoder.encode(
12221246
RecoverParams(
@@ -1300,7 +1324,7 @@ public final class AuthClient: Sendable {
13001324
}
13011325

13021326
var queryItems: [URLQueryItem] = [
1303-
URLQueryItem(name: "provider", value: provider.rawValue),
1327+
URLQueryItem(name: "provider", value: provider.rawValue)
13041328
]
13051329

13061330
if let scopes {

Sources/Storage/StorageFileApi.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,8 @@ enum FileUpload {
5151
}
5252

5353
#if DEBUG
54-
#if compiler(>=6)
55-
// It is safe to mark it as unsafe, since this property is only used in tests for overriding the
56-
// boundary value, instead of using the random one.
57-
nonisolated(unsafe) var testingBoundary: String?
58-
#else
59-
var testingBoundary: String?
60-
#endif
54+
import ConcurrencyExtras
55+
let testingBoundary = LockIsolated<String?>(nil)
6156
#endif
6257

6358
/// Supabase Storage File API
@@ -94,7 +89,7 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
9489
headers[.duplex] = options.duplex
9590

9691
#if DEBUG
97-
let formData = MultipartFormData(boundary: testingBoundary)
92+
let formData = MultipartFormData(boundary: testingBoundary.value)
9893
#else
9994
let formData = MultipartFormData()
10095
#endif

Tests/StorageTests/SupabaseStorageTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ final class SupabaseStorageTests: XCTestCase {
9494

9595
#if !os(Linux)
9696
func testUploadData() async throws {
97-
testingBoundary = "alamofire.boundary.c21f947c1c7b0c57"
97+
testingBoundary.setValue("alamofire.boundary.c21f947c1c7b0c57")
9898

9999
sessionMock.fetch = { request in
100100
assertInlineSnapshot(of: request, as: .curl) {
@@ -155,7 +155,7 @@ final class SupabaseStorageTests: XCTestCase {
155155
}
156156

157157
func testUploadFileURL() async throws {
158-
testingBoundary = "alamofire.boundary.c21f947c1c7b0c57"
158+
testingBoundary.setValue("alamofire.boundary.c21f947c1c7b0c57")
159159

160160
sessionMock.fetch = { request in
161161
assertInlineSnapshot(of: request, as: .curl) {

0 commit comments

Comments
 (0)