Skip to content

Commit 1e74f4b

Browse files
nglevinluispadron
authored andcommitted
Start wiring up build settings for crosstool dSYM bundles into the rules themselves.
Cherry-pick: f1ed76b
1 parent 04f4135 commit 1e74f4b

File tree

10 files changed

+80
-14
lines changed

10 files changed

+80
-14
lines changed

apple/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ bzl_library(
5656
"//apple/internal:rule_attrs",
5757
"//apple/internal:rule_factory",
5858
"//apple/internal:transition_support",
59+
"//apple/internal/toolchains:apple_toolchains",
5960
"@build_bazel_apple_support//lib:apple_support",
6061
],
6162
)

apple/apple_binary.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ load(
1818
"@build_bazel_apple_support//lib:apple_support.bzl",
1919
"apple_support",
2020
)
21+
load(
22+
"//apple/internal:apple_toolchains.bzl",
23+
"AppleXPlatToolsToolchainInfo",
24+
"apple_toolchain_utils",
25+
)
2126
load(
2227
"//apple/internal:linking_support.bzl",
2328
"linking_support",
@@ -67,6 +72,7 @@ visionOS binaries require a visionOS SDK provided by Xcode 15.1 beta or later.
6772
Resolved Xcode is version {xcode_version}.
6873
""".format(xcode_version = str(xcode_version_config.xcode_version())))
6974

75+
apple_xplat_toolchain_info = ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo]
7076
binary_type = ctx.attr.binary_type
7177
bundle_loader = ctx.attr.bundle_loader
7278
cc_toolchain_forwarder = ctx.split_attr._cc_toolchain_forwarder
@@ -97,6 +103,7 @@ Resolved Xcode is version {xcode_version}.
97103
link_result = linking_support.register_binary_linking_action(
98104
ctx,
99105
cc_toolchains = cc_toolchain_forwarder,
106+
build_settings = apple_xplat_toolchain_info.build_settings,
100107
bundle_loader = bundle_loader,
101108
exported_symbols_lists = ctx.files.exported_symbols_lists,
102109
extra_linkopts = extra_linkopts,
@@ -152,6 +159,7 @@ implementation of `apple_binary` in Bazel core so that it can be removed.
152159
implementation = _apple_binary_impl,
153160
attrs = [
154161
apple_support.platform_constraint_attrs(),
162+
apple_toolchain_utils.shared_attrs(),
155163
rule_attrs.binary_linking_attrs(
156164
deps_cfg = transition_support.apple_platform_split_transition,
157165
is_test_supporting_rule = False,

apple/internal/ios_rules.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def _ios_application_impl(ctx):
248248
ctx,
249249
cc_toolchains = cc_toolchain_forwarder,
250250
avoid_deps = ctx.attr.frameworks,
251+
build_settings = apple_xplat_toolchain_info.build_settings,
251252
entitlements = entitlements.linking,
252253
exported_symbols_lists = ctx.files.exported_symbols_lists,
253254
extra_linkopts = extra_linkopts,
@@ -627,6 +628,7 @@ def _ios_app_clip_impl(ctx):
627628
ctx,
628629
cc_toolchains = cc_toolchain_forwarder,
629630
avoid_deps = ctx.attr.frameworks,
631+
build_settings = apple_xplat_toolchain_info.build_settings,
630632
entitlements = entitlements.linking,
631633
exported_symbols_lists = ctx.files.exported_symbols_lists,
632634
platform_prerequisites = platform_prerequisites,
@@ -950,6 +952,7 @@ def _ios_framework_impl(ctx):
950952
ctx,
951953
cc_toolchains = cc_toolchain_forwarder,
952954
avoid_deps = ctx.attr.frameworks,
955+
build_settings = apple_xplat_toolchain_info.build_settings,
953956
# Frameworks do not have entitlements.
954957
entitlements = None,
955958
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1227,6 +1230,7 @@ def _ios_extension_impl(ctx):
12271230
ctx,
12281231
cc_toolchains = cc_toolchain_forwarder,
12291232
avoid_deps = ctx.attr.frameworks,
1233+
build_settings = apple_xplat_toolchain_info.build_settings,
12301234
entitlements = entitlements.linking,
12311235
exported_symbols_lists = ctx.files.exported_symbols_lists,
12321236
extra_linkopts = extra_linkopts,
@@ -1545,6 +1549,7 @@ def _ios_dynamic_framework_impl(ctx):
15451549
ctx,
15461550
cc_toolchains = cc_toolchain_forwarder,
15471551
avoid_deps = ctx.attr.frameworks,
1552+
build_settings = apple_xplat_toolchain_info.build_settings,
15481553
# Frameworks do not have entitlements.
15491554
entitlements = None,
15501555
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -2181,6 +2186,7 @@ def _ios_imessage_extension_impl(ctx):
21812186
ctx,
21822187
cc_toolchains = cc_toolchain_forwarder,
21832188
avoid_deps = ctx.attr.frameworks,
2189+
build_settings = apple_xplat_toolchain_info.build_settings,
21842190
entitlements = entitlements.linking,
21852191
exported_symbols_lists = ctx.files.exported_symbols_lists,
21862192
extra_linkopts = extra_linkopts,

apple/internal/linking_support.bzl

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def _link_multi_arch_binary(
144144
*,
145145
ctx,
146146
avoid_deps = [],
147+
build_settings,
147148
cc_toolchains,
148149
extra_linkopts = [],
149150
extra_link_inputs = [],
@@ -167,6 +168,7 @@ def _link_multi_arch_binary(
167168
dependencies that will be found at runtime in another image, such as the
168169
bundle loader or any dynamic libraries/frameworks that will be loaded by
169170
this binary.
171+
build_settings: A struct with build settings info from AppleXplatToolsToolchainInfo.
170172
cc_toolchains: Dictionary of CcToolchainInfo and ApplePlatformInfo providers under a split
171173
transition to relay target platform information for related deps.
172174
extra_linkopts: A list of strings: Extra linkopts to add to the linking action.
@@ -282,21 +284,42 @@ def _link_multi_arch_binary(
282284
additional_outputs = []
283285
extensions = {}
284286

285-
dsym_binary = None
287+
dsym_output = None
286288
if ctx.fragments.cpp.apple_generate_dsym:
287-
if ctx.fragments.cpp.objc_should_strip_binary:
288-
suffix = "_bin_unstripped.dwarf"
289+
dsym_variants = build_settings.dsym_variant_flag
290+
if dsym_variants == "bundle":
291+
# TODO(b/391401130): Remove this once dsymutil generated bundle dSYM output is
292+
# supported.
293+
fail("dsymutil bundle dSYM output is not yet supported by the Apple BUILD Rules.")
294+
elif dsym_variants != "flat":
295+
fail("""
296+
Internal Error: Found unsupported dsym_variant_flag: {dsym_variants}.
297+
298+
Please report this as a bug to the Apple BUILD Rules team.
299+
""".format(
300+
dsym_variants = dsym_variants,
301+
))
289302
else:
290-
suffix = "_bin.dwarf"
291-
dsym_binary = intermediates.file(
292-
actions = ctx.actions,
293-
target_name = ctx.label.name,
294-
output_discriminator = split_transition_key,
295-
file_name = ctx.label.name + suffix,
296-
)
297-
extensions["dsym_path"] = dsym_binary.path # dsym symbol file
298-
additional_outputs.append(dsym_binary)
299-
legacy_debug_outputs.setdefault(platform_info.target_arch, {})["dsym_binary"] = dsym_binary
303+
if ctx.fragments.cpp.objc_should_strip_binary:
304+
suffix = "_bin_unstripped"
305+
else:
306+
suffix = "_bin"
307+
dsym_output = intermediates.file(
308+
actions = ctx.actions,
309+
target_name = ctx.label.name,
310+
output_discriminator = split_transition_key,
311+
file_name = "{}.dwarf".format(ctx.label.name + suffix),
312+
)
313+
314+
# TODO(b/391401130): Remove this once all users are migrated to the downstream
315+
# provider AppleDsymBundleInfo.
316+
legacy_debug_outputs.setdefault(
317+
platform_info.target_arch,
318+
{},
319+
)["dsym_binary"] = dsym_output
320+
321+
extensions["dsym_path"] = dsym_output.path # dsym symbol file
322+
additional_outputs.append(dsym_output)
300323

301324
linkmap = None
302325
if ctx.fragments.cpp.objc_generate_linkmap:
@@ -329,7 +352,7 @@ def _link_multi_arch_binary(
329352
"platform": platform_info.target_os,
330353
"architecture": platform_info.target_arch,
331354
"environment": platform_info.target_environment,
332-
"dsym_binary": dsym_binary,
355+
"dsym_binary": dsym_output,
333356
"linkmap": linkmap,
334357
}
335358

@@ -419,6 +442,7 @@ def _register_binary_linking_action(
419442
ctx,
420443
*,
421444
avoid_deps = [],
445+
build_settings,
422446
bundle_loader = None,
423447
cc_toolchains,
424448
entitlements = None,
@@ -439,6 +463,7 @@ def _register_binary_linking_action(
439463
ctx: The rule context.
440464
avoid_deps: A list of `Target`s representing dependencies of the binary but whose
441465
symbols should not be linked into it.
466+
build_settings: A struct with build settings info from AppleXplatToolsToolchainInfo.
442467
bundle_loader: For Mach-O bundles, the `Target` whose binary will load this bundle.
443468
This target must propagate the `AppleExecutableBinaryInfo` provider.
444469
This simplifies the process of passing the bundle loader to all the arguments
@@ -550,6 +575,7 @@ def _register_binary_linking_action(
550575
linking_outputs = _link_multi_arch_binary(
551576
ctx = ctx,
552577
avoid_deps = all_avoid_deps,
578+
build_settings = build_settings,
553579
cc_toolchains = cc_toolchains,
554580
extra_linkopts = linkopts,
555581
extra_link_inputs = link_inputs,

apple/internal/macos_rules.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def _macos_application_impl(ctx):
241241
ctx,
242242
cc_toolchains = cc_toolchain_forwarder,
243243
avoid_deps = ctx.attr.frameworks,
244+
build_settings = apple_xplat_toolchain_info.build_settings,
244245
entitlements = entitlements.linking,
245246
exported_symbols_lists = ctx.files.exported_symbols_lists,
246247
platform_prerequisites = platform_prerequisites,
@@ -546,6 +547,7 @@ def _macos_bundle_impl(ctx):
546547
link_result = linking_support.register_binary_linking_action(
547548
ctx,
548549
cc_toolchains = cc_toolchain_forwarder,
550+
build_settings = apple_xplat_toolchain_info.build_settings,
549551
bundle_loader = ctx.attr.bundle_loader,
550552
entitlements = entitlements.linking,
551553
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -800,6 +802,7 @@ def _macos_extension_impl(ctx):
800802
ctx,
801803
cc_toolchains = cc_toolchain_forwarder,
802804
avoid_deps = ctx.attr.frameworks,
805+
build_settings = apple_xplat_toolchain_info.build_settings,
803806
entitlements = entitlements.linking,
804807
exported_symbols_lists = ctx.files.exported_symbols_lists,
805808
extra_linkopts = extra_linkopts,
@@ -1068,6 +1071,7 @@ def _macos_quick_look_plugin_impl(ctx):
10681071

10691072
link_result = linking_support.register_binary_linking_action(
10701073
ctx,
1074+
build_settings = apple_xplat_toolchain_info.build_settings,
10711075
cc_toolchains = cc_toolchain_forwarder,
10721076
entitlements = entitlements.linking,
10731077
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1322,6 +1326,7 @@ def _macos_kernel_extension_impl(ctx):
13221326

13231327
link_result = linking_support.register_binary_linking_action(
13241328
ctx,
1329+
build_settings = apple_xplat_toolchain_info.build_settings,
13251330
cc_toolchains = cc_toolchain_forwarder,
13261331
entitlements = entitlements.linking,
13271332
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1565,6 +1570,7 @@ def _macos_spotlight_importer_impl(ctx):
15651570

15661571
link_result = linking_support.register_binary_linking_action(
15671572
ctx,
1573+
build_settings = apple_xplat_toolchain_info.build_settings,
15681574
cc_toolchains = cc_toolchain_forwarder,
15691575
entitlements = entitlements.linking,
15701576
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1806,6 +1812,7 @@ def _macos_xpc_service_impl(ctx):
18061812

18071813
link_result = linking_support.register_binary_linking_action(
18081814
ctx,
1815+
build_settings = apple_xplat_toolchain_info.build_settings,
18091816
cc_toolchains = cc_toolchain_forwarder,
18101817
entitlements = entitlements.linking,
18111818
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -2022,6 +2029,7 @@ def _macos_command_line_application_impl(ctx):
20222029

20232030
link_result = linking_support.register_binary_linking_action(
20242031
ctx,
2032+
build_settings = apple_xplat_toolchain_info.build_settings,
20252033
cc_toolchains = cc_toolchain_forwarder,
20262034
# Command-line applications do not have entitlements.
20272035
entitlements = None,
@@ -2164,6 +2172,7 @@ def _macos_dylib_impl(ctx):
21642172

21652173
link_result = linking_support.register_binary_linking_action(
21662174
ctx,
2175+
build_settings = apple_xplat_toolchain_info.build_settings,
21672176
cc_toolchains = cc_toolchain_forwarder,
21682177
# Dynamic libraries do not have entitlements.
21692178
entitlements = None,
@@ -2856,6 +2865,7 @@ def _macos_framework_impl(ctx):
28562865
ctx,
28572866
cc_toolchains = cc_toolchain_forwarder,
28582867
avoid_deps = ctx.attr.frameworks,
2868+
build_settings = apple_xplat_toolchain_info.build_settings,
28592869
# Frameworks do not have entitlements.
28602870
entitlements = None,
28612871
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -3139,6 +3149,7 @@ def _macos_dynamic_framework_impl(ctx):
31393149
ctx,
31403150
cc_toolchains = cc_toolchain_forwarder,
31413151
avoid_deps = ctx.attr.frameworks,
3152+
build_settings = apple_xplat_toolchain_info.build_settings,
31423153
# Frameworks do not have entitlements.
31433154
entitlements = None,
31443155
exported_symbols_lists = ctx.files.exported_symbols_lists,

apple/internal/testing/apple_test_bundle_support.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ def _apple_test_bundle_impl(*, ctx, product_type):
392392
ctx,
393393
cc_toolchains = cc_toolchain_forwarder,
394394
avoid_deps = getattr(ctx.attr, "frameworks", []),
395+
build_settings = apple_xplat_toolchain_info.build_settings,
395396
bundle_loader = bundle_loader,
396397
# Unit/UI tests do not use entitlements.
397398
entitlements = None,

apple/internal/tvos_rules.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def _tvos_application_impl(ctx):
225225
ctx,
226226
cc_toolchains = cc_toolchain_forwarder,
227227
avoid_deps = ctx.attr.frameworks,
228+
build_settings = apple_xplat_toolchain_info.build_settings,
228229
entitlements = entitlements.linking,
229230
exported_symbols_lists = ctx.files.exported_symbols_lists,
230231
platform_prerequisites = platform_prerequisites,
@@ -561,6 +562,7 @@ def _tvos_dynamic_framework_impl(ctx):
561562
ctx,
562563
cc_toolchains = cc_toolchain_forwarder,
563564
avoid_deps = ctx.attr.frameworks,
565+
build_settings = apple_xplat_toolchain_info.build_settings,
564566
# Frameworks do not have entitlements.
565567
entitlements = None,
566568
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -848,6 +850,7 @@ def _tvos_framework_impl(ctx):
848850
ctx,
849851
cc_toolchains = cc_toolchain_forwarder,
850852
avoid_deps = ctx.attr.frameworks,
853+
build_settings = apple_xplat_toolchain_info.build_settings,
851854
# Frameworks do not have entitlements.
852855
entitlements = None,
853856
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1133,6 +1136,7 @@ def _tvos_extension_impl(ctx):
11331136
ctx,
11341137
cc_toolchains = cc_toolchain_forwarder,
11351138
avoid_deps = ctx.attr.frameworks,
1139+
build_settings = apple_xplat_toolchain_info.build_settings,
11361140
entitlements = entitlements.linking,
11371141
exported_symbols_lists = ctx.files.exported_symbols_lists,
11381142
extra_linkopts = extra_linkopts,

apple/internal/visionos_rules.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ Resolved Xcode is version {xcode_version}.
233233
ctx,
234234
cc_toolchains = cc_toolchain_forwarder,
235235
avoid_deps = ctx.attr.frameworks,
236+
build_settings = apple_xplat_toolchain_info.build_settings,
236237
entitlements = entitlements.linking,
237238
exported_symbols_lists = ctx.files.exported_symbols_lists,
238239
platform_prerequisites = platform_prerequisites,
@@ -565,6 +566,7 @@ def _visionos_dynamic_framework_impl(ctx):
565566
ctx,
566567
cc_toolchains = cc_toolchain_forwarder,
567568
avoid_deps = ctx.attr.frameworks,
569+
build_settings = apple_xplat_toolchain_info.build_settings,
568570
# Frameworks do not have entitlements.
569571
entitlements = None,
570572
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -853,6 +855,7 @@ def _visionos_framework_impl(ctx):
853855
ctx,
854856
cc_toolchains = cc_toolchain_forwarder,
855857
avoid_deps = ctx.attr.frameworks,
858+
build_settings = apple_xplat_toolchain_info.build_settings,
856859
# Frameworks do not have entitlements.
857860
entitlements = None,
858861
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1125,6 +1128,7 @@ def _visionos_extension_impl(ctx):
11251128
ctx,
11261129
cc_toolchains = cc_toolchain_forwarder,
11271130
avoid_deps = ctx.attr.frameworks,
1131+
build_settings = apple_xplat_toolchain_info.build_settings,
11281132
entitlements = entitlements.linking,
11291133
exported_symbols_lists = ctx.files.exported_symbols_lists,
11301134
extra_linkopts = [

apple/internal/watchos_rules.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def _watchos_framework_impl(ctx):
226226
ctx,
227227
cc_toolchains = cc_toolchain_forwarder,
228228
avoid_deps = ctx.attr.frameworks,
229+
build_settings = apple_xplat_toolchain_info.build_settings,
229230
# Frameworks do not have entitlements.
230231
entitlements = None,
231232
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -506,6 +507,7 @@ def _watchos_dynamic_framework_impl(ctx):
506507
ctx,
507508
cc_toolchains = cc_toolchain_forwarder,
508509
avoid_deps = ctx.attr.frameworks,
510+
build_settings = apple_xplat_toolchain_info.build_settings,
509511
# Frameworks do not have entitlements.
510512
entitlements = None,
511513
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1127,6 +1129,7 @@ def _watchos_extension_impl(ctx):
11271129
ctx,
11281130
cc_toolchains = cc_toolchain_forwarder,
11291131
avoid_deps = ctx.attr.frameworks,
1132+
build_settings = apple_xplat_toolchain_info.build_settings,
11301133
entitlements = entitlements.linking,
11311134
exported_symbols_lists = ctx.files.exported_symbols_lists,
11321135
extra_linkopts = extra_linkopts,
@@ -1597,6 +1600,7 @@ delegate is referenced in the single-target `watchos_application`'s `deps`.
15971600
ctx,
15981601
cc_toolchains = cc_toolchain_forwarder,
15991602
avoid_deps = ctx.attr.frameworks,
1603+
build_settings = apple_xplat_toolchain_info.build_settings,
16001604
entitlements = entitlements.linking,
16011605
exported_symbols_lists = ctx.files.exported_symbols_lists,
16021606
extra_linkopts = [],

apple/internal/xcframework_rules.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ def _apple_xcframework_impl(ctx):
590590

591591
link_result = linking_support.register_binary_linking_action(
592592
ctx,
593+
build_settings = apple_xplat_toolchain_info.build_settings,
593594
cc_toolchains = cc_toolchain_forwarder,
594595
# Frameworks do not have entitlements.
595596
entitlements = None,

0 commit comments

Comments
 (0)