Xcode fails to build app for testing when depending on transient Swift Packages

Hello team!

We have had a curious problem in the past few days where Xcode fails to build our app for testing when depending on transient Swift Packages. When building for testing, our project fails with error: "clang: No such file or directory", looking for the library in PackageFrameworks.

Raised problem to Apple as well as Feedback FB21314909.

In a sample project (as well as our main app project), the clang compiler and projects fails to build for testing, when the projects depends on a Swift Package, which depends on another Swift Package. Changing nothing else, by setting the 2-nd level package to be of type `.dynamic` resolves the issue.

Our main app target depends on target A in the Swift Package, and our test target depends on target B in the same Package. Target B also depends on target A, and target A depends on a 3rd party package.

Changing the underlying package dependency to be of dynamic type resolves this issue. This, however requires package developers to provide this option, or for us to fork them.

As far as my research goes, this could be an existing Xcode bug, in how particular libraries are statically or dynamically linked. It may also be us, not following certain principles in the way we design our dependencies. I'd like to understand further, what is happening.

We raised an issue for the GitHub package we're depending on, though I did further investigations with another package, and can exclude the package itself from being the problem. If I take the same dependencies that Jose-swift has, and add to another random package, the same problem occurs.
Please see this issue for details: Issues when using package indirectly · Issue #57 · beatt83/jose-swift · GitHub

I have reproduced this in a minimal new sample project, including screenshots and build log. I don’t see an option to attach files here. Please find a .zip of the project at the GitHub issue link above.

Any help, and more importantly, information for me to understand and learn exactly what’s happening here, is appreciated!