11load ("@bazel_skylib//lib:partial.bzl" , "partial" )
22load ("@bazel_tools//tools/cpp:toolchain_utils.bzl" , "find_cpp_toolchain" , "use_cpp_toolchain" )
3+ load ("@build_bazel_rules_swift//swift:swift.bzl" , "SwiftInfo" )
34load (
45 "@build_bazel_rules_apple//apple/internal:providers.bzl" ,
56 "AppleResourceInfo" ,
@@ -41,6 +42,7 @@ def _framework_middleman(ctx):
4142 dynamic_framework_providers = []
4243 apple_embeddable_infos = []
4344 cc_providers = []
45+ swift_infos = []
4446 cc_toolchain = find_cpp_toolchain (ctx )
4547 cc_features = cc_common .configure_features (
4648 ctx = ctx ,
@@ -64,6 +66,11 @@ def _framework_middleman(ctx):
6466 resource_providers .append (lib_dep [AppleResourceInfo ])
6567 if apple_common .Objc in lib_dep :
6668 objc_providers .append (lib_dep [apple_common .Objc ])
69+ if SwiftInfo in lib_dep :
70+ swift_infos .append (lib_dep [SwiftInfo ])
71+ # Also ensure Swift's CcInfo is collected
72+ if CcInfo in lib_dep and lib_dep not in cc_providers :
73+ cc_providers .append (lib_dep [CcInfo ])
6774 # Bazel 8 compatibility: Try both old and potential new provider names
6875 if hasattr (apple_common , "AppleDynamicFramework" ) and apple_common .AppleDynamicFramework in lib_dep :
6976 dynamic_frameworks .append (lib_dep )
@@ -79,16 +86,14 @@ def _framework_middleman(ctx):
7986 _process_dep (lib_dep )
8087
8188 # Here we only need to loop a subset of the keys
82- objc_provider_fields = objc_provider_utils . merge_objc_providers_dict ( providers = objc_providers , merge_keys = [
83- "dynamic_framework_file" ,
84- ])
89+ # In Bazel 8, dynamic_framework_file is not supported in ObjcInfo
90+ # We'll handle it through CcInfo instead
91+ objc_provider_fields = objc_provider_utils . merge_objc_providers_dict ( providers = objc_providers , merge_keys = [ ])
8592
8693 # Add the frameworks to the objc provider for Bazel <= 6
8794 dynamic_framework_provider = objc_provider_utils .merge_dynamic_framework_providers (dynamic_framework_providers )
88- if dynamic_framework_provider :
89- objc_provider_fields ["dynamic_framework_file" ] = depset (
90- transitive = [dynamic_framework_provider .framework_files , objc_provider_fields .get ("dynamic_framework_file" , depset ([]))],
91- )
95+ # Don't add dynamic_framework_file to ObjcInfo in Bazel 8 - it will be handled via CcInfo
96+
9297 objc_provider = apple_common .new_objc_provider (** objc_provider_fields )
9398
9499 # Add the framework info to the cc info linking context for Bazel >= 7
@@ -115,6 +120,56 @@ def _framework_middleman(ctx):
115120 else :
116121 cc_info_provider = cc_common .merge_cc_infos (cc_infos = cc_providers )
117122
123+ # Bazel 8 compatibility: Collect libraries from ObjcInfo and add to CcInfo
124+ # This ensures all libraries (including .lo files) are properly linked
125+ additional_libraries = []
126+ for objc_p in objc_providers :
127+ # Collect regular libraries
128+ if hasattr (objc_p , "library" ):
129+ additional_libraries .extend (objc_p .library .to_list ())
130+ # Collect force_load libraries (critical for alwayslink)
131+ if hasattr (objc_p , "force_load_library" ):
132+ additional_libraries .extend (objc_p .force_load_library .to_list ())
133+ # Collect imported libraries
134+ if hasattr (objc_p , "imported_library" ):
135+ additional_libraries .extend (objc_p .imported_library .to_list ())
136+ # Collect static framework files
137+ if hasattr (objc_p , "static_framework_file" ):
138+ additional_libraries .extend (objc_p .static_framework_file .to_list ())
139+
140+ # If we found additional libraries not in CcInfo, add them
141+ if additional_libraries :
142+ # Create library_to_link for each additional library
143+ libraries_to_link = []
144+ for lib in additional_libraries :
145+ # Check if it's a static library (.a or .lo)
146+ if lib .path .endswith (".a" ) or lib .path .endswith (".lo" ):
147+ libraries_to_link .append (
148+ cc_common .create_library_to_link (
149+ actions = ctx .actions ,
150+ cc_toolchain = cc_toolchain ,
151+ feature_configuration = cc_features ,
152+ static_library = lib ,
153+ alwayslink = lib .path .endswith (".lo" ), # .lo files are alwayslink
154+ )
155+ )
156+
157+ if libraries_to_link :
158+ additional_cc_info = CcInfo (
159+ linking_context = cc_common .create_linking_context (
160+ linker_inputs = depset ([
161+ cc_common .create_linker_input (
162+ owner = ctx .label ,
163+ libraries = depset (libraries_to_link ),
164+ ),
165+ ]),
166+ ),
167+ )
168+ cc_info_provider = cc_common .merge_cc_infos (
169+ direct_cc_infos = [additional_cc_info ],
170+ cc_infos = [cc_info_provider ],
171+ )
172+
118173 providers = [
119174 cc_info_provider ,
120175 objc_provider ,
@@ -135,6 +190,13 @@ def _framework_middleman(ctx):
135190 if dynamic_framework_provider :
136191 providers .append (dynamic_framework_provider )
137192
193+ # Add SwiftInfo if there are Swift dependencies
194+ if swift_infos :
195+ # For now, just pass through the first SwiftInfo if it exists
196+ # Proper merging of SwiftInfo is complex and would require swift_common.merge_swift_info
197+ if len (swift_infos ) > 0 :
198+ providers .append (swift_infos [0 ])
199+
138200 embed_info_provider = embeddable_info .merge_providers (apple_embeddable_infos )
139201 if embed_info_provider :
140202 providers .append (embed_info_provider )
@@ -238,13 +300,19 @@ def _get_lib_name(name):
238300def _dep_middleman (ctx ):
239301 objc_providers = []
240302 cc_providers = []
303+ swift_infos = []
241304 avoid_libraries = {}
242305
243306 def _collect_providers (lib_dep ):
244307 if apple_common .Objc in lib_dep :
245308 objc_providers .append (lib_dep [apple_common .Objc ])
246309 if CcInfo in lib_dep :
247310 cc_providers .append (lib_dep [CcInfo ])
311+ if SwiftInfo in lib_dep :
312+ swift_infos .append (lib_dep [SwiftInfo ])
313+ # Ensure Swift's CcInfo is also collected
314+ if CcInfo in lib_dep and lib_dep [CcInfo ] not in cc_providers :
315+ cc_providers .append (lib_dep [CcInfo ])
248316
249317 def _process_avoid_deps (avoid_dep_libs ):
250318 for dep in avoid_dep_libs :
@@ -317,14 +385,72 @@ def _dep_middleman(ctx):
317385
318386 # Construct the CcInfo provider, the linking information is used in Bazel >= 7.
319387 cc_info_provider = cc_common .merge_cc_infos (cc_infos = cc_providers )
388+
389+ # Bazel 8 compatibility: Ensure all libraries from ObjcInfo are in CcInfo
390+ # Collect libraries that might not be in CcInfo yet
391+ all_libraries = []
392+ for key in ["library" , "force_load_library" , "imported_library" , "static_framework_file" ]:
393+ if key in objc_provider_fields :
394+ libs = objc_provider_fields [key ].to_list ()
395+ for lib in libs :
396+ # Only add files, not basenames
397+ if hasattr (lib , "path" ):
398+ all_libraries .append (lib )
399+
400+ # Add any missing libraries to CcInfo
401+ if all_libraries :
402+ cc_toolchain = find_cpp_toolchain (ctx )
403+ cc_features = cc_common .configure_features (
404+ ctx = ctx ,
405+ cc_toolchain = cc_toolchain ,
406+ requested_features = ctx .features ,
407+ unsupported_features = ctx .disabled_features ,
408+ )
409+
410+ libraries_to_link = []
411+ for lib in all_libraries :
412+ if lib .path .endswith (".a" ) or lib .path .endswith (".lo" ):
413+ libraries_to_link .append (
414+ cc_common .create_library_to_link (
415+ actions = ctx .actions ,
416+ cc_toolchain = cc_toolchain ,
417+ feature_configuration = cc_features ,
418+ static_library = lib ,
419+ alwayslink = lib .path .endswith (".lo" ),
420+ )
421+ )
422+
423+ if libraries_to_link :
424+ additional_cc_info = CcInfo (
425+ linking_context = cc_common .create_linking_context (
426+ linker_inputs = depset ([
427+ cc_common .create_linker_input (
428+ owner = ctx .label ,
429+ libraries = depset (libraries_to_link ),
430+ ),
431+ ]),
432+ ),
433+ )
434+ cc_info_provider = cc_common .merge_cc_infos (
435+ direct_cc_infos = [additional_cc_info ],
436+ cc_infos = [cc_info_provider ],
437+ )
320438
321- return [
439+ providers = [
322440 cc_info_provider ,
323441 objc_provider ,
324442 ]
443+
444+ # Add SwiftInfo if there are Swift dependencies
445+ if swift_infos and len (swift_infos ) > 0 :
446+ # Pass through the first SwiftInfo (simplified - may need proper merging)
447+ providers .append (swift_infos [0 ])
448+
449+ return providers
325450
326451dep_middleman = rule (
327452 implementation = _dep_middleman ,
453+ toolchains = use_cpp_toolchain (),
328454 attrs = {
329455 "deps" : attr .label_list (
330456 cfg = transition_support .apple_platform_split_transition ,
0 commit comments