Skip to content

Commit aa175e1

Browse files
authored
2.x cherry-pick: Add clang_deps attr to mixed_language_library (#1540) (#1542)
At Square, we're using a headermap for the Swift generated header, so that the objective-C half of a module is able to import it using `#import <Module/Module-Swift.h>`. This headermap target can't be placed in `deps`, as doing so creates a dependency cycle. Here is an example of what the use case looks like: master...jschear:rules_swift:js/demo_swift_header_imports_in_clang_half ``` header_map( name = "swift_headermap", module_name = "MixedAnswer", propagate_include = False, # This relies on us knowing the naming scheme used for internal targets in mixed_language_library, which is not ideal. deps = ["MixedAnswer_swift"], ) mixed_language_library( name = "MixedAnswer", hdrs = ["MixedAnswer.h"], clang_copts = [ "-I$(execpath :swift_headermap)", "-I.", ], clang_deps = [":swift_headermap"], clang_srcs = [ "MixedAnswer.m", "MixedAnswerPrivate.m", "MixedAnswerPrivate.h", ], enable_modules = True, module_name = "MixedAnswer", swift_srcs = [ "MixedAnswer.swift", ], target_compatible_with = ["@platforms//os:macos"], ) ```
1 parent d187295 commit aa175e1

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

doc/rules.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -992,15 +992,16 @@ swift_library(
992992

993993
<pre>
994994
mixed_language_library(<a href="#mixed_language_library-name">name</a>, <a href="#mixed_language_library-always_include_developer_search_paths">always_include_developer_search_paths</a>, <a href="#mixed_language_library-alwayslink">alwayslink</a>, <a href="#mixed_language_library-clang_copts">clang_copts</a>,
995-
<a href="#mixed_language_library-clang_defines">clang_defines</a>, <a href="#mixed_language_library-clang_srcs">clang_srcs</a>, <a href="#mixed_language_library-data">data</a>, <a href="#mixed_language_library-enable_modules">enable_modules</a>, <a href="#mixed_language_library-hdrs">hdrs</a>, <a href="#mixed_language_library-includes">includes</a>, <a href="#mixed_language_library-linkopts">linkopts</a>,
996-
<a href="#mixed_language_library-module_map">module_map</a>, <a href="#mixed_language_library-module_name">module_name</a>, <a href="#mixed_language_library-non_arc_srcs">non_arc_srcs</a>, <a href="#mixed_language_library-package_name">package_name</a>, <a href="#mixed_language_library-private_deps">private_deps</a>, <a href="#mixed_language_library-sdk_dylibs">sdk_dylibs</a>,
997-
<a href="#mixed_language_library-sdk_frameworks">sdk_frameworks</a>, <a href="#mixed_language_library-swift_copts">swift_copts</a>, <a href="#mixed_language_library-swift_defines">swift_defines</a>, <a href="#mixed_language_library-swift_srcs">swift_srcs</a>, <a href="#mixed_language_library-swiftc_inputs">swiftc_inputs</a>,
998-
<a href="#mixed_language_library-textual_hdrs">textual_hdrs</a>, <a href="#mixed_language_library-umbrella_header">umbrella_header</a>, <a href="#mixed_language_library-weak_sdk_frameworks">weak_sdk_frameworks</a>, <a href="#mixed_language_library-deps">deps</a>, <a href="#mixed_language_library-kwargs">kwargs</a>)
995+
<a href="#mixed_language_library-clang_defines">clang_defines</a>, <a href="#mixed_language_library-clang_deps">clang_deps</a>, <a href="#mixed_language_library-clang_srcs">clang_srcs</a>, <a href="#mixed_language_library-data">data</a>, <a href="#mixed_language_library-enable_modules">enable_modules</a>, <a href="#mixed_language_library-hdrs">hdrs</a>, <a href="#mixed_language_library-includes">includes</a>,
996+
<a href="#mixed_language_library-linkopts">linkopts</a>, <a href="#mixed_language_library-module_map">module_map</a>, <a href="#mixed_language_library-module_name">module_name</a>, <a href="#mixed_language_library-non_arc_srcs">non_arc_srcs</a>, <a href="#mixed_language_library-package_name">package_name</a>, <a href="#mixed_language_library-private_deps">private_deps</a>,
997+
<a href="#mixed_language_library-sdk_dylibs">sdk_dylibs</a>, <a href="#mixed_language_library-sdk_frameworks">sdk_frameworks</a>, <a href="#mixed_language_library-swift_copts">swift_copts</a>, <a href="#mixed_language_library-swift_defines">swift_defines</a>, <a href="#mixed_language_library-swift_srcs">swift_srcs</a>,
998+
<a href="#mixed_language_library-swiftc_inputs">swiftc_inputs</a>, <a href="#mixed_language_library-textual_hdrs">textual_hdrs</a>, <a href="#mixed_language_library-umbrella_header">umbrella_header</a>, <a href="#mixed_language_library-weak_sdk_frameworks">weak_sdk_frameworks</a>, <a href="#mixed_language_library-deps">deps</a>,
999+
<a href="#mixed_language_library-kwargs">kwargs</a>)
9991000
</pre>
10001001

10011002
Creates a mixed language library from a Clang and Swift library target pair.
10021003

1003-
Note: In the future `swift_library` will support mixed-langauge libraries.
1004+
Note: In the future `swift_library` will support mixed-language libraries.
10041005
Once that is the case, this macro will be deprecated.
10051006

10061007

@@ -1014,6 +1015,7 @@ Once that is the case, this macro will be deprecated.
10141015
| <a id="mixed_language_library-alwayslink"></a>alwayslink | If true, any binary that depends (directly or indirectly) on this library will link in all the object files for the files listed in `clang_srcs` and `swift_srcs`, even if some contain no symbols referenced by the binary. This is useful if your code isn't explicitly called by code in the binary; for example, if you rely on runtime checks for protocol conformances added in extensions in the library but do not directly reference any other symbols in the object file that adds that conformance. | `False` |
10151016
| <a id="mixed_language_library-clang_copts"></a>clang_copts | The compiler flags for the clang library. These will only be used for the clang library. If you want them to affect the swift library as well, you need to pass them with `-Xcc` in `swift_copts`. | `[]` |
10161017
| <a id="mixed_language_library-clang_defines"></a>clang_defines | Extra clang `-D` flags to pass to the compiler. They should be in the form `KEY=VALUE` or simply `KEY` and are passed not only to the compiler for this target (as `clang_copts` are) but also to all dependers of this target. Subject to "Make variable" substitution and Bourne shell tokenization. | `[]` |
1018+
| <a id="mixed_language_library-clang_deps"></a>clang_deps | A list of targets that are dependencies of only the clang library. | `[]` |
10171019
| <a id="mixed_language_library-clang_srcs"></a>clang_srcs | The list of C, C++, Objective-C, or Objective-C++ sources for the clang library. | none |
10181020
| <a id="mixed_language_library-data"></a>data | The list of files needed by this target at runtime.<br><br>Files and targets named in the `data` attribute will appear in the `*.runfiles` area of this target, if it has one. This may include data files needed by a binary or library, or other programs needed by it. | `[]` |
10191021
| <a id="mixed_language_library-enable_modules"></a>enable_modules | Enables clang module support (via `-fmodules`). Setting this to `True` will allow you to `@import` system headers and other targets: `@import UIKit;` `@import path_to_package_target;`. | `False` |

mixed_language/mixed_language_library.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def mixed_language_library(
3939
alwayslink = False,
4040
clang_copts = [],
4141
clang_defines = [],
42+
clang_deps = [],
4243
clang_srcs,
4344
data = [],
4445
enable_modules = False,
@@ -64,7 +65,7 @@ def mixed_language_library(
6465
"""Creates a mixed language library from a Clang and Swift library target \
6566
pair.
6667
67-
Note: In the future `swift_library` will support mixed-langauge libraries.
68+
Note: In the future `swift_library` will support mixed-language libraries.
6869
Once that is the case, this macro will be deprecated.
6970
7071
Args:
@@ -89,6 +90,8 @@ def mixed_language_library(
8990
only to the compiler for this target (as `clang_copts` are) but also
9091
to all dependers of this target. Subject to "Make variable"
9192
substitution and Bourne shell tokenization.
93+
clang_deps: A list of targets that are dependencies of only the
94+
clang library.
9295
clang_srcs: The list of C, C++, Objective-C, or Objective-C++ sources
9396
for the clang library.
9497
data: The list of files needed by this target at runtime.
@@ -376,7 +379,7 @@ a mixed language Swift library, use a clang only library rule like \
376379
testonly = testonly,
377380
textual_hdrs = textual_hdrs,
378381
weak_sdk_frameworks = weak_sdk_frameworks,
379-
deps = deps,
382+
deps = deps + clang_deps,
380383
**kwargs
381384
)
382385

0 commit comments

Comments
 (0)