drekka
drekka

Reputation: 21883

Swift macros in multiple SPM modules fail compilation of main project with :"Multiple command produce …" on the swift-syntax modules

I have a large multi-module project with multiple SPM modules in an Xcode workspace with the app project that uses them. For illustrative purposes, something like this:

AppProject (Xcode)
  +-- Sources
  +-- Modules (SPM)
        +-- ModuleA
              +-- Package.swift
              +-- Sources
              +-- Macros
        +-- ModuleC
              +-- Package.swift
              +-- Sources
              +-- Macros
        +-- ModuleC
              +-- Package.swift
              +-- Sources
              +-- Macros

In each of the package files I'm importing swift-syntax and using it in a macro target. Something like this:

let package = Package(
    name: "ModuleA",

    platforms: [
        .macOS(.v12),
        .iOS(.v15),
    ],

    products: [
        .library(name: "ModuleA", targets: ["ModuleA"]),
    ],

    dependencies: [
        .package(url: "https://github.com/swiftlang/swift-syntax", from: "510.0.0"),
    ],

    targets: [

        .target(
            name: "ModuleA",
            dependencies: [
                "ModuleAMacros",
            ],
            path: "Sources"
        ),
        .macro(
            name: "ModuleAMacros",
            dependencies: [
                .product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
                .product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
            ],
            path: "Macros"
        ),
    ])

So far so good. I can code, debug and test the macros in their modules without issues.

However, when I switch to the app scheme and attempt to compile it I get a massive number of errors related to multiple copying of the Swift syntax frameworks:

Prepare build
error: Multiple commands produce '/Users/clarkson/Library/Developer/Xcode/DerivedData/…/Build/Products/Debug/Frameworks/SwiftBasicFormat.framework'
    note: Target 'ModuleAMacros' (project 'ModuleA') has copy command from '/Users/clarkson/Library/Developer/Xcode/DerivedData/…/Build/Products/Debug/PackageFrameworks/SwiftBasicFormat.framework' to '/Users/clarkson/Library/Developer/Xcode/DerivedData/…/Build/Products/Debug/Frameworks/SwiftBasicFormat.framework'
    note: Target 'ModuleBMacros' (project 'ModuleB') has copy command from '/Users/clarkson/Library/Developer/Xcode/DerivedData/…/Build/Products/Debug/PackageFrameworks/SwiftBasicFormat.framework' to '/Users/clarkson/Library/Developer/Xcode/DerivedData/…/Build/Products/Debug/Frameworks/SwiftBasicFormat.framework'
    note: Target 'ModuleCMacros' (project 'ModuleC') has copy command from '/Users/clarkson/Library/Developer/Xcode/DerivedData/…/Build/Products/Debug/PackageFrameworks/SwiftBasicFormat.framework' to '/Users/clarkson/Library/Developer/Xcode/DerivedData/…/Build/Products/Debug/Frameworks/SwiftBasicFormat.framework'
… and so on for all the other swift-syntax frameworks

I can't fathom out how to resolve this or why it's happening. Has anyone encountered and solved this problem?

Upvotes: 0

Views: 64

Answers (0)

Related Questions