Skip to content

Plugin: Stop building with -enable-testing even with release config #8025

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

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Oct 5, 2024

Motivation:

When building a SwiftPM target through PackagePlugin APIs and overall configuration is debug, they were built with -enable-testing even with plugins requests building with release configuration.

This mis-configuration led performance and code size regression only when building through package plugins.

The root problem is that some of the properties under BuildParameters store values derived from other properties.
buildParameters.testing.enableTestability was one of them. It depends on configuration but it's computed only in BuildParameters.Testing initializer. Therefore the property was not updated after PluginDelegate modifies configuration for requested builds.

switch parameters.configuration {
case .debug:
buildParameters.configuration = .debug
case .release:
buildParameters.configuration = .release
case .inherit:
// The top level argument parser set buildParameters.configuration according to the
// --configuration command line parameter. We don't need to do anything to inherit it.
break
}

self.enableTestability = enableTestability ?? (.debug == configuration)

For those who want an immediate workaround: One of the workaround was to set the overall configuration as release, but it forces building plugins as release too.

Modifications:

This PR made those properties that depend on other stored properties as computed properties rather than stored ones.

There are still some properties having the same issue (BuildParameters.Debugging), so I'll fix them in a follow-up PR separately.

Result:

Release builds requested through package plugins are truly built as release mode even if the overall configuration is debug.

@kateinoigakukun
Copy link
Member Author

@swift-ci test

@MaxDesiatov MaxDesiatov requested a review from grynspan October 6, 2024 12:08
@MaxDesiatov
Copy link
Contributor

@swift-ci test

@grynspan
Copy link
Contributor

grynspan commented Oct 6, 2024

I haven't dug in but I would suggest making sure the flag is still set when calling --build-tests or swift test since the intent there is pretty clear.

@kateinoigakukun kateinoigakukun force-pushed the yt/plugin-release-testable branch from 65bb939 to 9dbba7b Compare October 7, 2024 06:29
@kateinoigakukun kateinoigakukun force-pushed the yt/plugin-release-testable branch from 9dbba7b to eff0cbc Compare October 7, 2024 06:30
@kateinoigakukun
Copy link
Member Author

kateinoigakukun commented Oct 7, 2024

@grynspan That's a good point. I added a validation test for swift test -c release. For swift build --build-tests -c release, I'll make a follow-up fix separately because it has not been working for long and is independent from plugin system.

@kateinoigakukun
Copy link
Member Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

@grynspan
Copy link
Contributor

grynspan commented Oct 7, 2024

@plemarquand FYI

@dschaefer2
Copy link
Member

Wouldn't changing flags with swift test, or --build-tests, trigger an expensive full rebuild?

@kateinoigakukun
Copy link
Member Author

kateinoigakukun commented Oct 7, 2024

@dschaefer2 No full rebuilding triggered between swift build, swit build --build-tests, and swift test. Changing between swift build -c release and swift test -c release triggers a full rebuild but I think it's acceptable to provide the best performance for release mode.
For those who don't really want full rebuilding even with release mode, they can use swift build -c release --enable-testable-imports and swift test -c release instead to take build time over runtime performance.

@dschaefer2
Copy link
Member

The community is very sensitive to build times, especially when macros are involved as is the case with swift-testing. And the worst case is building SwiftSyntax in release mode which can take up to 5 minutes.

@kateinoigakukun
Copy link
Member Author

kateinoigakukun commented Oct 7, 2024

@dschaefer2 First of all, this PR does not change the build behavior triggered by the CLI but changes the build behavior triggered through Package Plugin APIs to be aligned with today's CLI's behavior.

Back to the build time tradeoff, I agree that today's CLI behavior is arguable. I think we have three options:

  1. Keep the current behavior
    • Changing testability always requires full rebuilding
  2. Have separate build description and object directory for with/without testability, not to overwrite artifacts
    • Changing testability requires full rebuilding only for the first time
    • Need non-trivial refactoring in SwiftPM because we assume a pair of build description and object directory corresponds to a configuration.
      • Or internally introduce [debug, debug-test, release, release-test] configurations
    • Double disk footprint if switching testability even once
  3. Always build with -enable-testing
    • Changing testability never requires full rebuilding
    • Sacrifice runtime performance and code size in release mode

I think the current behavior is a good balance option given that most developers rarely use swift test -c release nor swift build -c debug --disable-testable-imports, but I'd like to hear your opinion here

@grynspan
Copy link
Contributor

grynspan commented Oct 8, 2024

If we do continue with this change, let's make sure to run a full toolchain build against it.

@kateinoigakukun
Copy link
Member Author

kateinoigakukun commented Oct 9, 2024

I verified this change doesn't work full toolchain build :)

Since 1. this change does not change anything in CLI behavior but just for package plugin invocations (not related to macro plugins, to be clear), 2. also it just aligns with the current CLI behavior, and 3. we are suffering from a huge performance regression due to this issue, I'd like to proceed this change and discuss the incremental build topic as a separate issue (#8031)
Does it make sense for you? @MaxDesiatov @dschaefer2

@grynspan
Copy link
Contributor

grynspan commented Oct 9, 2024

"Doesn't work" or "doesn't break"? 😬

@kateinoigakukun
Copy link
Member Author

"Doesn't break"😅

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I hope @xedin could have a look before this is merged

@MaxDesiatov MaxDesiatov added the build system Changes to interactions with build systems label Oct 10, 2024
@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Oct 10, 2024

cc @rauhul who's building in release configuration for embedded

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me for both to be consistent. Once it is decided what release behavior in regards to testability should be (@rauhul has a thread about that on forums) we could change both places to reflect that.

Copy link
Member

@dschaefer2 dschaefer2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@dschaefer2 dschaefer2 merged commit 04329d3 into swiftlang:main Oct 15, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug build system Changes to interactions with build systems plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants