Skip to content

Commit 24c03a2

Browse files
authored
Add objc_library binary to outputs of apple_framework_packaging rule when virtualized frameworks feature is enabled (#931)
This fixes an issue where building an `apple_framework_packaging` rule with the VFS feature enabled wouldn't trigger objc compilation for the framework. When the VFS feature is disabled, the binaries from the `objc_library` and `swift_library` targets are merged using libtool, and that binary is included in the outputs of the `apple_framework_packaging` rule ([see packaging action](https://github.com/bazel-ios/rules_ios/blob/f7dcd0c4f90985495bba517dc8cc7d86ce7f7632/rules/framework/framework_packaging.py#L19)). When the VFS feature is enabled, all of the packaging actions are skipped, and the binaries from the `objc_library` and `swift_library` targets aren't merged. One of the input binaries is arbitrarily included in the rule's output files -- for a target containing swift and objc sources, this would be the `swift_library` binary. The PR adds both input binaries to the rule outputs when the VFS feature is enabled, so building an `apple_framework_packaging` rule triggers both objc and swift compilation actions.
1 parent 940087b commit 24c03a2

File tree

1 file changed

+40
-24
lines changed

1 file changed

+40
-24
lines changed

rules/framework.bzl

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,9 @@ def _framework_packaging_multi(ctx, action, inputs, outputs, manifest = None):
206206
return []
207207
if inputs == [None]:
208208
return []
209-
210209
virtualize_frameworks = feature_names.virtualize_frameworks in ctx.features
211210
if virtualize_frameworks:
212-
return inputs
213-
211+
fail("Should not be packaging frameworks when virtualizing frameworks")
214212
if action in ctx.attr.skip_packaging:
215213
return []
216214
action_inputs = [manifest] + inputs if manifest else inputs
@@ -441,26 +439,41 @@ def _get_framework_files(ctx, deps):
441439
else:
442440
framework_manifest = None
443441

444-
# Package each part of the framework separately,
445-
# so inputs that do not depend on compilation
446-
# are available before those that do,
447-
# improving parallelism
448-
binary_out = _framework_packaging_single(ctx, "binary", binaries_in, binary_out, framework_manifest)
449-
headers_out = _framework_packaging_multi(ctx, "header", headers_in, headers_out, framework_manifest)
450-
private_headers_out = _framework_packaging_multi(ctx, "private_header", private_headers_in, private_headers_out, framework_manifest)
451-
452-
# Instead of creating a symlink of the modulemap, we need to copy it to modulemap_out.
453-
# It's a hacky fix to guarantee running the clean action before compiling objc files depending on this framework in non-sandboxed mode.
454-
# Otherwise, stale header files under framework_root will cause compilation failure in non-sandboxed mode.
455-
modulemap_out = _framework_packaging_single(ctx, "modulemap", [modulemap_in], modulemap_out, framework_manifest)
456-
swiftmodule_out = _framework_packaging_single(ctx, "swiftmodule", [swiftmodule_in], swiftmodule_out, framework_manifest)
457-
swiftinterface_out = _framework_packaging_single(ctx, "swiftinterface", [swiftinterface_in], swiftinterface_out, framework_manifest)
458-
swiftdoc_out = _framework_packaging_single(ctx, "swiftdoc", [swiftdoc_in], swiftdoc_out, framework_manifest)
459-
infoplist_out = _framework_packaging_single(ctx, "infoplist", [infoplist_in], infoplist_out, framework_manifest)
460-
symbol_graph_out = _framework_packaging_single(ctx, "symbol_graph", [symbol_graph_in], symbol_graph_out, framework_manifest)
442+
if virtualize_frameworks:
443+
# When using virtualized frameworks, we skip the packaging step.
444+
binaries_out = binaries_in
445+
headers_out = headers_in
446+
private_headers_out = private_headers_in
447+
modulemap_out = modulemap_in
448+
swiftmodule_out = swiftmodule_in
449+
swiftinterface_out = swiftinterface_in
450+
swiftdoc_out = swiftdoc_in
451+
infoplist_out = infoplist_in
452+
symbol_graph_out = symbol_graph_in
453+
else:
454+
# Package each part of the framework separately,
455+
# so inputs that do not depend on compilation
456+
# are available before those that do,
457+
# improving parallelism
458+
binaries_out = _compact([_framework_packaging_single(ctx, "binary", binaries_in, binary_out, framework_manifest)])
459+
headers_out = _framework_packaging_multi(ctx, "header", headers_in, headers_out, framework_manifest)
460+
private_headers_out = _framework_packaging_multi(ctx, "private_header", private_headers_in, private_headers_out, framework_manifest)
461+
462+
# Instead of creating a symlink of the modulemap, we need to copy it to modulemap_out.
463+
# It's a hacky fix to guarantee running the clean action before compiling objc files depending on this framework in non-sandboxed mode.
464+
# Otherwise, stale header files under framework_root will cause compilation failure in non-sandboxed mode.
465+
modulemap_out = _framework_packaging_single(ctx, "modulemap", [modulemap_in], modulemap_out, framework_manifest)
466+
swiftmodule_out = _framework_packaging_single(ctx, "swiftmodule", [swiftmodule_in], swiftmodule_out, framework_manifest)
467+
swiftinterface_out = _framework_packaging_single(ctx, "swiftinterface", [swiftinterface_in], swiftinterface_out, framework_manifest)
468+
swiftdoc_out = _framework_packaging_single(ctx, "swiftdoc", [swiftdoc_in], swiftdoc_out, framework_manifest)
469+
infoplist_out = _framework_packaging_single(ctx, "infoplist", [infoplist_in], infoplist_out, framework_manifest)
470+
symbol_graph_out = _framework_packaging_single(ctx, "symbol_graph", [symbol_graph_in], symbol_graph_out, framework_manifest)
461471

462472
outputs = struct(
463-
binary = binary_out,
473+
# When the virtualized frameworks feature is disabled, this contains a single binary, merged with libtool.
474+
# When the virtualized frameworks feature is enabled, this contains both the objc_library and swift_library binaries, so that
475+
# both binaries are included in the output files of this rule.
476+
binaries = binaries_out,
464477
headers = headers_out,
465478
infoplist = infoplist_out,
466479
private_headers = private_headers_out,
@@ -502,10 +515,10 @@ def _get_symlinked_framework_clean_action(ctx, framework_files, compilation_cont
502515

503516
framework_contents = _compact(
504517
[
505-
outputs.binary,
506518
outputs.swiftmodule,
507519
outputs.swiftdoc,
508520
] +
521+
outputs.binaries +
509522
outputs.modulemaps +
510523
outputs.headers +
511524
outputs.private_headers,
@@ -982,7 +995,9 @@ def _bundle_static_framework(ctx, is_extension_safe, current_apple_platform, out
982995
new_applebundleinfo(
983996
archive = None,
984997
archive_root = None,
985-
binary = outputs.binary,
998+
# When the virtualized frameworks feature is enabled, outputs.binaries can contain two binaries:
999+
# the swift_library binary and the objc_library binary. Arbitrarily use the first, matching previous behavior.
1000+
binary = outputs.binaries[0] if outputs.binaries else None,
9861001
bundle_id = ctx.attr.bundle_id,
9871002
bundle_name = ctx.attr.framework_name,
9881003
bundle_extension = ctx.attr.bundle_extension,
@@ -1128,7 +1143,8 @@ def _apple_framework_packaging_impl(ctx):
11281143
swift_info = _get_merged_swift_info(ctx, framework_files, transitive_deps, clang_module)
11291144

11301145
# Build out the default info provider
1131-
out_files = _compact([outputs.binary, outputs.swiftmodule, outputs.infoplist])
1146+
out_files = _compact([outputs.swiftmodule, outputs.infoplist])
1147+
out_files.extend(outputs.binaries)
11321148
out_files.extend(outputs.headers)
11331149
out_files.extend(outputs.private_headers)
11341150
out_files.extend(outputs.modulemaps)

0 commit comments

Comments
 (0)