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

plugins: Global compiler flags should not be used for plugin dependencies #7549

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

euanh
Copy link
Contributor

@euanh euanh commented May 10, 2024

Motivation:

Build tools and end products are built with separate toolchains:

  • Plugins and any targets they depend on, such as helper tools,
    are built with the host toolchain.
  • End products are built with the target toolchain.

Compiler flags set with -Xswiftc are intended to be applied only to
end product builds, but they are incorrectly being applied to
plugin tool builds as well. This can cause problems because target
toolchain flags might not be suitable for a tools build. In the
worst case, the build might fail completely if the host toolchain
rejects the target toolchain flag. For example, Linux toochains
accept the -static-executable flag, but macOS toolchains reject
it.

Modifications:

Global compiler flags are no longer applied to toolsBuildParameters
and so are no longer used when building plugin dependencies.

Result:

Plugin dependency builds will no longer fail because of incompatible
flags.

In future, the hidden -Xbuild-tools-swift flags should be passed to
command plugin tools builds. These are currently only passed to the
plugin script runner.

Fixes: rdar://127813618

@euanh
Copy link
Contributor Author

euanh commented May 10, 2024

@swift-ci test

@euanh
Copy link
Contributor Author

euanh commented May 10, 2024

Test to follow.

@euanh euanh changed the title plugins: Global compiler flags should not be used when building plugi… plugins: Global compiler flags should not be used for plugin dependencies May 10, 2024
@euanh euanh marked this pull request as ready for review May 10, 2024 21:03
@euanh
Copy link
Contributor Author

euanh commented May 10, 2024

@swift-ci test

@MaxDesiatov MaxDesiatov requested a review from xedin May 10, 2024 21:06
@@ -741,7 +741,7 @@ package final class SwiftCommandState {
configuration: options.build.configuration,
toolchain: toolchain,
triple: triple,
flags: options.build.buildFlags,
flags: toolsBuild ? .init() : options.build.buildFlags,
Copy link
Member

Choose a reason for hiding this comment

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

buildFlags is a combination of C/C++/Swift/Linker/XCBuild which means that host compiler doesn't get any of them but are there situations when some of the flags intended for the host and/or tools?

At the very list I think descriptions of all flags and not just swiftCompilerFlags have to be updated to indicate that they are no longer applied to the host.

@@ -796,7 +796,7 @@ package final class SwiftCommandState {

private lazy var _toolsBuildParameters: Result<BuildParameters, Swift.Error> = {
Result(catching: {
try _buildParams(toolchain: self.getHostToolchain())
try _buildParams(toolchain: self.getHostToolchain(), toolsBuild: true)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe instead of a boolean flag here we should just pass in the options.build.buildFlags or []?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think that's better and will help when we tidy up the tools/products build option split.

@MaxDesiatov MaxDesiatov added add to change log bug plugins build system Changes to interactions with build systems labels May 12, 2024
…n dependencies

Build tools and end products are built with separate toolchains:
* Plugins and any targets they depend on, such as helper tools, are
built with the host toolchain.
* End products are built with the target toolchain.

Compiler flags set with -Xswiftc are intended to be applied only
to end product builds, but they are incorrectly being applied to
plugin tool builds as well.   This can cause problems because target
toolchain flags might not be suitable for a tools build.   In the
worst case, the build might fail completely if the host toolchain
rejects the target toolchain flag.    For example, Linux toochains
accept the `-static-executable` flag, but macOS toolchains reject
it.

Fixes: rdar://127813618
@euanh
Copy link
Contributor Author

euanh commented May 13, 2024

@swift-ci test

@euanh euanh requested a review from xedin May 13, 2024 08:08
@euanh
Copy link
Contributor Author

euanh commented May 13, 2024

@swift-ci test windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to change log bug build system Changes to interactions with build systems plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants