Skip to content

Commit

Permalink
Add mixed_langauge_library
Browse files Browse the repository at this point in the history
Replaces `experimental_mixed_langauge_library` in rules_apple. Meant to support SE-0403.

Signed-off-by: Brentley Jones <github@brentleyjones.com>
  • Loading branch information
brentleyjones committed Jul 23, 2024
1 parent 293fb3c commit 16b82ca
Show file tree
Hide file tree
Showing 15 changed files with 910 additions and 8 deletions.
2 changes: 2 additions & 0 deletions doc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ _DOC_SRCS = {
"swift_interop_hint",
"swift_library",
"swift_library_group",
"mixed_language_library",
"swift_module_alias",
"swift_package_configuration",
"swift_test",
Expand Down Expand Up @@ -170,6 +171,7 @@ bzl_library(
srcs = ["//doc:doc.bzl"],
visibility = ["//doc:__pkg__"],
deps = [
"//mixed_language",
"//proto",
"//swift",
],
Expand Down
7 changes: 4 additions & 3 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ A provider whose type/layout is an implementation detail and should not
## swift_common.create_swift_module

<pre>
swift_common.create_swift_module(<a href="#swift_common.create_swift_module-swiftdoc">swiftdoc</a>, <a href="#swift_common.create_swift_module-swiftmodule">swiftmodule</a>, <a href="#swift_common.create_swift_module-ast_files">ast_files</a>, <a href="#swift_common.create_swift_module-defines">defines</a>, <a href="#swift_common.create_swift_module-indexstore">indexstore</a>, <a href="#swift_common.create_swift_module-plugins">plugins</a>,
<a href="#swift_common.create_swift_module-swiftsourceinfo">swiftsourceinfo</a>, <a href="#swift_common.create_swift_module-swiftinterface">swiftinterface</a>, <a href="#swift_common.create_swift_module-private_swiftinterface">private_swiftinterface</a>,
<a href="#swift_common.create_swift_module-const_protocols_to_gather">const_protocols_to_gather</a>)
swift_common.create_swift_module(<a href="#swift_common.create_swift_module-swiftdoc">swiftdoc</a>, <a href="#swift_common.create_swift_module-swiftmodule">swiftmodule</a>, <a href="#swift_common.create_swift_module-ast_files">ast_files</a>, <a href="#swift_common.create_swift_module-defines">defines</a>, <a href="#swift_common.create_swift_module-generated_header">generated_header</a>,
<a href="#swift_common.create_swift_module-indexstore">indexstore</a>, <a href="#swift_common.create_swift_module-plugins">plugins</a>, <a href="#swift_common.create_swift_module-swiftsourceinfo">swiftsourceinfo</a>, <a href="#swift_common.create_swift_module-swiftinterface">swiftinterface</a>,
<a href="#swift_common.create_swift_module-private_swiftinterface">private_swiftinterface</a>, <a href="#swift_common.create_swift_module-const_protocols_to_gather">const_protocols_to_gather</a>)
</pre>

Creates a value representing a Swift module use as a Swift dependency.
Expand All @@ -492,6 +492,7 @@ Creates a value representing a Swift module use as a Swift dependency.
| <a id="swift_common.create_swift_module-swiftmodule"></a>swiftmodule | The `.swiftmodule` file emitted by the compiler for this module. | none |
| <a id="swift_common.create_swift_module-ast_files"></a>ast_files | A list of `File`s output from the `DUMP_AST` action. | `[]` |
| <a id="swift_common.create_swift_module-defines"></a>defines | A list of defines that will be provided as `copts` to targets that depend on this module. If omitted, the empty list will be used. | `[]` |
| <a id="swift_common.create_swift_module-generated_header"></a>generated_header | A `File` representing the Swift generated header. | `None` |
| <a id="swift_common.create_swift_module-indexstore"></a>indexstore | A `File` representing the directory that contains the index store data generated by the compiler if the `"swift.index_while_building"` feature is enabled, otherwise this will be `None`. | `None` |
| <a id="swift_common.create_swift_module-plugins"></a>plugins | A list of `SwiftCompilerPluginInfo` providers representing compiler plugins that are required by this module and should be loaded by the compiler when this module is directly depended on. | `[]` |
| <a id="swift_common.create_swift_module-swiftsourceinfo"></a>swiftsourceinfo | The `.swiftsourceinfo` file emitted by the compiler for this module. May be `None` if no source info file was emitted. | `None` |
Expand Down
5 changes: 5 additions & 0 deletions doc/doc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ load("@build_bazel_rules_swift//proto:swift_proto_library.bzl", "swift_proto_lib
```
"""

load(
"//mixed_language:mixed_language_library.bzl",
_mixed_language_library = "mixed_language_library",
)
load(
"//proto:swift_proto_common.bzl",
_swift_proto_common = "swift_proto_common",
Expand Down Expand Up @@ -102,6 +106,7 @@ swift_import = _swift_import
swift_interop_hint = _swift_interop_hint
swift_library = _swift_library
swift_library_group = _swift_library_group
mixed_language_library = _mixed_language_library
swift_module_alias = _swift_module_alias
swift_package_configuration = _swift_package_configuration
swift_test = _swift_test
42 changes: 42 additions & 0 deletions doc/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ On this page:
* [swift_interop_hint](#swift_interop_hint)
* [swift_library](#swift_library)
* [swift_library_group](#swift_library_group)
* [mixed_language_library](#mixed_language_library)
* [swift_module_alias](#swift_module_alias)
* [swift_package_configuration](#swift_package_configuration)
* [swift_test](#swift_test)
Expand Down Expand Up @@ -802,3 +803,44 @@ swift_library(
| <a id="universal_swift_compiler_plugin-plugin"></a>plugin | Target to generate a 'fat' binary from. | <a href="https://bazel.build/concepts/labels">Label</a> | required | |


<a id="mixed_language_library"></a>

## mixed_language_library

<pre>
mixed_language_library(<a href="#mixed_language_library-name">name</a>, <a href="#mixed_language_library-clang_copts">clang_copts</a>, <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-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>, <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-private_deps">private_deps</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>, <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>, <a href="#mixed_language_library-kwargs">kwargs</a>)
</pre>

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

**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="mixed_language_library-name"></a>name | The name of the target. | none |
| <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`. | `[]` |
| <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. | `[]` |
| <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 |
| <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` |
| <a id="mixed_language_library-hdrs"></a>hdrs | The list of C, C++, Objective-C, or Objective-C++ header files published by this library to be included by sources in dependent rules. This can't include `umbrella_header`. | `[]` |
| <a id="mixed_language_library-includes"></a>includes | List of `#include`/`#import` search paths to add to this target and all depending targets. | `[]` |
| <a id="mixed_language_library-linkopts"></a>linkopts | Extra flags to pass to the linker. | `[]` |
| <a id="mixed_language_library-module_map"></a>module_map | A `File` representing an existing module map that should be used to represent the module, or `None` (the default) if the module map should be generated based on `hdrs`. If this argument is provided, then `module_name` must also be provided.<br><br>Warning: If a module map (whether provided here or not) is able to be found via an include path, it will result in duplicate module definition errors for downstream targets unless sandboxing or remote execution is used. | `None` |
| <a id="mixed_language_library-module_name"></a>module_name | The name of the Swift module being built.<br><br>If left unspecified, the module name will be computed based on the target's build label, by stripping the leading `//` and replacing `/`, `:`, and other non-identifier characters with underscores. | `None` |
| <a id="mixed_language_library-private_deps"></a>private_deps | A list of targets that are implementation-only dependencies of the target being built. Libraries/linker flags from these dependencies will be propagated to dependent for linking, but artifacts/flags required for compilation (such as .swiftmodule files, C headers, and search paths) will not be propagated. | `[]` |
| <a id="mixed_language_library-sdk_frameworks"></a>sdk_frameworks | A list of SDK frameworks to link with (e.g. "AddressBook", "QuartzCore").<br><br>When linking a top level Apple binary, all SDK frameworks listed in that binary's transitive dependency graph are linked. | `[]` |
| <a id="mixed_language_library-swift_copts"></a>swift_copts | The compiler flags for the swift library. | `[]` |
| <a id="mixed_language_library-swift_defines"></a>swift_defines | A list of Swift 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 `swift_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 `swift_copts`, only using this feature in the rare case that a library needs to propagate a symbol up to those that depend on it. | `[]` |
| <a id="mixed_language_library-swift_srcs"></a>swift_srcs | The sources for the swift library. | none |
| <a id="mixed_language_library-swiftc_inputs"></a>swiftc_inputs | Additional files that are referenced using `$(location ...)` in attributes that support location expansion. | `[]` |
| <a id="mixed_language_library-textual_hdrs"></a>textual_hdrs | The list of C, C++, Objective-C, or Objective-C++ files that are included as headers by source files in this rule or by users of this library. Unlike `hdrs`, these will not be compiled separately from the sources. | `[]` |
| <a id="mixed_language_library-umbrella_header"></a>umbrella_header | A `File` representing an existing umbrella header that should be used in the generated module map or is used in the custom module map, or `None` (the default) if the umbrella header should be generated based on `hdrs`. A symlink to this header is added to an include path such that `#import <ModuleName/ModuleName.h>` works for this and downstream targets. | `None` |
| <a id="mixed_language_library-weak_sdk_frameworks"></a>weak_sdk_frameworks | A list of SDK frameworks to weakly link with. For instance, "MediaAccessibility". In difference to regularly linked SDK frameworks, symbols from weakly linked frameworks do not cause an error if they are not present at runtime. | `[]` |
| <a id="mixed_language_library-deps"></a>deps | A list of targets that are dependencies of the target being built. | `[]` |
| <a id="mixed_language_library-kwargs"></a>kwargs | Additional arguments to pass to the underlying clang and swift library targets. | none |


26 changes: 26 additions & 0 deletions mixed_language/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

bzl_library(
name = "mixed_language",
deps = [
":mixed_language_library",
],
)

bzl_library(
name = "mixed_language_library",
srcs = ["mixed_language_library.bzl"],
deps = [
"//mixed_language/internal:library",
"//mixed_language/internal:module_map",
"//mixed_language/internal:umbrella_header",
"//swift:swift_interop_hint",
"//swift:swift_library",
"//swift/internal:compiling",
"@bazel_skylib//lib:paths",
],
)
40 changes: 40 additions & 0 deletions mixed_language/internal/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

licenses(["notice"])

bzl_library(
name = "library",
srcs = ["library.bzl"],
visibility = ["//mixed_language:__subpackages__"],
deps = [
"//swift:providers",
"//swift:swift_clang_module_aspect",
"//swift/internal:attrs",
"//swift/internal:compiling",
"//swift/internal:feature_names",
"//swift/internal:features",
"//swift/internal:providers",
"//swift/internal:toolchain_utils",
"//swift/internal:utils",
"@bazel_skylib//lib:dicts",
"@bazel_skylib//lib:paths",
],
)

bzl_library(
name = "module_map",
srcs = ["module_map.bzl"],
visibility = ["//mixed_language:__subpackages__"],
deps = [
"//swift/internal:module_maps",
],
)

bzl_library(
name = "umbrella_header",
srcs = ["umbrella_header.bzl"],
visibility = ["//mixed_language:__subpackages__"],
deps = [
"@bazel_skylib//lib:paths",
],
)
Loading

0 comments on commit 16b82ca

Please sign in to comment.