From 6aa454059bc28f2b19c751a398b48fb8d5f742f1 Mon Sep 17 00:00:00 2001 From: Sarad Date: Fri, 17 Jan 2025 09:13:43 -0500 Subject: [PATCH] Remove references to objc_provider and remove force_load_direct_deps to support rules_apple > 3.15.0 (#934) 1) With rules_apple removing legacy objc_providers, rules_apple > 3.15.0 is no longer compatible with rules_ios due to https://github.com/bazelbuild/rules_apple/pull/2611 2) Removing force load direct deps as its no longer needed in Bazel 7 https://github.com/bazel-ios/rules_ios/issues/862 ```sh ERROR: /Users/ssarad/Bazel/BUILD.bazel:3:15: in apple_framework_packaging rule Traceback (most recent call last): File "/Users/ssarad/.bazel_cache/output/external/rules_ios~/rules/framework.bzl", line 1109, column 48, in _apple_framework_packaging_impl bundle_outs = _bundle_dynamic_framework(ctx, is_extension_safe = is_extension_safe, avoid_deps = avoid_deps) File "/Users/ssarad/.bazel_cache/output/external/rules_ios~/rules/framework.bzl", line 888, column 44, in _bundle_dynamic_framework partials.framework_provider_partial( File "/Users/ssarad/.bazel_cache/output/external/rules_apple~/apple/internal/partials/framework_provider.bzl", line 94, column 5, in framework_provider_partial def framework_provider_partial( Error: framework_provider_partial() got unexpected keyword argument: objc_provider ``` This PR is attempt to make rules_ios compatible with rules_apple + remove the legacy code to force load direct deps as with Bazel 7, `--incompatible_objc_alwayslink_by_default` does the same thing. --------- Co-authored-by: Sarad --- .github/workflows/tests.yml | 2 +- MODULE.bazel | 4 +- README.md | 2 +- docs/BUILD.bazel | 1 - docs/app_clip_doc.md | 2 + docs/app_doc.md | 2 + docs/extension_doc.md | 2 + docs/force_load_direct_deps_doc.md | 48 ----- docs/framework_doc.md | 4 + docs/hmap_doc.md | 7 +- docs/import_middleman_doc.md | 4 + docs/library_doc.md | 7 +- docs/plists_doc.md | 6 + docs/precompiled_apple_resource_bundle_doc.md | 2 + docs/providers_doc.md | 10 +- docs/substitute_build_settings_doc.md | 2 + docs/test_doc.md | 18 ++ docs/transition_support_doc.md | 2 + docs/vfs_overlay_doc.md | 4 + docs/xcconfig_doc.md | 6 + rules/BUILD.bazel | 15 -- rules/app.bzl | 15 +- rules/app_clip.bzl | 12 +- rules/extension.bzl | 12 +- rules/force_load_direct_deps.bzl | 176 ------------------ rules/framework.bzl | 17 -- rules/import_middleman.bzl | 19 +- rules/library.bzl | 2 + 28 files changed, 86 insertions(+), 317 deletions(-) delete mode 100755 docs/force_load_direct_deps_doc.md delete mode 100644 rules/force_load_direct_deps.bzl diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 902c73f13..1b7ad5ddd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,7 +29,7 @@ jobs: XCODE_VERSION: ${{ matrix.xcode_version }} USE_BAZEL_VERSION: ${{ matrix.bazel_version }} LATEST_RULES_SWIFT_VERSION: 2.1.1 - LATEST_RULES_APPLE_VERSION: 3.8.0 + LATEST_RULES_APPLE_VERSION: 3.15.0 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v4 diff --git a/MODULE.bazel b/MODULE.bazel index 23dbee47e..fd51d66ab 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -22,12 +22,12 @@ bazel_dep( ) bazel_dep( name = "rules_apple", - version = "3.5.1", + version = "3.15.0", repo_name = "build_bazel_rules_apple", ) bazel_dep( name = "rules_cc", - version = "0.0.6", + version = "0.0.10", ) bazel_dep( name = "rules_swift", diff --git a/README.md b/README.md index d3b57c220..19902fe7c 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ See the following table for supported rules_apple release versions. | rules_apple release | Minimum supported rules version | Final supported rules version |:-------------------:|:-------------------------:|:-------------------------: -| 3.5.1 | 4.3.1 | current +| 3.15.0 | 5.3.0 | current | 3.* | 3.* | 4.2.1 | 2.* | 2.* | 3.2.2 | 1.* | 1.0.0 | 3.2.2 diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 2dbbc1cd1..b553aa2d2 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -14,7 +14,6 @@ _DOC_SRCS = [ "import_middleman", "library", "plists", - "force_load_direct_deps", "precompiled_apple_resource_bundle", "providers", "substitute_build_settings", diff --git a/docs/app_clip_doc.md b/docs/app_clip_doc.md index 880d7f97e..0f2fb9b11 100755 --- a/docs/app_clip_doc.md +++ b/docs/app_clip_doc.md @@ -7,6 +7,8 @@ ## ios_app_clip
+load("@rules_ios//rules:app_clip.bzl", "ios_app_clip")
+
 ios_app_clip(name, families, infoplists, infoplists_by_build_setting, xcconfig,
              xcconfig_by_build_setting, kwargs)
 
diff --git a/docs/app_doc.md b/docs/app_doc.md index 8e64f75dc..e24713980 100755 --- a/docs/app_doc.md +++ b/docs/app_doc.md @@ -7,6 +7,8 @@ ## ios_application
+load("@rules_ios//rules:app.bzl", "ios_application")
+
 ios_application(name, families, apple_library, infoplists, infoplists_by_build_setting, xcconfig,
                 xcconfig_by_build_setting, kwargs)
 
diff --git a/docs/extension_doc.md b/docs/extension_doc.md index 6013b9d99..27a5ee862 100755 --- a/docs/extension_doc.md +++ b/docs/extension_doc.md @@ -7,6 +7,8 @@ ## ios_extension
+load("@rules_ios//rules:extension.bzl", "ios_extension")
+
 ios_extension(name, families, infoplists, infoplists_by_build_setting, xcconfig,
               xcconfig_by_build_setting, kwargs)
 
diff --git a/docs/force_load_direct_deps_doc.md b/docs/force_load_direct_deps_doc.md deleted file mode 100755 index fc9fa68a7..000000000 --- a/docs/force_load_direct_deps_doc.md +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - -## force_load_direct_deps - -
-force_load_direct_deps(name, deps, minimum_os_version, platform_type, should_force_load)
-
- -A rule to link with `-force_load` for direct`deps` - -ld has different behavior when loading members of a static library VS objects -as far as visibility. Under `-dynamic` -- linked _swift object files_ can have public visibility -- symbols from _swift static libraries_ are omitted unless used, and not -visible otherwise - -By using `-force_load`, we can load static libraries in the attributes of an -application's direct depenencies. These args need go at the _front_ of the -linker invocation otherwise these arguments don't work with lds logic. - -Why not put it into `rules_apple`? Ideally it could be, and perhaps consider a -PR to there .The underlying java rule, `AppleBinary.linkMultiArchBinary` -places `extraLinkopts` at the end of the linker invocation. At the time of -writing these args need to go into the current rule context where -`AppleBinary.linkMultiArchBinary` is called. - -One use case of this is that iOS developers want to load above mentioned -symbols from applications. Another alternate could be to create an aspect, -that actually generates a different application and linker invocation instead -of force loading symbols. This could be more complicated from an integration -perspective so it isn't used. - -**ATTRIBUTES** - - -| Name | Description | Type | Mandatory | Default | -| :------------- | :------------- | :------------- | :------------- | :------------- | -| name | A unique name for this target. | Name | required | | -| deps | Deps | List of labels | required | | -| minimum_os_version | Internal - currently rules_ios the dict `platforms` | String | optional | `""` | -| platform_type | Internal - currently rules_ios uses the dict `platforms` | String | optional | `""` | -| should_force_load | Allows parametrically enabling the functionality in this rule. | Boolean | optional | `True` | - - diff --git a/docs/framework_doc.md b/docs/framework_doc.md index 1d5ae76ba..1566020e2 100755 --- a/docs/framework_doc.md +++ b/docs/framework_doc.md @@ -7,6 +7,8 @@ Framework rules ## apple_framework_packaging
+load("@rules_ios//rules:framework.bzl", "apple_framework_packaging")
+
 apple_framework_packaging(name, deps, data, bundle_extension, bundle_id, environment_plist,
                           exported_symbols_lists, framework_name, frameworks, infoplists,
                           library_linkopts, link_dynamic, minimum_deployment_os_version,
@@ -49,6 +51,8 @@ Packages compiled code into an Apple .framework package
 ## apple_framework
 
 
+load("@rules_ios//rules:framework.bzl", "apple_framework")
+
 apple_framework(name, apple_library, infoplists, infoplists_by_build_setting, xcconfig,
                 xcconfig_by_build_setting, kwargs)
 
diff --git a/docs/hmap_doc.md b/docs/hmap_doc.md index e28067dbe..9898e86de 100755 --- a/docs/hmap_doc.md +++ b/docs/hmap_doc.md @@ -7,6 +7,8 @@ Header Map rules ## headermap
+load("@rules_ios//rules:hmap.bzl", "headermap")
+
 headermap(name, hdrs, direct_hdr_providers, namespace)
 
@@ -32,6 +34,8 @@ regardless of the package structure being used. ## HeaderMapInfo
+load("@rules_ios//rules:hmap.bzl", "HeaderMapInfo")
+
 HeaderMapInfo(files)
 
@@ -39,7 +43,6 @@ Propagates header maps **FIELDS** - | Name | Description | | :------------- | :------------- | | files | depset with headermaps | @@ -50,6 +53,8 @@ Propagates header maps ## hmap.make_hmap
+load("@rules_ios//rules:hmap.bzl", "hmap")
+
 hmap.make_hmap(actions, headermap_builder, output, namespace, hdrs_lists)
 
diff --git a/docs/import_middleman_doc.md b/docs/import_middleman_doc.md index 1cfcf4b4a..235fc36fb 100755 --- a/docs/import_middleman_doc.md +++ b/docs/import_middleman_doc.md @@ -7,6 +7,8 @@ ## import_middleman
+load("@rules_ios//rules:import_middleman.bzl", "import_middleman")
+
 import_middleman(name, deps, test_deps, update_in_place)
 
@@ -50,6 +52,8 @@ can be updated to work without the other behavior ## find_imports
+load("@rules_ios//rules:import_middleman.bzl", "find_imports")
+
 find_imports(name)
 
diff --git a/docs/library_doc.md b/docs/library_doc.md index 1a9790f4d..e8f0bfc17 100755 --- a/docs/library_doc.md +++ b/docs/library_doc.md @@ -7,6 +7,8 @@ Library rules ## extend_modulemap
+load("@rules_ios//rules:library.bzl", "extend_modulemap")
+
 extend_modulemap(name, destination, module_name, source, swift_header)
 
@@ -29,6 +31,8 @@ Extends a modulemap with a Swift submodule ## PrivateHeadersInfo
+load("@rules_ios//rules:library.bzl", "PrivateHeadersInfo")
+
 PrivateHeadersInfo(headers)
 
@@ -36,7 +40,6 @@ Propagates private headers, so they can be accessed if necessary **FIELDS** - | Name | Description | | :------------- | :------------- | | headers | Private headers | @@ -47,6 +50,8 @@ Propagates private headers, so they can be accessed if necessary ## apple_library
+load("@rules_ios//rules:library.bzl", "apple_library")
+
 apple_library(name, library_tools, export_private_headers, namespace_is_module_name,
               default_xcconfig_name, xcconfig, xcconfig_by_build_setting, objc_defines, swift_defines,
               kwargs)
diff --git a/docs/plists_doc.md b/docs/plists_doc.md
index 67110b175..e38cd86be 100755
--- a/docs/plists_doc.md
+++ b/docs/plists_doc.md
@@ -7,6 +7,8 @@ Defines macros for working with plist files.
 ## process_infoplists
 
 
+load("@rules_ios//rules:plists.bzl", "process_infoplists")
+
 process_infoplists(name, infoplists, infoplists_by_build_setting, xcconfig,
                    xcconfig_by_build_setting)
 
@@ -34,6 +36,8 @@ A selectable dict of the substituted_plists grouped by config_setting ## substituted_plist
+load("@rules_ios//rules:plists.bzl", "substituted_plist")
+
 substituted_plist(name, plist, xcconfig)
 
@@ -58,6 +62,8 @@ The plist target with the substituted variables. ## write_info_plists_if_needed
+load("@rules_ios//rules:plists.bzl", "write_info_plists_if_needed")
+
 write_info_plists_if_needed(name, plists)
 
diff --git a/docs/precompiled_apple_resource_bundle_doc.md b/docs/precompiled_apple_resource_bundle_doc.md index f9c8db6c2..278ae416c 100755 --- a/docs/precompiled_apple_resource_bundle_doc.md +++ b/docs/precompiled_apple_resource_bundle_doc.md @@ -11,6 +11,8 @@ if this is ever fixed in bazel it should be removed ## precompiled_apple_resource_bundle
+load("@rules_ios//rules:precompiled_apple_resource_bundle.bzl", "precompiled_apple_resource_bundle")
+
 precompiled_apple_resource_bundle(kwargs)
 
diff --git a/docs/providers_doc.md b/docs/providers_doc.md index 84541ee90..f4494acd8 100755 --- a/docs/providers_doc.md +++ b/docs/providers_doc.md @@ -7,14 +7,13 @@ ## AvoidDepsInfo
+load("@rules_ios//rules:providers.bzl", "AvoidDepsInfo")
+
 AvoidDepsInfo(libraries, link_dynamic)
 
- - **FIELDS** - | Name | Description | | :------------- | :------------- | | libraries | Libraries to avoid | @@ -26,14 +25,13 @@ AvoidDepsInfo(libraries, vfsoverlay_infos, binary, headers, private_headers, modulemap, swiftmodule, swiftdoc)
- - **FIELDS** - | Name | Description | | :------------- | :------------- | | vfsoverlay_infos | Merged VFS overlay infos, present when virtual frameworks enabled | diff --git a/docs/substitute_build_settings_doc.md b/docs/substitute_build_settings_doc.md index 055e1891f..367596fef 100755 --- a/docs/substitute_build_settings_doc.md +++ b/docs/substitute_build_settings_doc.md @@ -7,6 +7,8 @@ ## substitute_build_settings
+load("@rules_ios//rules:substitute_build_settings.bzl", "substitute_build_settings")
+
 substitute_build_settings(name, source, variables)
 
diff --git a/docs/test_doc.md b/docs/test_doc.md index 78c2876bb..4d6c53b63 100755 --- a/docs/test_doc.md +++ b/docs/test_doc.md @@ -7,6 +7,8 @@ ## default_test_factory.make_named_split
+load("@rules_ios//rules:test.bzl", "default_test_factory")
+
 default_test_factory.make_named_split(name, split_kwargs, in_split)
 
@@ -27,6 +29,8 @@ default_test_factory.make_named_split(name, runner, in_split)
@@ -47,6 +51,8 @@ default_test_factory.make_runner_split(name, test_rule, kwargs) @@ -67,6 +73,8 @@ Helper to create an individual test ## default_test_factory.make_test_suite
+load("@rules_ios//rules:test.bzl", "default_test_factory")
+
 default_test_factory.make_test_suite(factory, name, test_rule, test_kwargs)
 
@@ -88,6 +96,8 @@ default_test_factory.make_test_suite(factory, name, in_kwargs) @@ -113,6 +123,8 @@ Finally - you can set the splits to be whatever you want. ## default_test_factory.make_tests
+load("@rules_ios//rules:test.bzl", "default_test_factory")
+
 default_test_factory.make_tests(factory, name, test_rule, kwargs)
 
@@ -134,6 +146,8 @@ Main entry point of generating tests" ## ios_ui_test
+load("@rules_ios//rules:test.bzl", "ios_ui_test")
+
 ios_ui_test(name, apple_library, test_factory, kwargs)
 
@@ -155,6 +169,8 @@ Builds and packages iOS UI Tests. ## ios_unit_snapshot_test
+load("@rules_ios//rules:test.bzl", "ios_unit_snapshot_test")
+
 ios_unit_snapshot_test(name, apple_library, test_factory, kwargs)
 
@@ -176,6 +192,8 @@ Builds and packages iOS Unit Snapshot Tests. ## ios_unit_test
+load("@rules_ios//rules:test.bzl", "ios_unit_test")
+
 ios_unit_test(name, apple_library, test_factory, kwargs)
 
diff --git a/docs/transition_support_doc.md b/docs/transition_support_doc.md index 152950121..c71c9caca 100755 --- a/docs/transition_support_doc.md +++ b/docs/transition_support_doc.md @@ -23,6 +23,8 @@ part on the language used for XCFramework library identifiers: ## transition_support.current_apple_platform
+load("@rules_ios//rules:transition_support.bzl", "transition_support")
+
 transition_support.current_apple_platform(apple_fragment, xcode_config)
 
diff --git a/docs/vfs_overlay_doc.md b/docs/vfs_overlay_doc.md index d86cb6d46..87f4becfb 100755 --- a/docs/vfs_overlay_doc.md +++ b/docs/vfs_overlay_doc.md @@ -7,6 +7,8 @@ ## framework_vfs_overlay
+load("@rules_ios//rules:vfs_overlay.doc.bzl", "framework_vfs_overlay")
+
 framework_vfs_overlay(name, deps, hdrs, extra_search_paths, framework_name, has_swift, modulemap,
                       private_hdrs, swiftmodules)
 
@@ -34,6 +36,8 @@ framework_vfs_overlay(name, ctx, hdrs, module_map, private_hdrs, has_swift, swiftmodules, merge_vfsoverlays, extra_search_paths, output, framework_name) diff --git a/docs/xcconfig_doc.md b/docs/xcconfig_doc.md index 6f74a5342..fa1577e27 100755 --- a/docs/xcconfig_doc.md +++ b/docs/xcconfig_doc.md @@ -7,6 +7,8 @@ ## build_setting_name
+load("@rules_ios//rules:xcconfig.doc.bzl", "build_setting_name")
+
 build_setting_name(build_setting)
 
@@ -32,6 +34,8 @@ The string 'target_name' in '@repo_name//path/to/package:target_name' ## copts_by_build_setting_with_defaults
+load("@rules_ios//rules:xcconfig.doc.bzl", "copts_by_build_setting_with_defaults")
+
 copts_by_build_setting_with_defaults(xcconfig, fetch_default_xcconfig, xcconfig_by_build_setting)
 
@@ -64,6 +68,8 @@ Struct with different copts behind 'select()' statements ## merge_xcconfigs
+load("@rules_ios//rules:xcconfig.doc.bzl", "merge_xcconfigs")
+
 merge_xcconfigs(xcconfigs)
 
diff --git a/rules/BUILD.bazel b/rules/BUILD.bazel index 8e48c04ca..803c4f4f6 100644 --- a/rules/BUILD.bazel +++ b/rules/BUILD.bazel @@ -46,17 +46,6 @@ bzl_library( visibility = ["//visibility:public"], ) -bzl_library( - name = "force_load_direct_deps", - srcs = ["force_load_direct_deps.bzl"], - visibility = ["//visibility:public"], - deps = [ - ":providers", - ":transition_support", - "@bazel_skylib//lib:dicts", - ], -) - bzl_library( name = "xcconfig.doc", srcs = ["xcconfig.doc.bzl"], @@ -139,7 +128,6 @@ bzl_library( visibility = ["//visibility:public"], deps = [ ":features", - ":force_load_direct_deps", ":library", ":plists", ":providers", @@ -159,7 +147,6 @@ bzl_library( srcs = ["app_clip.bzl"], visibility = ["//visibility:public"], deps = [ - ":force_load_direct_deps", ":plists", "//rules/internal:framework_middleman", "@build_bazel_rules_apple//apple:ios", @@ -171,7 +158,6 @@ bzl_library( srcs = ["app.bzl"], visibility = ["//visibility:public"], deps = [ - ":force_load_direct_deps", ":library", ":plists", "//rules/internal:framework_middleman", @@ -184,7 +170,6 @@ bzl_library( srcs = ["extension.bzl"], visibility = ["//visibility:public"], deps = [ - ":force_load_direct_deps", ":plists", ":transition_support", "//rules/internal:framework_middleman", diff --git a/rules/app.bzl b/rules/app.bzl index 52b950ec9..b92ca8f1d 100644 --- a/rules/app.bzl +++ b/rules/app.bzl @@ -1,7 +1,6 @@ load("@build_bazel_rules_apple//apple:ios.bzl", rules_apple_ios_application = "ios_application") load("//rules:library.bzl", "apple_library") load("//rules:plists.bzl", "process_infoplists") -load("//rules:force_load_direct_deps.bzl", "force_load_direct_deps") load("//rules/internal:framework_middleman.bzl", "dep_middleman", "framework_middleman") # We need to try and partition out arguments for obj_library / swift_library @@ -93,17 +92,6 @@ def ios_application( application_kwargs["launch_storyboard"] = application_kwargs.pop("launch_storyboard", library.launch_screen_storyboard_name) - # Setup force loading here - need to process deps and libs - force_load_name = name + ".force_load_direct_deps" - force_load_direct_deps( - name = force_load_name, - deps = kwargs.get("deps", []) + library.lib_names, - tags = ["manual"], - testonly = testonly, - platform_type = "ios", - minimum_os_version = application_kwargs.get("minimum_os_version"), - ) - # Setup framework middlemen - need to process deps and libs fw_name = name + ".framework_middleman" framework_middleman( @@ -125,8 +113,7 @@ def ios_application( platform_type = "ios", minimum_os_version = application_kwargs.get("minimum_os_version"), ) - deps = [dep_name] + [force_load_name] - + deps = [dep_name] processed_infoplists = process_infoplists( name = name, infoplists = infoplists, diff --git a/rules/app_clip.bzl b/rules/app_clip.bzl index 05fd0bf34..33fcecc97 100644 --- a/rules/app_clip.bzl +++ b/rules/app_clip.bzl @@ -1,6 +1,5 @@ load("@build_bazel_rules_apple//apple:ios.bzl", rules_apple_ios_app_clip = "ios_app_clip") load("//rules:plists.bzl", "process_infoplists") -load("//rules:force_load_direct_deps.bzl", "force_load_direct_deps") load("//rules/internal:framework_middleman.bzl", "dep_middleman", "framework_middleman") def ios_app_clip( @@ -43,15 +42,6 @@ def ios_app_clip( frameworks = kwargs.pop("frameworks", []) testonly = kwargs.pop("testonly", False) - # Setup force loading here - need to process deps and libs - force_load_name = name + ".force_load_direct_deps" - force_load_direct_deps( - name = force_load_name, - deps = deps, - tags = ["manual"], - testonly = testonly, - ) - # Setup framework middlemen - need to process deps and libs fw_name = name + ".framework_middleman" framework_middleman( @@ -69,7 +59,7 @@ def ios_app_clip( tags = ["manual"], testonly = testonly, ) - deps = [dep_name] + [force_load_name] + deps = [dep_name] processed_infoplists = process_infoplists( name = name, diff --git a/rules/extension.bzl b/rules/extension.bzl index 0607cdc35..dc20ae4f0 100644 --- a/rules/extension.bzl +++ b/rules/extension.bzl @@ -1,6 +1,5 @@ load("@build_bazel_rules_apple//apple:ios.bzl", rules_apple_ios_extension = "ios_extension") load("//rules:plists.bzl", "process_infoplists") -load("//rules:force_load_direct_deps.bzl", "force_load_direct_deps") load("//rules/internal:framework_middleman.bzl", "dep_middleman", "framework_middleman") def ios_extension( @@ -45,15 +44,6 @@ def ios_extension( frameworks = kwargs.pop("frameworks", []) testonly = kwargs.pop("testonly", False) - # Setup force loading here - need to process deps and libs - force_load_name = name + ".force_load_direct_deps" - force_load_direct_deps( - name = force_load_name, - deps = deps, - tags = ["manual"], - testonly = testonly, - ) - # Setup framework middlemen - need to process deps and libs fw_name = name + ".framework_middleman" framework_middleman( @@ -72,7 +62,7 @@ def ios_extension( tags = ["manual"], testonly = testonly, ) - deps = [dep_name] + [force_load_name] + deps = [dep_name] processed_infoplists = process_infoplists( name = name, diff --git a/rules/force_load_direct_deps.bzl b/rules/force_load_direct_deps.bzl deleted file mode 100644 index ec7aaf928..000000000 --- a/rules/force_load_direct_deps.bzl +++ /dev/null @@ -1,176 +0,0 @@ -load("@bazel_skylib//lib:paths.bzl", "paths") -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain") -load("//rules:providers.bzl", "AvoidDepsInfo") -load("//rules:transition_support.bzl", "transition_support") - -def _objc_provider_static_libraries(dep): - """Returns the ObjcProvider static libraries (.a) that should be force loaded. - """ - if not apple_common.Objc in dep: - return [] - - return dep[apple_common.Objc].library.to_list() - -def _cc_info_static_libraries(dep): - """Returns the CcInfo static libraries (.a) that should be force loaded. - - NOTE: CcInfo, unlike ObjcProvider, does not encode where the static library came from. - In the existing `_objc_provider_static_libraries` we only collect `.library` from ObjcProvider. - ObjcProvider `.library` list static library dependencies of the current target, - it does not include imported static libraries (such as those from `.framework` files). - CcInfo only provides `.static_library` and does not make this distinction. - To match this behavior, we only collect `.static_library` from CcInfo that are not from `.framework`s. - """ - if not CcInfo in dep: - return [] - - static_cc_libraries = [] - for linker_input in dep[CcInfo].linking_context.linker_inputs.to_list(): - for library_to_link in linker_input.libraries: - if not library_to_link.static_library: - continue - containing_path = paths.dirname(library_to_link.static_library.path) - if containing_path.endswith(".framework"): - continue - static_cc_libraries.append(library_to_link.static_library) - - return static_cc_libraries - -# TODO: We should deprecate this rule for Bazel 7+ as `--incompatible_objc_alwayslink_by_default` effectively -# does the same thing. -def _force_load_direct_deps_impl(ctx): - """This rule will traverse the direct deps of the target and force load the static libraries of the objc deps. - """ - - if not ctx.attr.should_force_load: - return [ - apple_common.new_objc_provider(), - CcInfo(), - ] - - force_load_libraries = [] - force_load_cc_libraries = [] - avoid_deps = [] - avoid_libraries = {} - avoid_cc_libraries = {} - cc_toolchain = find_cpp_toolchain(ctx) - cc_features = cc_common.configure_features( - ctx = ctx, - cc_toolchain = cc_toolchain, - language = "objc", - ) - - # Set the deps that should be avoided and not linked. - for dep in ctx.attr.deps: - if AvoidDepsInfo in dep: - avoid_deps.extend(dep[AvoidDepsInfo].libraries) - - # Collect the libraries that should be avoided. - for dep in avoid_deps: - for lib in _objc_provider_static_libraries(dep): - avoid_libraries[lib] = True - for lib in _cc_info_static_libraries(dep): - avoid_cc_libraries[lib] = True - - # Collect the libraries that should be force loaded. - for dep in ctx.attr.deps: - for lib in _objc_provider_static_libraries(dep): - if not lib in avoid_libraries: - force_load_libraries.append(lib) - for lib in _cc_info_static_libraries(dep): - if not lib in avoid_cc_libraries: - force_load_cc_libraries.append(lib) - - return [ - apple_common.new_objc_provider( - force_load_library = depset(force_load_libraries), - link_inputs = depset(force_load_libraries), - ), - CcInfo( - linking_context = cc_common.create_linking_context( - linker_inputs = depset([ - cc_common.create_linker_input( - owner = ctx.label, - libraries = depset([ - cc_common.create_library_to_link( - actions = ctx.actions, - cc_toolchain = cc_toolchain, - feature_configuration = cc_features, - static_library = library, - alwayslink = True, - ) - for library in force_load_cc_libraries - ]), - ), - ]), - ), - ), - ] - -force_load_direct_deps = rule( - implementation = _force_load_direct_deps_impl, - toolchains = use_cpp_toolchain(), - fragments = ["apple", "cpp", "objc"], - attrs = { - "deps": attr.label_list( - cfg = transition_support.apple_platform_split_transition, - mandatory = True, - doc = - "Deps", - ), - "should_force_load": attr.bool( - default = True, - doc = "Allows parametrically enabling the functionality in this rule.", - ), - "platform_type": attr.string( - mandatory = False, - doc = - """Internal - currently rules_ios uses the dict `platforms` -""", - ), - "minimum_os_version": attr.string( - mandatory = False, - doc = - """Internal - currently rules_ios the dict `platforms` -""", - ), - "_allowlist_function_transition": attr.label( - default = "@bazel_tools//tools/allowlists/function_transition_allowlist", - doc = "Needed to allow this rule to have an incoming edge configuration transition.", - ), - "_cc_toolchain": attr.label( - providers = [cc_common.CcToolchainInfo], - default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"), - doc = """\ -The C++ toolchain from which linking flags and other tools needed by the Swift -toolchain (such as `clang`) will be retrieved. -""", - ), - }, - doc = """ -A rule to link with `-force_load` for direct`deps` - -ld has different behavior when loading members of a static library VS objects -as far as visibility. Under `-dynamic` -- linked _swift object files_ can have public visibility -- symbols from _swift static libraries_ are omitted unless used, and not -visible otherwise - -By using `-force_load`, we can load static libraries in the attributes of an -application's direct depenencies. These args need go at the _front_ of the -linker invocation otherwise these arguments don't work with lds logic. - -Why not put it into `rules_apple`? Ideally it could be, and perhaps consider a -PR to there .The underlying java rule, `AppleBinary.linkMultiArchBinary` -places `extraLinkopts` at the end of the linker invocation. At the time of -writing these args need to go into the current rule context where -`AppleBinary.linkMultiArchBinary` is called. - -One use case of this is that iOS developers want to load above mentioned -symbols from applications. Another alternate could be to create an aspect, -that actually generates a different application and linker invocation instead -of force loading symbols. This could be more complicated from an integration -perspective so it isn't used. - - """, -) diff --git a/rules/framework.bzl b/rules/framework.bzl index 9e5fcc7e0..69f084b66 100644 --- a/rules/framework.bzl +++ b/rules/framework.bzl @@ -30,7 +30,6 @@ load( "@build_bazel_rules_apple//apple/internal/aspects:resource_aspect.bzl", "apple_resource_aspect", ) -load("//rules:force_load_direct_deps.bzl", "force_load_direct_deps") _APPLE_FRAMEWORK_PACKAGING_KWARGS = [ "visibility", @@ -125,21 +124,6 @@ def apple_framework( "//conditions:default": "", }) - # Setup force loading here - only for direct deps / direct libs and when `link_dynamic` is set. - should_force_load = framework_packaging_kwargs.get("link_dynamic", False) - if should_force_load: - force_load_name = name + ".force_load_direct_deps" - force_load_direct_deps( - name = force_load_name, - deps = kwargs.get("deps", []) + library.lib_names, - should_force_load = should_force_load, - testonly = testonly, - tags = ["manual"], - minimum_os_version = minimum_os_version, - platform_type = platform_type, - ) - framework_deps.append(force_load_name) - framework_deps += library.lib_names apple_framework_packaging( name = name, @@ -894,7 +878,6 @@ def _bundle_dynamic_framework(ctx, is_extension_safe, avoid_deps): cc_features = cc_features, cc_info = link_result.cc_info, cc_toolchain = cc_toolchain, - objc_provider = link_result.objc, rule_label = label, ), ) diff --git a/rules/import_middleman.bzl b/rules/import_middleman.bzl index 80ea3974b..f76c086f3 100644 --- a/rules/import_middleman.bzl +++ b/rules/import_middleman.bzl @@ -92,17 +92,12 @@ def _find_imports_impl(target, ctx): dynamic_framework_file.append(dep[_FindImportsAspectInfo].dynamic_framework_file) import_infos.update(dep[_FindImportsAspectInfo].import_infos) - if ctx.rule.kind == "objc_import": - imported_library_file.append(target[apple_common.Objc].imported_library) - - elif AppleFrameworkImportInfo in target: - static_framework_file.append(target[apple_common.Objc].imported_library) - target_dynamic_framework_file = target[apple_common.Objc].dynamic_framework_file - target_dynamic_framework_file_list = target_dynamic_framework_file.to_list() - if len(target_dynamic_framework_file_list) > 0: - import_infos[target_dynamic_framework_file_list[0].path] = target[AppleFrameworkImportInfo] - - dynamic_framework_file.append(target_dynamic_framework_file) + if AppleFrameworkImportInfo in target: + if CcInfo in target: + for linker_input in target[CcInfo].linking_context.linker_inputs.to_list(): + for library_to_link in linker_input.libraries: + if library_to_link.static_library: + static_framework_file.append(depset([library_to_link.static_library])) return [_FindImportsAspectInfo( dynamic_framework_file = depset(transitive = dynamic_framework_file), @@ -196,7 +191,7 @@ def _file_collector_rule_impl(ctx): ] objc_provider_fields = objc_provider_utils.merge_objc_providers_dict( - providers = [dep[apple_common.Objc] for dep in ctx.attr.deps], + providers = [], merge_keys = merge_keys, ) diff --git a/rules/library.bzl b/rules/library.bzl index 2bf39f6f6..b77a9afa9 100644 --- a/rules/library.bzl +++ b/rules/library.bzl @@ -1069,6 +1069,7 @@ def apple_library( deps = deps + private_deps + private_dep_names, defines = defines, tags = tags_manual, + alwayslink = True, # ensure symbols from any static deps are always included (see https://github.com/bazelbuild/rules_apple/issues/1938) testonly = testonly, features = features, ) @@ -1123,6 +1124,7 @@ def apple_library( defines = defines + objc_defines, testonly = testonly, features = features, + alwayslink = True, # ensure symbols from any static deps are always included (see https://github.com/bazelbuild/rules_apple/issues/1938) **kwargs ) launch_screen_storyboard_name = name + "_launch_screen_storyboard"