Skip to content

Commit f2e0645

Browse files
authored
Fix static xcframework import identifier picking issues (#1579)
Fix xcframework incorrect library identifier picking. There are a few issues being fixed here: - armv7 can't be included in device tests unless we want to include it in xcframework fixtures, I just removed that since 32 bit usage should be low, and was also partially removed upstream - added ios_cpu to the default transition, sometimes we get this set from bazel itself, so in the case you have a dependency tree where an ios_application built for device transitively depends on a apple_static_xcframework, you ended up with conflicting actions because of the minor configuration difference. Theoretically people mostly shouldn't have this, but if you want to test a real xcframework that's produced, then you hit this case - fix library identification where previously it was too aggressive and over including simulator files for device
1 parent a9aaadb commit f2e0645

6 files changed

Lines changed: 65 additions & 9 deletions

File tree

apple/internal/apple_xcframework_import.bzl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,23 @@ def _get_xcframework_library_from_paths(*, target_triplet, xcframework):
183183
if not library_identifier:
184184
return None
185185

186+
def _matches_library(file):
187+
return library_identifier in file.short_path.split("/")
188+
186189
files = xcframework.files_by_category
187-
binaries = [f for f in files.binary_imports if library_identifier in f.short_path]
188-
framework_imports = [f for f in files.bundling_imports if library_identifier in f.short_path]
189-
headers = [f for f in files.header_imports if library_identifier in f.short_path]
190-
module_maps = [f for f in files.module_map_imports if library_identifier in f.short_path]
190+
binaries = [f for f in files.binary_imports if _matches_library(f)]
191+
framework_imports = [f for f in files.bundling_imports if _matches_library(f)]
192+
headers = [f for f in files.header_imports if _matches_library(f)]
193+
module_maps = [f for f in files.module_map_imports if _matches_library(f)]
191194
swiftmodules = [
192195
f
193196
for f in files.swift_module_imports
194-
if library_identifier in f.short_path and
197+
if _matches_library(f) and
195198
f.basename.startswith(target_triplet.architecture)
196199
]
197200

198201
framework_dirs = [f.dirname for f in binaries]
199-
framework_files = [f for f in xcframework.files if library_identifier in f.short_path]
202+
framework_files = [f for f in xcframework.files if _matches_library(f)]
200203

201204
includes = []
202205
framework_includes = []
@@ -385,6 +388,8 @@ def _get_library_identifier(
385388

386389
if target_environment == "simulator" and not library_identifier.endswith("-simulator"):
387390
continue
391+
if target_environment != "simulator" and library_identifier.endswith("-simulator"):
392+
continue
388393

389394
return library_identifier
390395

apple/internal/transition_support.bzl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ def _command_line_options(
233233

234234
output_dictionary["@build_bazel_rules_swift//swift:emit_swiftinterface"] = emit_swiftinterface
235235

236+
# Without handling this flag our transition differs from what we get
237+
# from bazel when the dependency tree contains a rule inheriting bazel's
238+
# built in transitions. This flag should not be used, we can remove this
239+
# once https://github.com/bazelbuild/bazel/pull/13872 is merged
240+
if platform_type == "ios":
241+
output_dictionary["//command_line_option:ios_cpu"] = _cpu_string(
242+
cpu = cpu,
243+
platform_type = platform_type,
244+
settings = settings,
245+
)
246+
else:
247+
output_dictionary["//command_line_option:ios_cpu"] = ""
248+
236249
return output_dictionary
237250

238251
def _xcframework_split_attr_key(*, cpu, environment, platform_type):
@@ -358,6 +371,7 @@ _apple_rule_base_transition_outputs = [
358371
"//command_line_option:apple_split_cpu",
359372
"//command_line_option:compiler",
360373
"//command_line_option:cpu",
374+
"//command_line_option:ios_cpu",
361375
"//command_line_option:crosstool_top",
362376
"//command_line_option:fission",
363377
"//command_line_option:grte_top",

test/starlark_tests/apple_static_xcframework_import_tests.bzl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ def apple_static_xcframework_import_test_suite(name):
3939
tags = [name],
4040
)
4141

42+
archive_contents_test(
43+
name = "{}_ios_application_with_imported_static_xcframework_includes_symbols_device".format(name),
44+
build_type = "device",
45+
target_under_test = "//test/starlark_tests/targets_under_test/ios:app_with_imported_xcframework_with_static_library",
46+
binary_test_file = "$BINARY",
47+
binary_test_architecture = "arm64",
48+
binary_contains_symbols = [
49+
"-[SharedClass doSomethingShared]",
50+
"_OBJC_CLASS_$_SharedClass",
51+
],
52+
not_contains = ["$BUNDLE_ROOT/Frameworks/"],
53+
tags = [name],
54+
)
55+
4256
# Verify ios_application with XCFramework with Swift static library dependency contains
4357
# Objective-C symbols, doesn't bundle XCFramework, and does bundle Swift standard libraries.
4458
archive_contents_test(

test/starlark_tests/apple_xcframework_import_tests.bzl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,21 @@ def apple_xcframework_import_test_suite(name):
6666
)
6767

6868
apple_verification_test(
69-
name = "{}_xcfmwk_bundling_static_xcfmwks_codesign_test".format(name),
69+
name = "{}_xcfmwk_bundling_static_xcfmwks_codesign_test_simulator".format(name),
7070
build_type = "simulator",
7171
target_under_test = "//test/starlark_tests/targets_under_test/ios:app_with_imported_xcfmwk_bundling_static_fmwks",
7272
verifier_script = "verifier_scripts/codesign_verifier.sh",
7373
tags = [name],
7474
)
7575

76+
apple_verification_test(
77+
name = "{}_xcfmwk_bundling_static_xcfmwks_codesign_test_device".format(name),
78+
build_type = "device",
79+
target_under_test = "//test/starlark_tests/targets_under_test/ios:app_with_imported_xcfmwk_bundling_static_fmwks",
80+
verifier_script = "verifier_scripts/codesign_verifier.sh",
81+
tags = [name],
82+
)
83+
7684
# Test that apple_static_xcframework_import can import XCFrameworks
7785
# bundling static libraries and make them usable from objc_library
7886
analysis_target_outputs_test(
@@ -83,7 +91,7 @@ def apple_xcframework_import_test_suite(name):
8391
)
8492

8593
archive_contents_test(
86-
name = "{}_static_xcfw_binary_not_bundled".format(name),
94+
name = "{}_static_xcfw_binary_not_bundled_simulator".format(name),
8795
build_type = "simulator",
8896
target_under_test = "//test/starlark_tests/targets_under_test/ios:app_with_imported_xcfmwk_bundling_static_fmwks_with_resources",
8997
contains = [
@@ -96,6 +104,20 @@ def apple_xcframework_import_test_suite(name):
96104
tags = [name],
97105
)
98106

107+
archive_contents_test(
108+
name = "{}_static_xcfw_binary_not_bundled_device".format(name),
109+
build_type = "device",
110+
target_under_test = "//test/starlark_tests/targets_under_test/ios:app_with_imported_xcfmwk_bundling_static_fmwks_with_resources",
111+
contains = [
112+
"$BUNDLE_ROOT/resource_bundle.bundle/custom_apple_resource_info.out",
113+
"$BUNDLE_ROOT/resource_bundle.bundle/Info.plist",
114+
],
115+
not_contains = [
116+
"$BUNDLE_ROOT/Frameworks/ios_static_xcframework_with_resources.framework/ios_static_xcframework_with_resources",
117+
],
118+
tags = [name],
119+
)
120+
99121
analysis_target_outputs_test(
100122
name = "{}_static_xcfw_import_with_lib_ids_ipa_test".format(name),
101123
target_under_test = "//test/starlark_tests/targets_under_test/ios:app_with_imported_static_xcfmwk_with_lib_ids",

test/starlark_tests/rules/apple_verification_test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _apple_verification_transition_impl(settings, attr):
5454
})
5555
else:
5656
output_dictionary.update({
57-
"//command_line_option:ios_multi_cpus": "arm64,armv7",
57+
"//command_line_option:ios_multi_cpus": "arm64",
5858
"//command_line_option:tvos_cpus": "arm64",
5959
"//command_line_option:watchos_cpus": "arm64_32,armv7k",
6060
})

test/starlark_tests/targets_under_test/ios/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,7 @@ ios_application(
18741874
"//test/starlark_tests/resources:Info.plist",
18751875
],
18761876
minimum_os_version = "11.0",
1877+
provisioning_profile = "//test/testdata/provisioning:integration_testing_ios.mobileprovision",
18771878
tags = FIXTURE_TAGS,
18781879
deps = [
18791880
":static_xcframework_depending_objc_lib",

0 commit comments

Comments
 (0)