# Using build tool plugin in the project with many targets

**URL:** <https://forums.swift.org/t/using-build-tool-plugin-in-the-project-with-many-targets/66329>\
**Category:** Package Manager\
**Tags:** packagemanager, buildtoolplugin\
**Created:** [July 24, 2023, 2:20pm UTC](https://forums.swift.org/t/using-build-tool-plugin-in-the-project-with-many-targets/66329 "2023-07-24T14:20:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomassliz](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tomassliz/32/45668_2.png) [@tomassliz](https://forums.swift.org/u/tomassliz)\
**Post date:** [July 24, 2023, 2:20pm UTC](https://forums.swift.org/t/using-build-tool-plugin-in-the-project-with-many-targets/66329/1 "2023-07-24T14:20:57Z")

</div>

Hello,

I created a custom build tool plugin (linter) and I would love to run it for all my targets. My project contains 4 Swift packages and each of them contains a lot of targets. When I use the plugin approx. with half of them, everything works as expected. But when I apply it for one more target, Xcode freezes and the project can't be built anymore.

The [same issue](https://github.com/realm/SwiftLint/issues/4844) has been reported in the SwiftLint repository, which provides its own plugin implementation.

Is there some limit to how many packages can be used with the build tool plugin in one Xcode project?

I get the same issue with **Xcode 14.3.1** and **Xcode 15.0.0 Beta 4**.

---

<div class="post-metadata">

**Author:** ![joshw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joshw/32/34626_2.png) [@joshw](https://forums.swift.org/u/joshw)\
**Post date:** [October 19, 2023, 1:52pm UTC](https://forums.swift.org/t/using-build-tool-plugin-in-the-project-with-many-targets/66329/2 "2023-10-19T13:52:15Z")

</div>

We're also experiencing this - 1 build plugin for ~50 targets causes a 7-10 second hang before each build.

This happens even if the plugin is completely empty and does nothing, i.e.

```swift
import Foundation
import PackagePlugin

@main struct DummyPlugin: BuildToolPlugin {
    func createBuildCommands(context: PluginContext, target: Target) async throws -> [Command] {
        return [ 
            // this plugin does nothing
        ]
    }
}

```

Has anyone discovered any sort of workaround? We'd LOVE to use a build plugin for some code generation, but a 7-10 second hang per build is pretty much a deal breaker.

> Xcode Version 15.0.1 (15A507)

---

<div class="post-metadata">

**Author:** ![Max\_Desiatov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/max_desiatov/32/20654_2.png) [@Max\_Desiatov](https://forums.swift.org/u/Max_Desiatov)\
**Post date:** [October 20, 2023, 11:11am UTC](https://forums.swift.org/t/using-build-tool-plugin-in-the-project-with-many-targets/66329/3 "2023-10-20T11:11:00Z")

</div>

Is this reproducible for you with the SwiftPM CLI when using `swift build` and `swift test`?

---

<div class="post-metadata">

**Author:** ![joshw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joshw/32/34626_2.png) [@joshw](https://forums.swift.org/u/joshw)\
**Post date:** [October 20, 2023, 11:11am UTC](https://forums.swift.org/t/using-build-tool-plugin-in-the-project-with-many-targets/66329/4 "2023-10-20T11:11:49Z")

</div>

No - it's unfortunately isolated to Xcode 😭

Guess it's an Xcode, not a SPM issue.

---

<div class="post-metadata">

**Author:** ![Max\_Desiatov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/max_desiatov/32/20654_2.png) [@Max\_Desiatov](https://forums.swift.org/u/Max_Desiatov)\
**Post date:** [October 20, 2023, 11:16am UTC](https://forums.swift.org/t/using-build-tool-plugin-in-the-project-with-many-targets/66329/5 "2023-10-20T11:16:24Z")

</div>

Do you know if there's an issue filed on [https://feedbackassistant.apple.com](https://feedbackassistant.apple.com) for this? What's the FB number if so?

---

<div class="post-metadata">

**Author:** ![joshw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joshw/32/34626_2.png) [@joshw](https://forums.swift.org/u/joshw)\
**Post date:** [October 20, 2023, 11:18am UTC](https://forums.swift.org/t/using-build-tool-plugin-in-the-project-with-many-targets/66329/6 "2023-10-20T11:18:06Z")

</div>

I don't know if one got filed per [your rec here](https://github.com/apple/swift-package-manager/issues/6543) but I'll go ahead and file one myself right now and repost the number here in a moment.

Thanks for the quick responses!

---

<div class="post-metadata">

**Author:** ![joshw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joshw/32/34626_2.png) [@joshw](https://forums.swift.org/u/joshw)\
**Post date:** [October 23, 2023, 12:02pm UTC](https://forums.swift.org/t/using-build-tool-plugin-in-the-project-with-many-targets/66329/7 "2023-10-23T12:02:07Z")

</div>

Sorry for the delay @Max_Desiatov - I wanted to put together a simple to follow demo.

I filed an issue on feedback assistant, it's [13296864](https://feedbackassistant.apple.com/feedback/13296864). I also created a dummy repo to demonstrate the issue:

> **[GitHub - joshuawright11/XcodePluginHang: Demonstrates how Xcode hangs for a...](https://github.com/joshuawright11/XcodePluginHang)**
>
> Demonstrates how Xcode hangs for a while each build when building a project with a lot of dependencies, each containing a lot of files, each using an empty build plugin. - GitHub - joshuawright11/X...

Essentially - its 100 targets with 100 single line files each. The 100th target depends on the other 99. All targets use a build plugin that does nothing.

If you build the 100th target, you'll see a hang / beach ball (5.6s on my 2023 M2 Max) on EVERY build. Even ones where nothing was changed. Comment out the build plugin in the Package.swift and builds will be instant.

 ![Screenshot 2023-10-23 at 1.04.58 PM](https://global.discourse-cdn.com/swift/original/3X/2/5/25d2d82472705a6703ed8ad7082a17a57f1f13ad.jpeg)

It seems to be related to having files in each dependency - I noticed if each dependency has a single file, the builds are basically instant - even with the build plugin. Perhaps there is an inefficient file lookup going on in the background?

EDIT:

Another note; the hang only happens when building in Xcode. Using `swift build` is much more efficient (the first build took a while since it was from scratch).

 ![Screenshot 2023-10-23 at 1.10.26 PM](https://global.discourse-cdn.com/swift/original/3X/f/2/f2dc82902ed5a3986a81f3a7e8d538f91b314453.png)

---

<div class="post-metadata">

**Author:** ![joshw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joshw/32/34626_2.png) [@joshw](https://forums.swift.org/u/joshw)\
**Post date:** [October 30, 2023, 9:45am UTC](https://forums.swift.org/t/using-build-tool-plugin-in-the-project-with-many-targets/66329/8 "2023-10-30T09:45:24Z")

</div>

@Max_Desiatov out of curiosity are there any temporary workarounds that we might be able to use? Would love to use build plugins @ a large scale if it's possible.

And please let me know if there's any way I can help resolve or provide more info!

---

<div class="post-metadata">

**Author:** ![bilousoleksandr](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bilousoleksandr/32/35703_2.png) [@bilousoleksandr](https://forums.swift.org/u/bilousoleksandr)\
**Post date:** [June 5, 2024, 2:55pm UTC](https://forums.swift.org/t/using-build-tool-plugin-in-the-project-with-many-targets/66329/9 "2024-06-05T14:55:00Z")

</div>

Still have the same issue. Was trying to fix by skipping plugin run if directory hash remains the same, but even without any actions applying empty plugin takes up to 10 seconds per each SPM Package.
