You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a Swift target depends on an Objective-C target that uses #if SWIFT_PACKAGE we are currently only adding the -DSWIFT_PACKAGE to copts but we should also be adding -Xcc -DSWIFT_PACKAGE for the clang compilation step.
The following build file reproduces an issue, it shows a minimal Package.swift BUILD files after rules_swift_package_manager generates it:
#ifSWIFT_PACKAGEintfoo(intx);
#elseintbar(intx); // should not be hit when building as a Swift package#endif
When running:
bazel run swift_package_copt_example
The following error is shown:
Foo.swift:5:12: error: cannot find 'foo' in scope
return foo(x)
^~~
This is because the #if SWIFT_PACKAGE case is not being hit. Fixing this requires updating the copts attribute of the swift_library to be: copts = ["-DSWIFT_PACKAGE", "-Xcc", "-DSWIFT_PACKAGE"].
Both are required because the first one is for the Swift compile and the second for the clang compile step.
The text was updated successfully, but these errors were encountered:
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
When a Swift target depends on an Objective-C target that uses
#if SWIFT_PACKAGE
we are currently only adding the-DSWIFT_PACKAGE
tocopts
but we should also be adding-Xcc -DSWIFT_PACKAGE
for the clang compilation step.The following build file reproduces an issue, it shows a minimal Package.swift BUILD files after rules_swift_package_manager generates it:
With the following
Foo.h
When running:
The following error is shown:
This is because the
#if SWIFT_PACKAGE
case is not being hit. Fixing this requires updating thecopts
attribute of theswift_library
to be:copts = ["-DSWIFT_PACKAGE", "-Xcc", "-DSWIFT_PACKAGE"]
.Both are required because the first one is for the Swift compile and the second for the clang compile step.
The text was updated successfully, but these errors were encountered: