Skip to content

swift build failed when macro and target depend on the same C target #8436

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

Closed
1 task done
qazyn951230 opened this issue Apr 1, 2025 · 4 comments
Closed
1 task done

Comments

@qazyn951230
Copy link

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

When marco and target depend on the same C target, running swift build will produce a redefinition of module error.

A minimal example can be found here. The project structure is as follows:

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

MyLib and MyMacro only import CLib and have no other code.

Expected behavior

Compiled successfully.

Actual behavior

$ 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 {
       ^

Steps to reproduce

  1. git clone https://github.com/qazyn951230/MacroTest.git
  2. cd MacroTest
  3. swift build

Swift Package Manager version/commit hash

6.1.0

Swift & OS version (output of swift --version ; uname -a)

Swift 6.1 from Xcode 16.3

$ 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
@qazyn951230 qazyn951230 added the bug label Apr 1, 2025
@dschaefer2 dschaefer2 changed the title swift build failed when marco and target depend on the same C target swift build failed when macro and target depend on the same C target Apr 9, 2025
@dschaefer2
Copy link
Member

I see. We are picking up the dependencies from the macros and plugins and hooking them up. That's why we get them twice. I'll fix up the algorithm.

@qazyn951230
Copy link
Author

@dschaefer2 I'm glad you fixed it. Should it be cherry-picked into the branch "release/6.2" since it's a bug fix?

@dschaefer2
Copy link
Member

Fixed by #8472

@dschaefer2
Copy link
Member

@qazyn951230 We'll be merging all changes in main to release/6.2 for the next few weeks. Just waiting to see if we get an auto merger first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants