Skip to content

Commit

Permalink
[Bazel 6.x.x] sim_arm64 middleman fixes (#767)
Browse files Browse the repository at this point in the history
* [6.x.x] sim_arm64 middleman fixes

In Bazel 6.x.x the `static_framework_file` was migrated onto
`imported_library` this PR completes the migration and is followup to
the Bazel 6 work.

The related rules_apple change which updated `static_framework_file`:
bazelbuild/rules_apple@8d84134
  • Loading branch information
jerrymarino authored Sep 14, 2023
1 parent d701fdc commit ac2ceab
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions rules/import_middleman.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Notes on Bazel 5.x.x VS 6.x.x and rules_apple rule_api_version changes:
# The provider field that contains the `static_framework_file` changed to
# `imported_library` - see
# https://github.com/bazelbuild/rules_apple/commit/8d841342c238457896cd7596cc29b2d06c9a75f0

load("@build_bazel_rules_apple//apple:providers.bzl", "AppleFrameworkImportInfo")
load("//rules:features.bzl", "feature_names")
load("//rules/internal:objc_provider_utils.bzl", "objc_provider_utils")
Expand Down Expand Up @@ -100,8 +105,6 @@ def _find_imports_impl(target, ctx):
if use_lts_5_rules_apple_api:
static_framework_file.append(target[apple_common.Objc].static_framework_file)
else:
# The provider field that contains the `static_framework_file` changed in
# https://github.com/bazelbuild/rules_apple/commit/8d841342c238457896cd7596cc29b2d06c9a75f0
static_framework_file.append(target[apple_common.Objc].imported_library)

target_dynamic_framework_file = target[apple_common.Objc].dynamic_framework_file
Expand Down Expand Up @@ -210,8 +213,17 @@ def _file_collector_rule_impl(ctx):
existing_static_framework = objc_provider_fields.get("static_framework_file", depset([]))

deduped_static_framework = depset(_deduplicate_test_deps(test_linker_deps[0], existing_static_framework.to_list()))

replaced_static_framework = _replace_inputs(ctx, deduped_static_framework, input_static_frameworks, _update_framework)
objc_provider_fields["static_framework_file"] = depset(replaced_static_framework.inputs)
rules_apple_api_version = getattr(bundling_support, "rule_api_version", None)
use_lts_5_rules_apple_api = rules_apple_api_version == 1.0
if use_lts_5_rules_apple_api:
objc_provider_fields["static_framework_file"] = depset(replaced_static_framework.inputs)
else:
objc_provider_fields["imported_library"] = depset([], transitive = [
depset(replaced_static_framework.inputs),
objc_provider_fields.get("imported_library", depset([])),
])

# Update dynamic frameworks - note that we need to do some additional
# processing for the ad-hoc files e.g. ( Info.plist )
Expand Down Expand Up @@ -239,11 +251,15 @@ def _file_collector_rule_impl(ctx):
dynamic_framework_dirs.append(f)
objc_provider_fields["dynamic_framework_file"] = depset(dynamic_framework_file)

replaced_frameworks = replaced_dyanmic_framework.values() + replaced_static_framework.replaced.values()
all_replaced_frameworks = replaced_dyanmic_framework.values() + replaced_static_framework.replaced.values()
if use_lts_5_rules_apple_api:
replaced_frameworks = all_replaced_frameworks
else:
replaced_frameworks = replaced_dyanmic_framework.values()

compat_link_opt = ["-L__BAZEL_XCODE_DEVELOPER_DIR__/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator", "-Wl,-weak-lswiftCompatibility51"]

if len(replaced_frameworks):
if len(all_replaced_frameworks):
# Triple quote the new path to put them first. Eliminating other paths
# may possible but needs more handling of other kinds of frameworks and
# has edge cases that require baking assumptions to handle.
Expand All @@ -255,7 +271,7 @@ def _file_collector_rule_impl(ctx):
objc_provider_fields["link_inputs"] = depset(
transitive = [
objc_provider_fields.get("link_inputs", depset([])),
depset(replaced_frameworks),
depset(all_replaced_frameworks),
],
)

Expand Down

0 comments on commit ac2ceab

Please sign in to comment.