Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Don't propagate an empty module map for {cc,objc}_library targets t…
Browse files Browse the repository at this point in the history
…hat 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
  • Loading branch information
allevato authored and swiple-rules-gardener committed Sep 17, 2020
1 parent 74f3f87 commit 639ecfa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions swift/internal/swift_clang_module_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 639ecfa

Please sign in to comment.