# BuildToolPlugin 'Multiple commands produce ...' error when embedding wachOS app in iOS app target

**URL:** <https://forums.swift.org/t/buildtoolplugin-multiple-commands-produce-error-when-embedding-wachos-app-in-ios-app-target/71437>\
**Category:** Package Manager\
**Created:** [April 24, 2024, 8:58am UTC](https://forums.swift.org/t/buildtoolplugin-multiple-commands-produce-error-when-embedding-wachos-app-in-ios-app-target/71437 "2024-04-24T08:58:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![liamnichols](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/liamnichols/32/6570_2.png) [@liamnichols](https://forums.swift.org/u/liamnichols)\
**Post date:** [April 24, 2024, 8:58am UTC](https://forums.swift.org/t/buildtoolplugin-multiple-commands-produce-error-when-embedding-wachos-app-in-ios-app-target/71437/1 "2024-04-24T08:58:08Z")

</div>

I'm an author of a tool called [xcstrings-tool](https://github.com/liamnichols/xcstrings-tool) that offers a `BuildToolPlugin` to generate Swift source code for accessing localized strings that are declared in an Xcode Strings Catalog.

While BuildTool Plugins have some rough edges, things are mostly great however a user of my tool reported a tricky issue recently:

> <https://github.com/liamnichols/xcstrings-tool/issues/57>
>
> There seems to be an issue when a Package integrates XCStrings Tool and that pac…kage target is linked into both an iOS app and a watchOS app.
> 
> I was able to reproduce a project with the issue here: https://github.com/liamnichols/xcstrings-tool-demo/compare/ln/embedded-watch-app

When using my Build Tool Plugin as a dependency on a Swift Package Target that in turn is a dependency of both the iOS app target and the embedded watchOS app target, the graph fails to build with an error “_Multiple Commands produce '...'_”.

The file that the error references is the file that my plugin writes into the `pluginWorkDirectory`.

I traced the issue back, and it seems that because the iOS app target embeds the watchOS app target via the “_Embed Watch Contents_” build phase, the SPM target must be compiled twice. Once for iOS and again for watchOS.

When doing this, the build tool plugin is invoked twice for the SPM target within the same build, which is what causes the original error.

The problem is however that it's necessary for the build to happen twice, and what I really need is to output the generated source into two different locations but my `BuildToolPlugin` doesn't seem to have enough power to do that.

The `PluginContext`/`Target` doesn't provide enough information for me to make my own unique output subdirectories, so it seems that really I probably want SPM to return `pluginWorkDirectory` as something more unique.

I raised FB13750966 because technically this is an Xcode issue since I can't reproduce the same scenario using `swift build`, but really I think that this is still partially an SPM specific issue.

I'm wondering if anybody here has any creative workarounds that I might have missed. The full feedback as well as a reproducible sample can be found in the GitHub issue linked above. Thanks!

---

<div class="post-metadata">

**Author:** ![code-per-day](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/code-per-day/32/32158_2.png) [@code-per-day](https://forums.swift.org/u/code-per-day)\
**Post date:** [April 25, 2024, 6:44pm UTC](https://forums.swift.org/t/buildtoolplugin-multiple-commands-produce-error-when-embedding-wachos-app-in-ios-app-target/71437/2 "2024-04-25T18:44:35Z")

</div>

I've been having the same issue with a company project using SwiftPM build tools. Same package and iOS/watchOS app setup, also for localization. Can't reproduce with `swift build` but that's because `swift build` doesn't know how to build the app's Xcode project.

Also for a time had trouble with generated `.lproj` folders from the app target weren't top-level and so weren't merged into the `.main` bundle. I believe this was fixed but I don't quite remember since we're using another solution for now.

---

<div class="post-metadata">

**Author:** ![Lancelotbronner](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lancelotbronner/32/22071_2.png) [@Lancelotbronner](https://forums.swift.org/u/Lancelotbronner)\
**Post date:** [May 28, 2024, 4:49pm UTC](https://forums.swift.org/t/buildtoolplugin-multiple-commands-produce-error-when-embedding-wachos-app-in-ios-app-target/71437/3 "2024-05-28T16:49:11Z")

</div>

Sorry for the ping @Max_Desiatov (since you're in SwiftPM's code owners), I would like to confirm that this issue is at least known? And if you potentially knew of a workaround.

---

<div class="post-metadata">

**Author:** ![Lancelotbronner](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lancelotbronner/32/22071_2.png) [@Lancelotbronner](https://forums.swift.org/u/Lancelotbronner)\
**Post date:** [July 15, 2024, 6:13pm UTC](https://forums.swift.org/t/buildtoolplugin-multiple-commands-produce-error-when-embedding-wachos-app-in-ios-app-target/71437/4 "2024-07-15T18:13:03Z")

</div>

Update: This still isn't fixed in Xcode 16.

---

<div class="post-metadata">

**Author:** ![c0dedbear](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/c0dedbear/32/41161_2.png) [@c0dedbear](https://forums.swift.org/u/c0dedbear)\
**Post date:** [June 9, 2025, 1:05pm UTC](https://forums.swift.org/t/buildtoolplugin-multiple-commands-produce-error-when-embedding-wachos-app-in-ios-app-target/71437/5 "2025-06-09T13:05:27Z")

</div>

The issue still exists in Xcode 16.4

---

<div class="post-metadata">

**Author:** ![maximkrouk](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maximkrouk/32/33394_2.png) [@maximkrouk](https://forums.swift.org/u/maximkrouk)\
**Post date:** [September 30, 2026, 1:37pm UTC](https://forums.swift.org/t/buildtoolplugin-multiple-commands-produce-error-when-embedding-wachos-app-in-ios-app-target/71437/6 "2026-09-30T13:37:15Z")

</div>

I also have a [package-resources-cli](https://github.com/capturecontext/package-resources-cli) codegen and faced the same issue on Xcode 27 🫠

And there is a workaround - plugin runs have to be done separately for iOS and watchOS, so we need 2 separate targets and conditional imports, this will allow one parent target to be reusable for iOS and watchOS.

Example:

- I used to have an `AppUI` target, that is shared between iOS and watchOS app and had resources, processed with a plugin
- I extracted resources to `AppUIResources` target
- I created `AppUIResourcesWatchOS` target with a path, pointing to `AppUIResources`directory to have a single source of truth on the disk
- Those resources targets use a plugin to process resources, plugin writes to target build directory, so generated boilerplate does not overlap in the build graph
- `AppUI` now conditionally imports corresponding resources targets and conditionally reexports them using `#if canImport` and `@_exported import`
