diff --git a/apple/internal/experimental_mixed_language_library.bzl b/apple/internal/experimental_mixed_language_library.bzl index c71093e6a3..a5c3fe28d3 100644 --- a/apple/internal/experimental_mixed_language_library.bzl +++ b/apple/internal/experimental_mixed_language_library.bzl @@ -195,6 +195,7 @@ def experimental_mixed_language_library( name, srcs, deps = [], + enable_modules = False, module_name = None, objc_copts = [], swift_copts = [], @@ -212,13 +213,14 @@ def experimental_mixed_language_library( it easier to migrate codebases with mixed language modules to Bazel without having to demix them first. - This macro only supports a very simple use case of mixed language - modules---it does not support for header maps or Clang modules. + This macro only supports a simple use case of mixed language + modules, it does not support header maps. Args: name: A unique name for this target. deps: A list of targets that are dependencies of the target being built, which will be linked into that target. + enable_modules: Enables clang module support for the Objective-C target. module_name: The name of the mixed language module being built. If left unspecified, the module name will be the name of the target. @@ -267,6 +269,7 @@ target only contains Objective-C files.""") swift_library_name = name + ".internal.swift" objc_deps = [] + objc_copts = [] + objc_copts swift_deps = [] + deps swift_copts = swift_copts + [ @@ -275,6 +278,12 @@ target only contains Objective-C files.""") "-import-underlying-module", ] + # Modules is not enabled if a custom module map is present even with + # `enable_modules` set to `True` in `objc_library`. This enables it via copts. + # See: https://github.com/bazelbuild/bazel/issues/20703 + if enable_modules: + objc_copts.append("-fmodules") + objc_deps = [":" + swift_library_name] # Add Obj-C includes to Swift header search paths diff --git a/doc/rules-apple.md b/doc/rules-apple.md index 68d166cbc7..f3c1e07ed7 100755 --- a/doc/rules-apple.md +++ b/doc/rules-apple.md @@ -375,8 +375,8 @@ ios_application( ## experimental_mixed_language_library
-experimental_mixed_language_library(name, srcs, deps, module_name, objc_copts, swift_copts,
-                                    swiftc_inputs, testonly, kwargs)
+experimental_mixed_language_library(name, srcs, deps, enable_modules, module_name, objc_copts,
+                                    swift_copts, swiftc_inputs, testonly, kwargs)
 
Compiles and links Objective-C and Swift code into a static library. @@ -390,8 +390,8 @@ mixed language modules in some old codebases. This macro is meant to make it easier to migrate codebases with mixed language modules to Bazel without having to demix them first. -This macro only supports a very simple use case of mixed language -modules---it does not support for header maps or Clang modules. +This macro only supports a simple use case of mixed language +modules, it does not support header maps. **PARAMETERS** @@ -402,6 +402,7 @@ modules---it does not support for header maps or Clang modules. | name | A unique name for this target. | none | | srcs | The list of Objective-C and Swift source files to compile. | none | | deps | A list of targets that are dependencies of the target being built, which will be linked into that target. | `[]` | +| enable_modules | Enables clang module support for the Objective-C target. | `False` | | module_name | The name of the mixed language module being built. If left unspecified, the module name will be the name of the target. | `None` | | objc_copts | Additional compiler options that should be passed to `clang`. | `[]` | | swift_copts | Additional compiler options that should be passed to `swiftc`. These strings are subject to `$(location ...)` and "Make" variable expansion. | `[]` | diff --git a/examples/multi_platform/MixedLib/BUILD b/examples/multi_platform/MixedLib/BUILD index 912dc3d315..fc5e9077ee 100644 --- a/examples/multi_platform/MixedLib/BUILD +++ b/examples/multi_platform/MixedLib/BUILD @@ -12,6 +12,7 @@ experimental_mixed_language_library( "MixedAnswer.swift", ], hdrs = ["MixedAnswer.h"], + enable_modules = True, ) swift_library( diff --git a/examples/multi_platform/MixedLib/MixedAnswer.h b/examples/multi_platform/MixedLib/MixedAnswer.h index 9798bd7c94..24ce6ac6fb 100644 --- a/examples/multi_platform/MixedLib/MixedAnswer.h +++ b/examples/multi_platform/MixedLib/MixedAnswer.h @@ -1,4 +1,4 @@ -#import +@import Foundation; @interface MixedAnswerObjc : NSObject