-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Improve handling of tool build flags #6475
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test to verify that #6380 doesn't regress with this change?
I admit, it was on me to add a test in #6380, I guess I can add it in a separate PR myself. This one still could benefit from a test that verifies that duplicate flags bug is fixed. |
a1fc0ce
to
0cf62db
Compare
Do not test yet please, I need to update some unit tests still |
0cf62db
to
5ad71d5
Compare
// User arguments (from -Xcc) should follow generated arguments to allow user overrides | ||
result += self.buildParameters.flags.cCompilerFlags.asSwiftcCCompilerFlags() | ||
|
||
result += self.buildParameters.toolchain.extraFlags.cxxCompilerFlags.asSwiftcCXXCompilerFlags() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@compnerd @MaxDesiatov I'd really like to get some feedback here. I'm not sure if passing -Xcxx flags
to swiftc is ok for all swift targets, but it seems maybe reasonable to do because the previous implementation passed the -Xcc flags
(via buildParameters.swiftCompilerFlags).
The -Xcc flags
can be needed when compiling a swift target to ensure additional args make it to the clang importer. For example I pass -D__none__
and -D__MACH__
to workaround some funkiness in my armv7em-apple-none-macho build. Similarly I figure -Xcxx flags
maybe should be passed to the clang importer when importing c++ modules/headers.
AFAICT by default the only change is a new trailing arg to swiftc: swiftc <old args> -Xcc -lc++
when compiling a an object this shouldn't matter and when linking I assume the linker doesn't eager link libraries if no symbols from it are used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading #4994 I think the cxxCompiler flags should go to swiftc prefixed by -Xcxx
however this option does not exist in swift-driver yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in absence of -Xcxx
we probably shouldn't forward the flags here, but if needed we could add another set of flags which are the CXX flags that are "safe" to pass to SwiftPM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked to @hyp this morning and it seems like we will be adding an -Xcxx to swift-driver some time in the future. When that happens we can start propagating spm's cxx flags to swift-driver.
triple: triple, | ||
destination: destination, | ||
environment: environment), | ||
linkerFlags: destination.toolset.knownTools[.linker]?.extraCLIOptions ?? [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MaxDesiatov toolset linker flags were previously getting lost here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, great catch!
I will update the commit message/PR title tomorrow as well with more detail about the changes |
5ad71d5
to
e44c050
Compare
All the duplication in target build description makes me a bit sad, but it's not an issue introduced by this PR. We should really refactor all of this... |
Refactors the various compilerArguments and linkerArgument functions slightly to ensure flags from a user's sdk and cli properly propagate to the expected subcommand invocations. Adds a fairly comprehensive test to cover the toolset and cli flag passing end result. --- Fixes a bug where clang targets didn't respect the `isCXX` override. Fixes a bug where cxxCompiler extraCLIFlags where not passed to clang when building cxx targets. Future work: #6491. cxxCompiler extraCLIFlags should also be passed to `swiftc` when compiling swift modules to ensure the clang importer has the same interpretation of the module as the initial compile. Fixes a bug where linker extraCLIFlags were not passed to `swiftc` prefixed by `-Xlinker`. The previous workaround to pass these flags in swiftCompiler extraCLIFlags is no longer necessary. Fixes a bug where a user could pass `-whole-module-optimization` or `-wmo` to swiftc when linking causing the driver to either attempt to compile the object files when using the legacy driver: rdar://27578292 or crash when using the new driver: rdar://108057797. Fixes a bug where cCompiler extraCLIFlags were not passed to `swiftc` prefixed by `-Xcc`. The previous workaround to pass these flags in swiftCompiler extraCLIFlags is no longer necessary. Fixes a bug where extraCLIFlags from an SDKs toolset.json files would be repeated multiple times in child process invocations. The repeated flags could cause issues with some downstream tools, such as repeated `-segaddr` flags to ld64 for the same segment. Fixes a bug where extra toolchain flags would be added to an xcode build parameters file without escaping. Fixes a bug where extra toolchain linker flags would not be added to an xcode build parameters file.
e44c050
to
e7c1d3e
Compare
@swift-ci please smoke test |
@swift-ci please smoke test windows |
@swift-ci please smoke test macOS |
@swift-ci smoke test macos |
Requires swiftlang/sourcekit-lsp#742 to pass macOS smoke test |
@swift-ci please test macOS |
@swift-ci please smoke test macOS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Cherry-pick of #6475. Refactors the various compilerArguments and linkerArgument functions slightly to ensure flags from a user's sdk and cli properly propagate to the expected subcommand invocations. Adds a fairly comprehensive test to cover the toolset and cli flag passing end result. --- Fixes a bug where clang targets didn't respect the `isCXX` override. Fixes a bug where cxxCompiler extraCLIFlags where not passed to clang when building cxx targets. Future work: #6491. cxxCompiler extraCLIFlags should also be passed to `swiftc` when compiling swift modules to ensure the clang importer has the same interpretation of the module as the initial compile. Fixes a bug where linker extraCLIFlags were not passed to `swiftc` prefixed by `-Xlinker`. The previous workaround to pass these flags in swiftCompiler extraCLIFlags is no longer necessary. Fixes a bug where a user could pass `-whole-module-optimization` or `-wmo` to swiftc when linking causing the driver to either attempt to compile the object files when using the legacy driver: rdar://27578292 or crash when using the new driver: rdar://108057797. Fixes a bug where cCompiler extraCLIFlags were not passed to `swiftc` prefixed by `-Xcc`. The previous workaround to pass these flags in swiftCompiler extraCLIFlags is no longer necessary. Fixes a bug where extraCLIFlags from an SDKs toolset.json files would be repeated multiple times in child process invocations. The repeated flags could cause issues with some downstream tools, such as repeated `-segaddr` flags to ld64 for the same segment. Fixes a bug where extra toolchain flags would be added to an xcode build parameters file without escaping. Fixes a bug where extra toolchain linker flags would not be added to an xcode build parameters file. (cherry picked from commit 151343e) # Conflicts: # Sources/Build/BuildPlan.swift # Tests/BuildTests/MockBuildTestHelper.swift --------- Co-authored-by: Rauhul Varma <[email protected]>
Refactors the various compilerArguments and linkerArgument functions
slightly to ensure flags from a user's sdk and cli properly propagate to
the expected subcommand invocations.
Adds a fairly comprehensive test to cover the toolset and cli flag
passing end result.
Fixes a bug where clang targets didn't respect the
isCXX
override.Fixes a bug where cxxCompiler extraCLIFlags where not passed to clang
when building cxx targets. Future work: #6491. cxxCompiler extraCLIFlags
should also be passed to
swiftc
when compiling swift modules to ensurethe clang importer has the same interpretation of the module as the
initial compile.
Fixes a bug where linker extraCLIFlags were not passed to
swiftc
prefixed by
-Xlinker
. The previous workaround to pass these flags inswiftCompiler extraCLIFlags is no longer necessary.
Fixes a bug where a user could pass
-whole-module-optimization
or-wmo
to swiftc when linking causing the driver to either attempt tocompile the object files when using the legacy driver: rdar://27578292
or crash when using the new driver: rdar://108057797.
Fixes a bug where cCompiler extraCLIFlags were not passed to
swiftc
prefixed by
-Xcc
. The previous workaround to pass these flags inswiftCompiler extraCLIFlags is no longer necessary.
Fixes a bug where extraCLIFlags from an SDK's toolset.json files would
be repeated multiple times in child process invocations. The repeated
flags could cause issues with some downstream tools, such as repeated
-segaddr
flags to ld64 for the same segment.Fixes a bug where extra toolchain flags would be added to an xcode build
parameters file without escaping.
Fixes a bug where extra toolchain linker flags would not be added to an
xcode build parameters file.