Swift tests fails with duplicate symbol when depending a 2 libraries that use build plugins

I have this code set up

  • C
    • has plugin that generates some code before build
  • X
  • has similar plugin

package that depend on X and C

Now when I run the tests in Xcode all green. Running swift test from commandline give weird error

Building for debugging...
duplicate symbol '_async_MainTu' in:
ld: 1 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[1766/1767] Linking packageTests
error: fatalError

I have no clue how to solve this. Do you?

There were some fixes recently regarding plugin dependency trees being linked into the final binary which could be the cause of this issue. I'd suggest using swift 5.9 and updating the tools version in your packages to match.

Thank you should have clarified. I tested it with swift version 5.9 but in package.swift it is 5.7. I changed it to 5.9 as you suggested.

This did change the output so I can confirm that the initial problem with actually running the plugin is fixed. However there seams to be still a problem as the generated code of X and C does not link.

Resulting in error output like this

  _symbolic _____ 19PluginX14V in Pluglin.swift.o

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

Unfortunately I cannot share the code as it is proprietary but as the project builds in xcode just fine it seams there is a problem still in swift 5.9?

As for me I'm in removing the plugin from one of the targets and generated the code before building for that target. This resolves the issue but is inconvenient.

So I hope this super awesome feature of plugins still gets some love and will happily test again if there is a fix.

@NeoNacho Maybe could provide more help? I am not familiar with this error. Is there anyway you could make a reduced shareable example?

Difficult at the moment due to deadline but in short

  1. cli tool depends on 2 libs from 2 packages
  2. both libs have plugins that generate code for the packages using ArgumentParser
  3. swift build -> success
  4. xcode test package -> success
  5. swift test -> weird issue symbolic reference fail

I hope to find time to build a small package like that but for now this is all the info I have and I have to continue with my workaround.

Thanks for any help!