1- load ("@build_bazel_rules_apple//apple/internal:providers.bzl" , "AppleFrameworkImportInfo" , "new_appleframeworkimportinfo" )
21load ("//rules/internal:objc_provider_utils.bzl" , "objc_provider_utils" )
2+ load ("//rules:utils.bzl" , "is_bazel_7" )
3+ load ("@bazel_tools//tools/cpp:toolchain_utils.bzl" , "find_cpp_toolchain" , "use_cpp_toolchain" )
34load ("@build_bazel_rules_apple//apple/internal:bundling_support.bzl" , "bundling_support" )
5+ load ("@build_bazel_rules_apple//apple/internal:providers.bzl" , "AppleFrameworkImportInfo" , "new_appleframeworkimportinfo" )
46
57_FindImportsAspectInfo = provider (fields = {
68 "imported_library_file" : "" ,
@@ -159,6 +161,15 @@ def _deduplicate_test_deps(test_deps, deps):
159161 return filtered
160162
161163def _file_collector_rule_impl (ctx ):
164+ cc_toolchain = find_cpp_toolchain (ctx )
165+ cc_features = cc_common .configure_features (
166+ ctx = ctx ,
167+ cc_toolchain = cc_toolchain ,
168+ language = "objc" ,
169+ requested_features = ctx .features ,
170+ unsupported_features = ctx .disabled_features ,
171+ )
172+
162173 linker_deps = _merge_linked_inputs (ctx .attr .deps )
163174 test_linker_deps = _merge_linked_inputs (ctx .attr .test_deps )
164175 input_static_frameworks = _deduplicate_test_deps (test_linker_deps [0 ], linker_deps [0 ])
@@ -255,8 +266,31 @@ def _file_collector_rule_impl(ctx):
255266 )
256267
257268 # Create the CcInfo provider, linking information from this is used in Bazel 7+.
258- dep_cc_infos = [dep [CcInfo ] for dep in ctx .attr .deps if CcInfo in dep ]
259- cc_info = cc_common .merge_cc_infos (cc_infos = dep_cc_infos )
269+ cc_info = None
270+ if is_bazel_7 :
271+ cc_info = CcInfo (
272+ linking_context = cc_common .create_linking_context (
273+ linker_inputs = depset ([
274+ cc_common .create_linker_input (
275+ owner = ctx .label ,
276+ user_link_flags = compat_link_opt if len (all_replaced_frameworks ) else [],
277+ libraries = depset ([
278+ cc_common .create_library_to_link (
279+ actions = ctx .actions ,
280+ cc_toolchain = cc_toolchain ,
281+ feature_configuration = cc_features ,
282+ static_library = static_library ,
283+ alwayslink = False ,
284+ )
285+ for static_library in replaced_static_framework .replaced .values ()
286+ ]),
287+ ),
288+ ]),
289+ ),
290+ )
291+ else :
292+ dep_cc_infos = [dep [CcInfo ] for dep in ctx .attr .deps if CcInfo in dep ]
293+ cc_info = cc_common .merge_cc_infos (cc_infos = dep_cc_infos )
260294
261295 return [
262296 DefaultInfo (files = depset (dynamic_framework_dirs + replaced_frameworks )),
@@ -266,11 +300,20 @@ def _file_collector_rule_impl(ctx):
266300
267301import_middleman = rule (
268302 implementation = _file_collector_rule_impl ,
269- fragments = ["apple" ],
303+ fragments = ["apple" , "cpp" ],
304+ toolchains = use_cpp_toolchain (),
270305 attrs = {
271306 "deps" : attr .label_list (aspects = [find_imports ]),
272307 "test_deps" : attr .label_list (aspects = [find_imports ], allow_empty = True ),
273308 "update_in_place" : attr .label (executable = True , default = Label ("//tools/m1_utils:update_in_place" ), cfg = "exec" ),
309+ "_cc_toolchain" : attr .label (
310+ providers = [cc_common .CcToolchainInfo ],
311+ default = Label ("@bazel_tools//tools/cpp:current_cc_toolchain" ),
312+ doc = """\
313+ The C++ toolchain from which linking flags and other tools needed by the Swift
314+ toolchain (such as `clang`) will be retrieved.
315+ """ ,
316+ ),
274317 },
275318 doc = """
276319This rule adds the ability to update the Mach-o header on imported
0 commit comments