Missing symbols from package in Xcode preview/playground

I'm having a strange issue with a package of my own that I'm working on and I'm unsure if this is a bug in Swift 5.3, Xcode 12b (most likely) or if I'm just doing something wrong.

I have a library that I'm working on called Validations. It has a dependency on a library called Validated, which in turn has a dependency on a library called NonEmpty.

My Package.swift file is here:

To test everything is OK with the package, I created an example Xcode project - just an empty SwiftUI app - using Xcode 11 and added my package using Xcode's package management facility. I can build and run the project in the simulator and the Xcode previews are working fine.

If I open the same project in Xcode 12, I can still build the project and run it in the simulator but if I try and load an Xcode preview, it fails with the following error:

linker command failed with exit code 1 (use -v to see invocation)

----------------------------------------

SchemeBuildError: Failed to build the scheme "ExampleApp"

linker command failed with exit code 1 (use -v to see invocation)

Link Validations (x86_64):
Undefined symbols for architecture x86_64:
  "protocol conformance descriptor for NonEmpty.NonEmpty<A> : Swift.Sequence in NonEmpty", referenced from:
      (extension in Validations):Validated.Validated.reduceErrors<A>(A1, (A1, B) -> A1) -> Validated.Validated<A, A1> in Validations.o
  "type metadata accessor for NonEmpty.NonEmpty", referenced from:
      (extension in Validations):Validated.Validated.mapErrors<A>((B) -> A1) -> Validated.Validated<A, A1> in Validations.o
      (extension in Validations):Validated.Validated.reduceErrors<A>(A1, (A1, B) -> A1) -> Validated.Validated<A, A1> in Validations.o
      closure #1 (A1) -> Validated.Validated<A1, B> in Validations.ValidatorOf.pullback<A>((A1) -> A) -> Validations.ValidatorOf<A1, B> in Validations.o
      closure #1 (A?) -> Validated.Validated<A?, B> in Validations.ValidatorOf.optional(errorOnNil: B?) -> Validations.ValidatorOf<A?, B> in Validations.o
      closure #1 (A) -> Validated.Validated<A, B> in Validations.ValidatorOf.negated(withError: B) -> Validations.ValidatorOf<A, B> in Validations.o
      closure #1 (A) -> Validated.Validated<A, A1> in Validations.ValidatorOf.mapErrors<A>((B) -> A1) -> Validations.ValidatorOf<A, A1> in Validations.o
      closure #1 (A) -> Validated.Validated<A, A1> in Validations.ValidatorOf.reduceErrors<A>(_: A1, reducer: (A1, B) -> A1) -> Validations.ValidatorOf<A, A1> in Validations.o
      ...
  "NonEmpty.NonEmpty.map<A>((A.Element) throws -> A1) throws -> NonEmpty.NonEmpty<[A1]>", referenced from:
      (extension in Validations):Validated.Validated.mapErrors<A>((B) -> A1) -> Validated.Validated<A, A1> in Validations.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have the same problem with Xcode's new playground support for Swift packages - if I create an empty playground, check the "Build Active Scheme" box and try and run the playground it fails with the same error as above.

Any pointers here would be helpful - am I doing something wrong, or is this a bug in Xcode 12 that should be reported via the Feedback Assistant?

Just wondering if this is specifically related to me having an extension to the Validated type (which comes from the Validated library dependency) inside my own library, as each of those missing symbol errors seem to reference it?

This seems like a bug to me, would be great if you could file a report for it.

Sure, happy to - to the Swift bug tracker or via Feedback Assistant, or both?

Also, I'm not sure if this is related but if I open my package in Xcode 12, create a playground and check the new "Build active scheme" checkbox, I get the same error. I'll mention that in my bug report.

Feedback Assistant, since the preview support is part of Xcode. Thanks!

Feedback assistant number FB7841981

@NeoNacho I don't suppose you're able to confirm whether or not this is a bug with Swift, or Xcode and definitely not a bug in my library? I'm still seeing this problem in beta 3 (and beta 2).

I consider this an Xcode bug, since the regular build and previews should behave the same.

It does however stem from the fact that Validations is directly importing NonEmpty without declaring a dependency, you can probably work around it by adding an explicit dependency.

1 Like

@NeoNacho thanks for confirming and yes, your workaround of adding an explicit dependency to my library does seem to have fixed the problem for now.

The issue should be resolved in Xcode 12 beta 5.

1 Like

Thanks, I just got the update in Feedback Assistant too. I will look into checking this tomorrow (also got my fingers crossed for FB8116155).

Any updates on this? Been running into a similar issue in Xcode 12.2 where Previews can't find a linked dynamic library that's defined as a Swift package, even though it's embedded in the preview app whose scheme is active.