Skip to content

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

Closed
@qazyn951230

Description

@qazyn951230

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions