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
Update docs to say that a source file should only be in a single swift_* target, and a swift_overlay should only be referenced by a single other target's aspect_hints
PiperOrigin-RevId: 664809810
(cherry picked from commit c593bc4)
Signed-off-by: Brentley Jones <[email protected]>
| <aid="swift_binary-name"></a>name | A unique name for this target. | <ahref="https://bazel.build/concepts/labels#target-names">Name</a> | required ||
68
68
| <aid="swift_binary-deps"></a>deps | A list of targets that are dependencies of the target being built, which will be linked into that target.<br><br>If the Swift toolchain supports implementation-only imports (`private_deps` on `swift_library`), then targets in `deps` are treated as regular (non-implementation-only) imports that are propagated both to their direct and indirect (transitive) dependents.<br><br>Allowed kinds of dependencies are:<br><br>*`swift_library` (or anything propagating `SwiftInfo`)<br><br>*`cc_library` and `objc_library` (or anything propagating `CcInfo`) | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
69
-
| <aid="swift_binary-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library. | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
69
+
| <aid="swift_binary-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library.<br><br>Except in very rare circumstances, a Swift source file should only appear in a single `swift_*` target. Adding the same source file to multiple `swift_*` targets can lead to binary bloat and/or symbol collisions. If specific sources need to be shared by multiple targets, consider factoring them out into their own `swift_library` instead.| <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
70
70
| <aid="swift_binary-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. | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
71
71
| <aid="swift_binary-copts"></a>copts | Additional compiler options that should be passed to `swiftc`. These strings are subject to `$(location ...)` and ["Make" variable](https://docs.bazel.build/versions/master/be/make-variables.html) expansion. | List of strings | optional |`[]`|
72
72
| <aid="swift_binary-defines"></a>defines | A list of defines to add to the compilation command line.<br><br>Note that unlike C-family languages, Swift defines do not have values; they are simply identifiers that are either defined or undefined. So strings in this list should be simple identifiers, **not**`name=value` pairs.<br><br>Each string is prepended with `-D` and added to the command line. Unlike `copts`, these flags are added for the target and every target that depends on it, so use this attribute with caution. It is preferred that you add defines directly to `copts`, only using this feature in the rare case that a library needs to propagate a symbol up to those that depend on it. | List of strings | optional |`[]`|
| <aid="swift_compiler_plugin-name"></a>name | A unique name for this target. | <ahref="https://bazel.build/concepts/labels#target-names">Name</a> | required ||
156
156
| <aid="swift_compiler_plugin-deps"></a>deps | A list of targets that are dependencies of the target being built, which will be linked into that target.<br><br>If the Swift toolchain supports implementation-only imports (`private_deps` on `swift_library`), then targets in `deps` are treated as regular (non-implementation-only) imports that are propagated both to their direct and indirect (transitive) dependents.<br><br>Allowed kinds of dependencies are:<br><br>*`swift_library` (or anything propagating `SwiftInfo`)<br><br>*`cc_library` and `objc_library` (or anything propagating `CcInfo`) | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
157
-
| <aid="swift_compiler_plugin-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library. | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
157
+
| <aid="swift_compiler_plugin-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library.<br><br>Except in very rare circumstances, a Swift source file should only appear in a single `swift_*` target. Adding the same source file to multiple `swift_*` targets can lead to binary bloat and/or symbol collisions. If specific sources need to be shared by multiple targets, consider factoring them out into their own `swift_library` instead.| <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
158
158
| <aid="swift_compiler_plugin-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. | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
159
159
| <aid="swift_compiler_plugin-copts"></a>copts | Additional compiler options that should be passed to `swiftc`. These strings are subject to `$(location ...)` and ["Make" variable](https://docs.bazel.build/versions/master/be/make-variables.html) expansion. | List of strings | optional |`[]`|
160
160
| <aid="swift_compiler_plugin-defines"></a>defines | A list of defines to add to the compilation command line.<br><br>Note that unlike C-family languages, Swift defines do not have values; they are simply identifiers that are either defined or undefined. So strings in this list should be simple identifiers, **not**`name=value` pairs.<br><br>Each string is prepended with `-D` and added to the command line. Unlike `copts`, these flags are added for the target and every target that depends on it, so use this attribute with caution. It is preferred that you add defines directly to `copts`, only using this feature in the rare case that a library needs to propagate a symbol up to those that depend on it. | List of strings | optional |`[]`|
@@ -467,7 +467,7 @@ Compiles and links Swift code into a static library and Swift module.
| <aid="swift_library-name"></a>name | A unique name for this target. | <ahref="https://bazel.build/concepts/labels#target-names">Name</a> | required ||
469
469
| <aid="swift_library-deps"></a>deps | A list of targets that are dependencies of the target being built, which will be linked into that target.<br><br>If the Swift toolchain supports implementation-only imports (`private_deps` on `swift_library`), then targets in `deps` are treated as regular (non-implementation-only) imports that are propagated both to their direct and indirect (transitive) dependents.<br><br>Allowed kinds of dependencies are:<br><br>*`swift_library` (or anything propagating `SwiftInfo`)<br><br>*`cc_library` and `objc_library` (or anything propagating `CcInfo`) | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
470
-
| <aid="swift_library-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library. | <ahref="https://bazel.build/concepts/labels">List of labels</a> | required ||
470
+
| <aid="swift_library-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library.<br><br>Except in very rare circumstances, a Swift source file should only appear in a single `swift_*` target. Adding the same source file to multiple `swift_*` targets can lead to binary bloat and/or symbol collisions. If specific sources need to be shared by multiple targets, consider factoring them out into their own `swift_library` instead.| <ahref="https://bazel.build/concepts/labels">List of labels</a> | required ||
471
471
| <aid="swift_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. | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
472
472
| <aid="swift_library-always_include_developer_search_paths"></a>always_include_developer_search_paths | If `True`, the developer framework search paths will be added to the compilation command. This enables a Swift module to access `XCTest` without having to mark the target as `testonly = True`. | Boolean | optional |`False`|
473
473
| <a id="swift_library-alwayslink"></a>alwayslink | If `False`, any binary that depends (directly or indirectly) on this Swift module will only link in all the object files for the files listed in `srcs` when there is a direct symbol reference.<br><br>Swift protocol conformances don't create linker references. Likewise, if the Swift code has Objective-C classes/methods, their usage does not always result in linker references.<br><br>_"All the object files"_ for this module is also somewhat fuzzy. Unlike C, C++, and Objective-C, where each source file results in a `.o` file; for Swift the number of .o files depends on the compiler options (`-wmo`/`-whole-module-optimization`, `-num-threads`). That makes relying on linker reference more fragile, and any individual .swift file in `srcs` may/may not get picked up based on the linker references to other files that happen to get batched into a single `.o` by the compiler options used.<br><br>Swift Package Manager always passes the individual `.o` files to the linker instead of using intermediate static libraries, so it effectively is the same as `alwayslink = True`. | Boolean | optional | `True` |
@@ -682,14 +682,20 @@ overlay target must explicitly depend on them as well. This means that an
682
682
overlay can have a different set of dependencies than the underlying module, if
683
683
desired.
684
684
685
+
There is a tight coupling between a Swift overlay and the C/Objective-C module
686
+
to which it is being applied, so a specific `swift_overlay` target should only
687
+
be referenced by the `aspect_hints` of a single `objc_library` or `cc_library`
688
+
target. Referencing a `swift_overlay` from multiple targets' `aspect_hints` is
689
+
almost always an anti-pattern.
690
+
685
691
**ATTRIBUTES**
686
692
687
693
688
694
| Name | Description | Type | Mandatory | Default |
| <aid="swift_overlay-name"></a>name | A unique name for this target. | <ahref="https://bazel.build/concepts/labels#target-names">Name</a> | required ||
691
697
| <aid="swift_overlay-deps"></a>deps | A list of targets that are dependencies of the target being built, which will be linked into that target.<br><br>If the Swift toolchain supports implementation-only imports (`private_deps` on `swift_library`), then targets in `deps` are treated as regular (non-implementation-only) imports that are propagated both to their direct and indirect (transitive) dependents.<br><br>Allowed kinds of dependencies are:<br><br>*`swift_library` (or anything propagating `SwiftInfo`)<br><br>*`cc_library` and `objc_library` (or anything propagating `CcInfo`) | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
692
-
| <aid="swift_overlay-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library. | <ahref="https://bazel.build/concepts/labels">List of labels</a> | required ||
698
+
| <aid="swift_overlay-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library.<br><br>Except in very rare circumstances, a Swift source file should only appear in a single `swift_*` target. Adding the same source file to multiple `swift_*` targets can lead to binary bloat and/or symbol collisions. If specific sources need to be shared by multiple targets, consider factoring them out into their own `swift_library` instead.| <ahref="https://bazel.build/concepts/labels">List of labels</a> | required ||
693
699
| <aid="swift_overlay-always_include_developer_search_paths"></a>always_include_developer_search_paths | If `True`, the developer framework search paths will be added to the compilation command. This enables a Swift module to access `XCTest` without having to mark the target as `testonly = True`. | Boolean | optional |`False`|
694
700
| <a id="swift_overlay-alwayslink"></a>alwayslink | If `False`, any binary that depends (directly or indirectly) on this Swift module will only link in all the object files for the files listed in `srcs` when there is a direct symbol reference.<br><br>Swift protocol conformances don't create linker references. Likewise, if the Swift code has Objective-C classes/methods, their usage does not always result in linker references.<br><br>_"All the object files"_ for this module is also somewhat fuzzy. Unlike C, C++, and Objective-C, where each source file results in a `.o` file; for Swift the number of .o files depends on the compiler options (`-wmo`/`-whole-module-optimization`, `-num-threads`). That makes relying on linker reference more fragile, and any individual .swift file in `srcs` may/may not get picked up based on the linker references to other files that happen to get batched into a single `.o` by the compiler options used.<br><br>Swift Package Manager always passes the individual `.o` files to the linker instead of using intermediate static libraries, so it effectively is the same as `alwayslink = True`. | Boolean | optional | `True` |
695
701
| <aid="swift_overlay-copts"></a>copts | Additional compiler options that should be passed to `swiftc`. These strings are subject to `$(location ...)` and ["Make" variable](https://docs.bazel.build/versions/master/be/make-variables.html) expansion. | List of strings | optional |`[]`|
| <aid="swift_proto_library-name"></a>name | A unique name for this target. | <ahref="https://bazel.build/concepts/labels#target-names">Name</a> | required ||
812
818
| <aid="swift_proto_library-deps"></a>deps | A list of targets that are dependencies of the target being built, which will be linked into that target.<br><br>If the Swift toolchain supports implementation-only imports (`private_deps` on `swift_library`), then targets in `deps` are treated as regular (non-implementation-only) imports that are propagated both to their direct and indirect (transitive) dependents.<br><br>Allowed kinds of dependencies are:<br><br>*`swift_library` (or anything propagating `SwiftInfo`)<br><br>*`cc_library` and `objc_library` (or anything propagating `CcInfo`) | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
813
-
| <aid="swift_proto_library-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library. | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
819
+
| <aid="swift_proto_library-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library.<br><br>Except in very rare circumstances, a Swift source file should only appear in a single `swift_*` target. Adding the same source file to multiple `swift_*` targets can lead to binary bloat and/or symbol collisions. If specific sources need to be shared by multiple targets, consider factoring them out into their own `swift_library` instead.| <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
814
820
| <aid="swift_proto_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. | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
815
821
| <aid="swift_proto_library-additional_compiler_deps"></a>additional_compiler_deps | List of additional dependencies required by the generated Swift code at compile time, whose SwiftProtoInfo will be ignored.<br><br>Allowed kinds of dependencies are:<br><br>*`swift_library` (or anything propagating `SwiftInfo`)<br><br>*`cc_library` and `objc_library` (or anything propagating `CcInfo`) | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
816
822
| <aid="swift_proto_library-additional_compiler_info"></a>additional_compiler_info | Dictionary of additional information passed to the compiler targets. See the documentation of the respective compiler rules for more information on which fields are accepted and how they are used. | <ahref="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional |`{}`|
@@ -987,7 +993,7 @@ root of your workspace (i.e. `$(SRCROOT)`).
| <aid="swift_test-name"></a>name | A unique name for this target. | <ahref="https://bazel.build/concepts/labels#target-names">Name</a> | required ||
989
995
| <aid="swift_test-deps"></a>deps | A list of targets that are dependencies of the target being built, which will be linked into that target.<br><br>If the Swift toolchain supports implementation-only imports (`private_deps` on `swift_library`), then targets in `deps` are treated as regular (non-implementation-only) imports that are propagated both to their direct and indirect (transitive) dependents.<br><br>Allowed kinds of dependencies are:<br><br>*`swift_library` (or anything propagating `SwiftInfo`)<br><br>*`cc_library` and `objc_library` (or anything propagating `CcInfo`) | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
990
-
| <aid="swift_test-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library. | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
996
+
| <aid="swift_test-srcs"></a>srcs | A list of `.swift` source files that will be compiled into the library.<br><br>Except in very rare circumstances, a Swift source file should only appear in a single `swift_*` target. Adding the same source file to multiple `swift_*` targets can lead to binary bloat and/or symbol collisions. If specific sources need to be shared by multiple targets, consider factoring them out into their own `swift_library` instead.| <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
991
997
| <aid="swift_test-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. | <ahref="https://bazel.build/concepts/labels">List of labels</a> | optional |`[]`|
992
998
| <aid="swift_test-copts"></a>copts | Additional compiler options that should be passed to `swiftc`. These strings are subject to `$(location ...)` and ["Make" variable](https://docs.bazel.build/versions/master/be/make-variables.html) expansion. | List of strings | optional |`[]`|
993
999
| <aid="swift_test-defines"></a>defines | A list of defines to add to the compilation command line.<br><br>Note that unlike C-family languages, Swift defines do not have values; they are simply identifiers that are either defined or undefined. So strings in this list should be simple identifiers, **not**`name=value` pairs.<br><br>Each string is prepended with `-D` and added to the command line. Unlike `copts`, these flags are added for the target and every target that depends on it, so use this attribute with caution. It is preferred that you add defines directly to `copts`, only using this feature in the rare case that a library needs to propagate a symbol up to those that depend on it. | List of strings | optional |`[]`|
0 commit comments