Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode preview fails to build with errors #101

Closed
drmarkpowell opened this issue Feb 1, 2022 · 8 comments
Closed

Xcode preview fails to build with errors #101

drmarkpowell opened this issue Feb 1, 2022 · 8 comments

Comments

@drmarkpowell
Copy link

Describe the bug
Adding mqtt-nio dependency to iOS project breaks SwiftUI Previews

To Reproduce
Steps to reproduce the behavior:

  1. Create a new iOS app project in Xcode
  2. Add mqtt-nio dependency in Swift packages to the app project
  3. open ContentView.swift and refresh the Preview. This generates 11 errors :

Undefined symbol: nominal type descriptor for NIOSSL.NIOSSLCertificate
Undefined symbol: nominal type descriptor for NIOSSL.NIOSSLClientTLSProvider
Undefined symbol: NIOSSL.NIOSSLCertificate.toDERBytes() throws -> [Swift.UInt8]
Undefined symbol: static NIOSSL.NIOSSLCertificate.fromPEMFile(Swift.String) throws -> [NIOSSL.NIOSSLCertificate]
Undefined symbol: type metadata accessor for NIOSSL.NIOSSLContext
Undefined symbol: nominal type descriptor for NIOSSL.TLSConfiguration
Undefined symbol: protocol conformance descriptor for NIOSSL.NIOSSLClientTLSProvider : NIOCore.NIOClientTLSProvider in NIOSSL
Undefined symbol: type metadata accessor for NIOSSL.NIOSSLCertificate
Undefined symbol: NIOSSL.NIOSSLContext.__allocating_init(configuration: NIOSSL.TLSConfiguration) throws -> NIOSSL.NIOSSLContext
Undefined symbol: static NIOSSL.TLSConfiguration.makeClientConfiguration() -> NIOSSL.TLSConfiguration
Undefined symbol: NIOSSL.NIOSSLClientTLSProvider.init(context: NIOSSL.NIOSSLContext, serverHostname: Swift.String?, customVerificationCallback: (([NIOSSL.NIOSSLCertificate], NIOCore.EventLoopPromise<NIOSSL.NIOSSLVerificationResult>) -> ())?) throws -> NIOSSL.NIOSSLClientTLSProvider

Expected behavior
mqtt-nio builds and runs fine in the iOS simulator and on a real iOS device but breaks previews in Xcode...the preview simulator fails with errors on the build.

Context (please complete the following information):

  • Platform [e.g. iOS, macOS, Linux] iOS
  • Swift/Xcode Version: Xcode 13.2.1
  • Version [e.g. 1.2.0] mqtt-nio latest 2.5.2

Additional context
I am filing a feedback with Apple as well, as it's equally likely that it's their tool that's broken as the code in mqtt-nio builds and run fine outside of Xcode Preview.

@drmarkpowell
Copy link
Author

Filed feedback FB9873153 with Apple on Xcode 13.2.1 about these errors in Xcode Preview.

@adam-fowler
Copy link
Collaborator

One thing which might be worthwhile adding to the feedback is NIOSSL is conditional added to the MQTTNIO target as a dependency based on platform ie it is only used for macOS, and Linux and shouldn't be linked with the iOS target. I control this via the following line in the Package.swift

.product(name: "NIOSSL", package: "swift-nio-ssl", condition: .when(platforms: [.linux, .macOS])),

@drmarkpowell
Copy link
Author

drmarkpowell commented Feb 2, 2022 via email

@adam-fowler
Copy link
Collaborator

adam-fowler commented Feb 2, 2022

You will need the condition when building a release. Apparently signing applications that include NIOSSL is problematic.

See #19

@obriensp
Copy link
Contributor

obriensp commented Feb 5, 2022

The link errors are coming from some blocks of code in mqtt-nio that are wrapped in #if canImport(NIOSSL). Tweaking the conditional to #if canImport(NIOSSL) && (os(macOS) || os(Linux)) resolves the errors, which makes me think that when building for SwiftUI Previews NIOSSL is "available" according to the Swift compiler but doesn't get linked in because of the SPM conditional.

@adam-fowler Is that updated #if an acceptable fix or is there a better way to express the intent for those parts of the code? Let me know and I can open a PR.

obriensp pushed a commit to obriensp/mqtt-nio that referenced this issue Feb 9, 2022
@adam-fowler
Copy link
Collaborator

@drmarkpowell can you add the details about the canImport returning the wrong value during SwiftUI previews to your feedback with Apple.

obriensp pushed a commit to obriensp/mqtt-nio that referenced this issue Feb 10, 2022
obriensp pushed a commit to obriensp/mqtt-nio that referenced this issue Feb 14, 2022
@drmarkpowell
Copy link
Author

included in the feedback: copied the comment from @obriensp and linked to this issue. Thanks!

@adam-fowler
Copy link
Collaborator

The fix is now in release 2.5.3

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

No branches or pull requests

3 participants