swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.7k stars 1.33k forks source link

Adding file to module A triggers rebuild of module B #7886

Open rauhul opened 3 weeks ago

rauhul commented 3 weeks ago

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

Description

Given a package with structure:

ModuleA/Foo.swift
ModuleB/Empty.swift

where ModuleB's content really comes from a build tool plugin

Adding a file to Module A like Bar.swift will trigger SwiftPM to rebuild ModuleB even though none of its inputs have changed. This can be really rough for users because ModuleB may take a while to compile, see the RP2350 module in swift-embedded-examples:

Compiling Swift Module 'RP2350' (7 sources) (1m 14.92s)

which gets rebuilt anytime the Application module adds or removes files.

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version ; uname -a)

No response

dschaefer2 commented 3 weeks ago

Do you have some sample code I could try?

rauhul commented 3 weeks ago

Almost, you can repro on branch pico2-blink of swift-embedded-examples but right now it has a hardcoded path into my env.

This is my build command on that branch right now:

TOOLCHAINS=org.swift.59202408071a make || PICO_SDK_PATH=/Users/rauhul/Developer/scratch/pico-sdk cmake -B build -G Ninja -DPICO_PLATFORM=rp2350 && ninja -C build | swift demangle && open build
rauhul commented 3 weeks ago

Sometimes SwiftPM also just decides to build more than just ModuleB...

Screenshot 2024-08-16 at 11 46 49 AM
dschaefer2 commented 3 weeks ago

OK, just taking notes. From what I've seen, we're building SwiftSyntax twice, once as a tool and once as a destination. Given we are cross compiling in this example, why is SwiftSyntax being compiled for armv7em?

(update, it's only being build for host, but I do see it both in the plugin-tools.yaml and release.yaml)

dschaefer2 commented 3 weeks ago

On a second build with no changes, I'm seeing SwiftSyntax for production being built again but not for plugin-tools.

On a third build with no changes, nothing builds as expected.