From 4f4b7f012e714eaecc7f16534690e1183aa1b9ca Mon Sep 17 00:00:00 2001 From: Tony Allevato Date: Thu, 17 Sep 2020 09:07:43 -0700 Subject: [PATCH] Don't propagate an empty module map for `{cc,objc}_library` targets that don't have any headers (and that don't specify an explicit module map using the `module_map` attribute). This is typically the case for libraries that group other libraries via their `deps`. Users mistakenly import these thinking they're required to use the underlying declarations, but they do nothing (except make more work for the compiler). PiperOrigin-RevId: 332246632 (cherry picked from commit 639ecfa9a164fc94ed205c25e6e43353ca0699c1) --- swift/internal/swift_clang_module_aspect.bzl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/swift/internal/swift_clang_module_aspect.bzl b/swift/internal/swift_clang_module_aspect.bzl index 00dec750f..2b871c685 100644 --- a/swift/internal/swift_clang_module_aspect.bzl +++ b/swift/internal/swift_clang_module_aspect.bzl @@ -179,6 +179,16 @@ def _module_info_for_target( if not aspect_ctx.rule.kind == "objc_library": return None, module_maps[0] + # If an `objc_library` doesn't have any headers (and doesn't specify an + # explicit module map), then don't generate or propagate a module map + # for it. Such modules define nothing and only waste space on the + # compilation command line and add more work for the compiler. + if not getattr(attr, "module_map", None) and not ( + compilation_context.direct_headers or + compilation_context.direct_textual_headers + ): + return None, None + module_name = getattr(attr, "module_name", None) if not module_name: module_name = derive_module_name(target.label)