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

fix: usage of copts for SWIFT_PACKAGE #1260

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

luispadron
Copy link
Collaborator

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

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",
Copy link
Owner

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.

Copy link
Collaborator Author

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

Copy link
Owner

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.

Copy link
Collaborator

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.

Copy link
Owner

@cgrindel cgrindel left a 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?

@luispadron
Copy link
Collaborator Author

Added an example repo and example in: #1261

@luispadron
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SWIFT_PACKAGE copt not correctly applied when importing Objective-C library
3 participants