1
1
load ("@bazel_skylib//lib:partial.bzl" , "partial" )
2
2
load ("@bazel_tools//tools/cpp:toolchain_utils.bzl" , "find_cpp_toolchain" , "use_cpp_toolchain" )
3
+ load ("@build_bazel_rules_swift//swift:swift.bzl" , "SwiftInfo" )
3
4
load (
4
5
"@build_bazel_rules_apple//apple/internal:providers.bzl" ,
5
6
"AppleResourceInfo" ,
@@ -41,6 +42,7 @@ def _framework_middleman(ctx):
41
42
dynamic_framework_providers = []
42
43
apple_embeddable_infos = []
43
44
cc_providers = []
45
+ swift_infos = []
44
46
cc_toolchain = find_cpp_toolchain (ctx )
45
47
cc_features = cc_common .configure_features (
46
48
ctx = ctx ,
@@ -64,6 +66,11 @@ def _framework_middleman(ctx):
64
66
resource_providers .append (lib_dep [AppleResourceInfo ])
65
67
if apple_common .Objc in lib_dep :
66
68
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 ])
67
74
# Bazel 8 compatibility: Try both old and potential new provider names
68
75
if hasattr (apple_common , "AppleDynamicFramework" ) and apple_common .AppleDynamicFramework in lib_dep :
69
76
dynamic_frameworks .append (lib_dep )
@@ -79,16 +86,14 @@ def _framework_middleman(ctx):
79
86
_process_dep (lib_dep )
80
87
81
88
# 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 = [ ])
85
92
86
93
# Add the frameworks to the objc provider for Bazel <= 6
87
94
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
+
92
97
objc_provider = apple_common .new_objc_provider (** objc_provider_fields )
93
98
94
99
# Add the framework info to the cc info linking context for Bazel >= 7
@@ -115,6 +120,56 @@ def _framework_middleman(ctx):
115
120
else :
116
121
cc_info_provider = cc_common .merge_cc_infos (cc_infos = cc_providers )
117
122
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
+
118
173
providers = [
119
174
cc_info_provider ,
120
175
objc_provider ,
@@ -135,6 +190,13 @@ def _framework_middleman(ctx):
135
190
if dynamic_framework_provider :
136
191
providers .append (dynamic_framework_provider )
137
192
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
+
138
200
embed_info_provider = embeddable_info .merge_providers (apple_embeddable_infos )
139
201
if embed_info_provider :
140
202
providers .append (embed_info_provider )
@@ -238,13 +300,19 @@ def _get_lib_name(name):
238
300
def _dep_middleman (ctx ):
239
301
objc_providers = []
240
302
cc_providers = []
303
+ swift_infos = []
241
304
avoid_libraries = {}
242
305
243
306
def _collect_providers (lib_dep ):
244
307
if apple_common .Objc in lib_dep :
245
308
objc_providers .append (lib_dep [apple_common .Objc ])
246
309
if CcInfo in lib_dep :
247
310
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 ])
248
316
249
317
def _process_avoid_deps (avoid_dep_libs ):
250
318
for dep in avoid_dep_libs :
@@ -317,14 +385,72 @@ def _dep_middleman(ctx):
317
385
318
386
# Construct the CcInfo provider, the linking information is used in Bazel >= 7.
319
387
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
+ )
320
438
321
- return [
439
+ providers = [
322
440
cc_info_provider ,
323
441
objc_provider ,
324
442
]
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
325
450
326
451
dep_middleman = rule (
327
452
implementation = _dep_middleman ,
453
+ toolchains = use_cpp_toolchain (),
328
454
attrs = {
329
455
"deps" : attr .label_list (
330
456
cfg = transition_support .apple_platform_split_transition ,
0 commit comments