Skip to content

Adopt Swift 6 and Xcode 16#322

Merged
dfed merged 16 commits intomasterfrom
dfed--swift-6
Oct 19, 2024
Merged

Adopt Swift 6 and Xcode 16#322
dfed merged 16 commits intomasterfrom
dfed--swift-6

Conversation

@dfed
Copy link
Copy Markdown
Collaborator

@dfed dfed commented Oct 11, 2024

Breaking change! Gets us running on Xcode 16, dropping support for prior Xcode versions. Fixes all consumer-facing warnings regardless of build system, belatedly addressing #294. Also (see inline comments) removes API for tvOS and watchOS that likely never worked given warnings received when compiling on Xcode 16.

Getting on Swift 6 allows us to use typed throws. Utilizing typed throws feels like the right move given that we haven't seen a change to what errors we throw in seven years.

@dfed dfed self-assigned this Oct 11, 2024
Comment on lines +9 to +12
.iOS(.v12),
.tvOS(.v12),
.watchOS(.v4),
.macOS(.v10_13),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimum versions in Xcode 16 updated

if !userPrompt.isEmpty {
secItemQuery[kSecUseOperationPrompt as String] = userPrompt
let context = LAContext()
context.localizedReason = userPrompt
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigh. this API doesn't exist on either tvOS or watchOS. the methods that call into this method no longer expose the userPrompt

/// - Throws: An error of type `KeychainError`.
@objc
public func object(forKey key: String, withPrompt userPrompt: String) throws -> Data {
try execute(in: lock) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swift 6 can't rethrow with a typed error, so we just inline the helper here and elsewhere


extension SecureEnclaveIntegrationTests {

@available (*, deprecated)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

funnily enough, this space is now a warning

@@ -1,20 +0,0 @@
#!/bin/bash -l
Copy link
Copy Markdown
Collaborator Author

@dfed dfed Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed on recent Xcodes!

// limitations under the License.
//

#import "VALLegacyValet.h"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops. Xcode is warning about these malformed imports now, which is long overdue!

@dfed dfed marked this pull request as ready for review October 11, 2024 08:11
@dfed dfed requested a review from NickEntin October 11, 2024 21:09
removeQueueExpectation.fulfill()
}

waitForExpectations(timeout: 10.0, handler: nil)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xcode is pushing us towards the fulfillment method below now.


for _ in 1...50 {
setQueue.async {
setQueue.async { [vanillaValet, passcode, key] in
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self isn't Sendable, so we capture what we need rather than self

// MARK: Shared Access Group

static var sharedAccessGroupIdentifier: SharedGroupIdentifier = {
static let sharedAccessGroupIdentifier: SharedGroupIdentifier = {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these were never set. not sure why I made them var to begin with, but... easy fix!

try migrateObjects(matching: valet.baseKeychainQuery, removeOnCompletion: removeOnCompletion)
}

// MARK: Renamed Methods
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were renamed in more than four years ago in the V4 release. Open to keeping them around but doing some roomba-ing.


## Migrating from prior Valet versions

The good news: most Valet configurations do _not_ have to migrate keychain data when upgrading from an older version of Valet. All Valet objects are backwards compatible with their counterparts from prior versions. We have exhaustive unit tests to prove it (search for `test_backwardsCompatibility`). Valets that have had their configurations deprecated by Apple will need to migrate stored data.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the exhaustive tests required the v2 (objc) version of Valet to live forever without changes, and these old files were utilizing deprecated API. We maintained these tests for the better part of a decade. We successfully managed to deploy a rewrite in Swift without regression years ago. Time to let go.

import Foundation


internal final class WeakStorage<T: AnyObject>: @unchecked Sendable {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thread-safe because the underlying storage is only ever accessed or modified within a lock.

}

/// - Parameters:
/// - identifier: A non-empty string that must correspond with the value for keychain-access-groups in your Entitlements file.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We missed updating these in #297.

@dfed dfed merged commit 23bad01 into master Oct 19, 2024
@dfed dfed deleted the dfed--swift-6 branch October 19, 2024 04:30
@dfed dfed mentioned this pull request Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant