Skip to content

Conversation

@simonjbeaumont
Copy link
Contributor

Motivation

When building this project for Apple platforms other than macOS, the build failed for a couple of reasons. First, NIOSSHServer requires Foundation.Process which is only available on macOS. Second, the tests are making use of an CryptoKit API that's only present on iOS 13.2 (and aligned other versions), which is newer than the 13.0 stated in the Package.swift:

error: Cannot find type 'Process' in scope
...
error: 'isValidAuthenticationCode(_:authenticating:using:)' is only available in iOS 13.2 or newer

Modifications

  • Wrap all the code in NIOSSHServer with #if canImport(Foundation.Process) and, in main.swift, throw a fatalError with a helpful message.
  • Add missing availability guards in test code. I've tried to keep them as scoped as possible.

Result

Source and tests can now build on Apple platforms other than macOS.

@simonjbeaumont simonjbeaumont force-pushed the sb/fix-build-on-apple-platforms branch from 5b4d0d0 to 7243288 Compare December 18, 2023 09:20
//
//===----------------------------------------------------------------------===//

#if canImport(Foundation.Process)
Copy link
Member

Choose a reason for hiding this comment

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

TIL that you can import check types and not only modules.

With that being said, why don't we use @available instead like we do in tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because that doesn't stop it trying to compile the code. If Foundation.Process was present on e.g. iOS but not available, then we could use @available here too, but it is simply not present in the iOS SDK (and others), so we must use a compiler directive.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense! Thanks

@simonjbeaumont simonjbeaumont merged commit d7d410f into apple:main Dec 18, 2023
@Lukasa Lukasa added the semver/none No version bump required. label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/none No version bump required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants