-
Notifications
You must be signed in to change notification settings - Fork 32
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
fix: usage of copts
for SWIFT_PACKAGE
#1260
base: main
Are you sure you want to change the base?
Conversation
This primarily does two changes: - Passes `-Xcc -DSWIFT_PACKAGE` for the Swift library target generated `copts` attribute. - Removes de-duplication in `bzl_selects.bzl` - This is required because `copts = ["-DSWIFT_PACKAGE", "-Xcc", "-DSWIFT_PACKAGE"]` are valid copts but would get de-duplicated into `copts = ["-DSWIFT_PACKAGE", "-Xcc"]` Fixes #1259
@@ -106,6 +106,9 @@ def _swift_target_build_file(pkg_ctx, target): | |||
# SPM directive instructing the code to build as if a Swift package. | |||
# https://github.com/apple/swift-package-manager/blob/main/Documentation/Usage.md#packaging-legacy-code | |||
"-DSWIFT_PACKAGE", | |||
# SPM directive instructing the code to build as if a Swift package for any clang modules. | |||
"-Xcc", | |||
"-DSWIFT_PACKAGE", |
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 am confused. When are we building a C/C++ file with the swift compiler? We have separate targets for Swift and C/C++ source code.
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.
-Xcc passes a flag through to all C compiler invocations
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.
Sorry. Perhaps, I am missing something. We create cc_xxx
, objc_xxx
, and swift_xxx
targets separating the source files into their respective targets. How is a C/C++ file being compiled by the Swift compiler? The cc_xxx
and objc_xxx
should be compiled with clang.
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.
When Swift depends on a clang module (modulemap and headers), with implicit modules it compiles that clang module. -Xcc
is a way to pass compiler flags to that compilation.
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.
Is there a publicly visible Swift package that exhibits this behavior? If so, can we add it to one of the examples?
Added an example repo and example in: #1261 |
I'll need to update this because we do want to dedupe some attrs (like deps) across configs/defaults but not copt. Going to look at making a new method for this |
This primarily does two changes:
-Xcc -DSWIFT_PACKAGE
for the Swift library target generatedcopts
attribute.bzl_selects.bzl
copts = ["-DSWIFT_PACKAGE", "-Xcc", "-DSWIFT_PACKAGE"]
are valid copts but would get de-duplicated intocopts = ["-DSWIFT_PACKAGE", "-Xcc"]
Fixes #1259