Skip to content
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

SwiftPM Build Tool Plugin excessively runs causing recompilation #305

Open
Brett-Best opened this issue Feb 2, 2025 · 9 comments
Open

Comments

@Brett-Best
Copy link

Brett-Best commented Feb 2, 2025

I use https://github.com/liamnichols/xcstrings-tool, this essentially takes in inputs of *.xcstring and outputs *.swift.
Unfortunately, this is having a large impact on incremental builds where for some reason the build tool plugin runs every time.
This invalidates already compiled SwiftPM targets leading to a large incremental compile time of >100 seconds in a project I work on.

This issue can be reproduced using https://github.com/liamnichols/xcstrings-tool-demo.

I also notice that the CompileXCStrings job runs on every incremental build as well.

I've tested this using Xcode 16.2 and using Xcode 16.2 with latest main of swiftlang/swift-build at time of posting.

CC: @dschaefer2

Build DogTracker_2025-02-03T05-22-22.txt
Build DogTracker_2025-02-03T05-22-36.txt

@dschaefer2 dschaefer2 transferred this issue from swiftlang/swift-build Feb 2, 2025
@dschaefer2
Copy link
Member

We'll start investigating this with the swift-package-manager.

@bcardarella
Copy link

Is there any update on this yet? We've seen re-build times go from seconds to well over 20 minutes due to what we suspect is this issue.

@dschaefer2
Copy link
Member

The example project is an Xcode project. We only deal with command line SwiftPM issues on GitHub. Can you reproduce this issue with a SwiftPM package?

@tonyarnold
Copy link
Contributor

tonyarnold commented Mar 10, 2025

Here's a sample showing the same behaviour in a Swift Package. Run swift build more than once, and you'll see the build plugin runs every time, regardless of changes to the inputs:

❯ swift build
[1/1] Planning build
Building for debugging...
/Users/tonyarnold/Desktop/ExcessiveBuildToolCompilation/Sources/ExcessiveBuildToolCompilation/Resources/Localizable.xcstrings: warning: String ‘Function Grapher‘ was ignored because it does not have a translation for source language (en)
/Users/tonyarnold/Desktop/ExcessiveBuildToolCompilation/Sources/ExcessiveBuildToolCompilation/Resources/Localizable.xcstrings: warning: String ‘Please enter valid range values‘ was ignored because it does not have a translation for source language (en)
/Users/tonyarnold/Desktop/ExcessiveBuildToolCompilation/Sources/ExcessiveBuildToolCompilation/Resources/Localizable.xcstrings: warning: String ‘Range‘ was ignored because it does not have a translation for source language (en)
note: Output written to ‘/Users/tonyarnold/Desktop/ExcessiveBuildToolCompilation/.build/plugins/outputs/excessivebuildtoolcompilation/ExcessiveBuildToolCompilation/destination/XCStringsToolPlugin/XCStringsTool/Localizable.swift‘
/Users/tonyarnold/Desktop/ExcessiveBuildToolCompilation/.build/plugins/outputs/excessivebuildtoolcompilation/ExcessiveBuildToolCompilation/destination/XCStringsToolPlugin/XCStringsTool/Localizable.swift:108:14: error: type 'Bundle' has no member 'module'
106 |         var bundle: Bundle {
107 |             #if SWIFT_PACKAGE
108 |             .module
    |              `- error: type 'Bundle' has no member 'module'
109 |             #else
110 |             Bundle(for: BundleLocator.self)
[16/16] Compiling ExcessiveBuildToolCompilation Localizable.swift

ExcessiveBuildToolCompilation.zip

@tonyarnold
Copy link
Contributor

@dschaefer2 are you certain that this is an issue with SwiftPM, rather than Swift Build? It seems to affect both Xcode and SwiftPM.

@bcardarella
Copy link

fwiw we're seeing our issue fixed in the latest xcode betas

@Brett-Best
Copy link
Author

Brett-Best commented Mar 10, 2025

Yeah, with the latest Xcode betas I was unable to create a reproducer that swift build could show.
It's still an issue with Xcode 16.3b2 including using latest main of swift-build (when opening inside of Xcode itself).

I'm wondering if @dschaefer2 could direct where this issue would be best transferred to based on that, back to swift-build where the issue was originally logged?

@MaxDesiatov MaxDesiatov changed the title SPM Build Tool Plugin excessively runs causing recompilation SwiftPM Build Tool Plugin excessively runs causing recompilation Mar 14, 2025
@owenv
Copy link
Collaborator

owenv commented Mar 14, 2025

I'm going to pull this over to Swift Build as it looks like potentially an issue with incremental invalidation in the build engine and the issue is primarily describing package builds driven via Xcode.

@owenv owenv transferred this issue from swiftlang/swift-package-manager Mar 14, 2025
@tonyarnold
Copy link
Contributor

tonyarnold commented Mar 15, 2025

A couple of interesting things I've noticed after enabling EnableBuildBacktraceRecording:

If I do not specify Resources/Localizable.xcstrings in my target, then I get the following:

Build Backtrace:
'XCStringsTool: Generate Swift code for 'Localizable'' had never run

Tracing that back up, the "Compile XCStrings" task for my target shows:

Build Backtrace:
'Compile XCStrings Localizable.xcstrings' had never run

If I manually specify the resource in the sample project I specified earlier, ie:

.target(
    name: "ExcessiveBuildToolCompilation",
    resources: [
        .process("Resources/Localizable.xcstrings")
    ],
    plugins: [
        .plugin(name: "XCStringsToolPlugin", package: "xcstrings-tool-plugin")
    ]
)

Then the backtrace shows:

Build Backtrace:
signature of 'XCStringsTool: Generate Swift code for ‘Localizable‘' changed

Tracing that back up, I see a new state for any "Compile XCStrings" tasks:

Build Backtrace:
an input of 'Compile XCStrings Localizable.xcstrings' changed
file '/Users/tonyarnold/Desktop/ExcessiveBuildToolCompilation/Sources/ExcessiveBuildToolCompilation/Resources/Localizable.xcstrings' changed

Hopefully this information is helpful - here are the full result bundles:

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

No branches or pull requests

5 participants