Swift 6.1 and "redefinition of module"

After upgrading (Xcode) to Swift 6.1, one of my projects failed to compile.
It prompted redefinition of module 'CLib' during compilation.

The simplified project (source code can be found here MacroTest) is like this:

  • CLib
  • MyLib
    • CLib
    • MyMacro
  • MyMacro
    • CLib

In short, MyMacro (marco) and MyLib (target) depend on the same C target.

The compilation log is as follows:

$ swift --version
swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

$ swift build
[1/1] Planning build
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
<REDACTED>/CLib-tool.build/module.modulemap:1:8: error: redefinition of module 'CLib'
module CLib {
       ^
<REDACTED>/CLib.build/module.modulemap:1:8: note: previously defined here
module CLib {
       ^
<REDACTED>/CLib-tool.build/module.modulemap:1:8: error: redefinition of module 'CLib'
module CLib {
       ^
<REDACTED>/CLib.build/module.modulemap:1:8: note: previously defined here
module CLib {
       ^

Xcode 16.3 uses a different compilation strategy and only generates one modulemap, which can compile successfully.
Swift 6.0.3 can also compile successfully.

Could you raise an issue on swiftlang/swift-package-manager on GitHub?

Of course, I will do it as soon as possible. Is there any temporary solution before the problem is solved?

I guess the only possible way is to use Xcode or downgrade.

Done: swift build failed when marco and target depend on the same C target

Thanks, I'll take a look as soon as I can. As I investigate and if I see any workarounds, I'll comment on the GH issue.