@@ -537,6 +537,7 @@ def apple_library(
537537 namespace = module_name if namespace_is_module_name else name
538538 module_map = kwargs .pop ("module_map" , None )
539539 swift_objc_bridging_header = kwargs .pop ("swift_objc_bridging_header" , None )
540+ has_swift_sources = len (swift_sources ) > 0
540541
541542 # Historically, xcode and cocoapods use an umbrella header that imports Foundation and UIKit at the
542543 # beginning of it. See:
@@ -605,7 +606,7 @@ def apple_library(
605606 #
606607 # If other Swift sources are present, generate Swift intent code, otherwise use Obj-C.
607608 # This mimics the behavior for INTENTS_CODEGEN_LANGUAGE="automatic" in Xcode.
608- if len ( swift_sources ) > 0 :
609+ if has_swift_sources :
609610 apple_intent_library (
610611 name = intent_name ,
611612 src = intent ,
@@ -817,7 +818,7 @@ def apple_library(
817818
818819 # TODO: remove under certian circumstances when framework if set
819820 # Needs to happen before headermaps are made, so the generated umbrella header gets added to those headermaps
820- has_compile_srcs = (objc_hdrs or objc_private_hdrs or swift_sources or objc_sources or cpp_sources )
821+ has_compile_srcs = (objc_hdrs or objc_private_hdrs or has_swift_sources or objc_sources or cpp_sources )
821822 generate_umbrella_module = (namespace_is_module_name and has_compile_srcs )
822823 if generate_umbrella_module :
823824 if not module_map :
@@ -840,33 +841,36 @@ def apple_library(
840841 ** kwargs
841842 )
842843
843- framework_vfs_overlay (
844- name = framework_vfs_overlay_name_swift ,
845- framework_name = module_name ,
846- modulemap = module_map ,
847- has_swift = len (swift_sources ) > 0 ,
848- private_hdrs = objc_private_hdrs ,
849- hdrs = objc_hdrs ,
850- tags = _MANUAL ,
851- testonly = testonly ,
852- deps = deps + private_deps + private_dep_names + lib_names + import_vfsoverlays ,
853- )
844+ if has_swift_sources :
845+ framework_vfs_overlay (
846+ name = framework_vfs_overlay_name_swift ,
847+ framework_name = module_name ,
848+ modulemap = module_map ,
849+ has_swift = has_swift_sources ,
850+ private_hdrs = objc_private_hdrs ,
851+ hdrs = objc_hdrs ,
852+ tags = _MANUAL ,
853+ testonly = testonly ,
854+ deps = deps + private_deps + private_dep_names + lib_names + import_vfsoverlays ,
855+ )
854856
855857 framework_vfs_objc_copts = [
856858 "-ivfsoverlay$(execpath :{})" .format (framework_vfs_overlay_name ),
857859 "-F{}" .format (VFS_OVERLAY_FRAMEWORK_SEARCH_PATH ),
858860 ]
859- framework_vfs_swift_copts = [
860- "-Xfrontend" ,
861- "-vfsoverlay$(execpath :{})" .format (framework_vfs_overlay_name_swift ),
862- "-Xfrontend" ,
863- "-F{}" .format (VFS_OVERLAY_FRAMEWORK_SEARCH_PATH ),
864- "-I{}" .format (VFS_OVERLAY_FRAMEWORK_SEARCH_PATH ),
865- "-Xcc" ,
866- "-ivfsoverlay$(execpath :{})" .format (framework_vfs_overlay_name_swift ),
867- "-Xcc" ,
868- "-F{}" .format (VFS_OVERLAY_FRAMEWORK_SEARCH_PATH ),
869- ]
861+ framework_vfs_swift_copts = []
862+ if has_swift_sources :
863+ framework_vfs_swift_copts = [
864+ "-Xfrontend" ,
865+ "-vfsoverlay$(execpath :{})" .format (framework_vfs_overlay_name_swift ),
866+ "-Xfrontend" ,
867+ "-F{}" .format (VFS_OVERLAY_FRAMEWORK_SEARCH_PATH ),
868+ "-I{}" .format (VFS_OVERLAY_FRAMEWORK_SEARCH_PATH ),
869+ "-Xcc" ,
870+ "-ivfsoverlay$(execpath :{})" .format (framework_vfs_overlay_name_swift ),
871+ "-Xcc" ,
872+ "-F{}" .format (VFS_OVERLAY_FRAMEWORK_SEARCH_PATH ),
873+ ]
870874
871875 ## BEGIN HMAP
872876
@@ -916,7 +920,7 @@ def apple_library(
916920
917921 module_data = library_tools ["wrap_resources_in_filegroup" ](name = name + "_wrapped_resources_filegroup" , srcs = data , testonly = testonly )
918922
919- if swift_sources :
923+ if has_swift_sources :
920924 additional_swift_copts += ["-Xcc" , "-I." ]
921925 if module_map :
922926 # Frameworks find the modulemap file via the framework vfs overlay
@@ -955,7 +959,7 @@ def apple_library(
955959 framework_vfs_overlay (
956960 name = framework_vfs_overlay_name ,
957961 framework_name = module_name ,
958- has_swift = len ( swift_sources ) > 0 ,
962+ has_swift = has_swift_sources ,
959963 modulemap = module_map ,
960964 private_hdrs = objc_private_hdrs ,
961965 hdrs = objc_hdrs ,
@@ -965,7 +969,7 @@ def apple_library(
965969 #enable_framework_vfs = enable_framework_vfs
966970 )
967971
968- if swift_sources :
972+ if has_swift_sources :
969973 # Forward the kwargs and the swift specific kwargs to the swift_library
970974 swift_library_kwargs = dicts .add (kwargs , swift_kwargs )
971975 swift_library (
@@ -1060,8 +1064,8 @@ def apple_library(
10601064 })
10611065
10621066 additional_objc_vfs_deps = select ({
1063- "@build_bazel_rules_ios//:virtualize_frameworks" : [framework_vfs_overlay_name_swift ] + [ framework_vfs_overlay_name ] ,
1064- "//conditions:default" : [ framework_vfs_overlay_name_swift ] + [ framework_vfs_overlay_name ] if enable_framework_vfs else [],
1067+ "@build_bazel_rules_ios//:virtualize_frameworks" : [framework_vfs_overlay_name ] + ([ framework_vfs_overlay_name_swift ] if has_swift_sources else []) ,
1068+ "//conditions:default" : ([ framework_vfs_overlay_name ] if enable_framework_vfs else []) + ([ framework_vfs_overlay_name_swift ] if has_swift_sources else []) ,
10651069 })
10661070 additional_objc_vfs_copts = select ({
10671071 "@build_bazel_rules_ios//:virtualize_frameworks" : framework_vfs_objc_copts ,
@@ -1083,7 +1087,7 @@ def apple_library(
10831087 weak_sdk_frameworks = weak_sdk_frameworks ,
10841088 sdk_includes = sdk_includes ,
10851089 pch = pch ,
1086- data = [] if swift_sources else [module_data ],
1090+ data = [] if has_swift_sources else [module_data ],
10871091 tags = tags_manual ,
10881092 defines = defines + objc_defines ,
10891093 testonly = testonly ,
@@ -1100,7 +1104,7 @@ def apple_library(
11001104 )
11011105 lib_names .append (objc_libname )
11021106
1103- if export_private_headers :
1107+ if export_private_headers and objc_private_hdrs :
11041108 private_headers_name = "%s_private_headers" % name
11051109 lib_names .append (private_headers_name )
11061110 _private_headers (name = private_headers_name , headers = objc_private_hdrs , tags = _MANUAL )
@@ -1116,5 +1120,5 @@ def apple_library(
11161120 namespace = namespace ,
11171121 linkopts = copts_by_build_setting .linkopts + linkopts ,
11181122 platforms = platforms ,
1119- has_swift_sources = ( swift_sources and len ( swift_sources ) > 0 ) ,
1123+ has_swift_sources = has_swift_sources ,
11201124 )
0 commit comments