Swiftly toolchains not gating Apple Platform Frameworks correctly
My understanding is that when using the open source toolchains installed by Swiftly, it should not see frameworks specific to Apple Platforms, e.g. AuthenticationServices However this isn't matching up with what I'm seeing.
Code that compiles fine with Xcode and on Linux fails compilation from the command line on macOS via Swiftly.
Steps to Reproduce:
- Checkout https://github.com/ChimeHQ/OAuthenticator - reproducible on
618971d4d341650db664925fd0479032294064ad - Install Swiftly and a toolchain, e.g.
swiftly install 6.2.0 && swiftly use 6.2.0 - Try and build -
swift build
Expected results:
It should compile correctly
Actual Results:
➜ OAuthenticator git:(main) ✗ swift build
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
/Users/timc/Developer/OAuthenticator/Sources/OAuthenticator/WebAuthenticationSession+Utility.swift:7:11: error: cannot find type 'WebAuthenticationSession' in scope
5 |
6 | @available(macOS 13.3, iOS 16.4, watchOS 9.4, macCatalyst 16.4, tvOS 16.4, *)
7 | extension WebAuthenticationSession {
| `- error: cannot find type 'WebAuthenticationSession' in scope
8 | public func userAuthenticator(preferredBrowserSession: BrowserSession? = nil) -> Authenticator.UserAuthenticator {
9 | return {
/Users/timc/Developer/OAuthenticator/Sources/OAuthenticator/WebAuthenticationSession+Utility.swift:7:11: error: cannot find type 'WebAuthenticationSession' in scope
5 |
6 | @available(macOS 13.3, iOS 16.4, watchOS 9.4, macCatalyst 16.4, tvOS 16.4, *)
7 | extension WebAuthenticationSession {
| `- error: cannot find type 'WebAuthenticationSession' in scope
8 | public func userAuthenticator(preferredBrowserSession: BrowserSession? = nil) -> Authenticator.UserAuthenticator {
9 | return {
/Users/timc/Developer/OAuthenticator/Sources/OAuthenticator/WebAuthenticationSession+Utility.swift:8:57: error: cannot find type 'BrowserSession' in scope
6 | @available(macOS 13.3, iOS 16.4, watchOS 9.4, macCatalyst 16.4, tvOS 16.4, *)
7 | extension WebAuthenticationSession {
8 | public func userAuthenticator(preferredBrowserSession: BrowserSession? = nil) -> Authenticator.UserAuthenticator {
| `- error: cannot find type 'BrowserSession' in scope
9 | return {
10 | try await self.authenticate(using: $0, callbackURLScheme: $1, preferredBrowserSession: preferredBrowserSession)
[3/3] Compiling OAuthenticator WebAuthenticationSession+Utility.swift
Note - the file uses an if canImport() gate which should not compile the file when it can't see the symbols. That gate passes but then compilation fails
It should either be able to see the frameworks and compile fine and see those symbols or not see the framework and ignore the file
My understanding is that when using the open source toolchains installed by Swiftly, it should not see frameworks specific to Apple Platforms, e.g. AuthenticationServices
This is untrue.
The toolchain doesn't get you access to macOS APIs, the SDK does that (which you get by installing either the Developer Command Line Tools package, or Xcode). A Swift.org toolchain alone can't compile for macOS at all.
What version of Xcode and/or the DCLT do you have installed?
Also, this issue would be better placed in swiftlang/swift-package-manager as a starting point. swiftly just installs the Swift toolchain; it isn't responsible for build behavior.
@jakepetroules, the same happens when:
- In Xcode install 6.2 or nightly toolchain from https://www.swift.org/install/macos/
- Selecting the installed toolchain
- Building minimal extension on SwiftUI
#if canImport(AuthenticationServices)
import AuthenticationServices
import SwiftUI
@available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *)
extension WebAuthenticationSession { }
#endif
Should the issue be created on swift-package-manager or swift? It seems the toolchain shipped with Xcode does have include AuthenticationServices.swiftmodule; while the nightly does not; but then the canImport succeeds. So not sure the best place for it to go