Skip to content

Commit 9c43767

Browse files
nglevinluispadron
authored andcommitted
Pass the bundle name directly into linking logic, so that the dSYM bundle and bundle's binary that is generated by shared linking logic can be based off the bundle name instead of the target name.
NOTE: requires updating rules_cc to at least 0.2.13 Cherry-pick: b5724c7
1 parent b8ecb43 commit 9c43767

14 files changed

Lines changed: 84 additions & 26 deletions

apple/apple_binary.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Resolved Xcode is version {xcode_version}.
106106
cc_toolchains = cc_toolchain_forwarder,
107107
build_settings = apple_xplat_toolchain_info.build_settings,
108108
bundle_loader = bundle_loader,
109+
bundle_name = ctx.label.name,
109110
exported_symbols_lists = ctx.files.exported_symbols_lists,
110111
extra_linkopts = extra_linkopts,
111112
platform_prerequisites = None,

apple/internal/compilation_support.bzl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ def _register_binary_strip_action(
196196
ctx,
197197
apple_platform_info,
198198
binary,
199+
bundle_name,
200+
cc_toolchain,
199201
extra_link_args,
200202
feature_configuration,
201203
name):
@@ -220,7 +222,8 @@ def _register_binary_strip_action(
220222

221223
stripped_binary = outputs.main_binary(
222224
actions = ctx.actions,
223-
apple_platform_info = apple_platform_info,
225+
bundle_name = bundle_name,
226+
cc_toolchain = cc_toolchain,
224227
cpp_fragment = ctx.fragments.cpp,
225228
label = ctx.label,
226229
unstripped = False,
@@ -302,6 +305,7 @@ def _register_configuration_specific_link_actions(
302305
additional_outputs,
303306
apple_platform_info,
304307
attr_linkopts,
308+
bundle_name,
305309
common_variables,
306310
cc_linking_context,
307311
extra_link_args,
@@ -330,7 +334,8 @@ def _register_configuration_specific_link_actions(
330334

331335
binary = outputs.main_binary(
332336
actions = ctx.actions,
333-
apple_platform_info = apple_platform_info,
337+
bundle_name = bundle_name,
338+
cc_toolchain = common_variables.toolchain,
334339
cpp_fragment = ctx.fragments.cpp,
335340
label = ctx.label,
336341
unstripped = unstripped,
@@ -346,6 +351,7 @@ def _register_configuration_specific_link_actions(
346351
apple_platform_info = apple_platform_info,
347352
attr_linkopts = attr_linkopts,
348353
binary = binary,
354+
bundle_name = bundle_name,
349355
cc_linking_context = cc_linking_context,
350356
common_variables = common_variables,
351357
extra_link_args = extra_link_args,
@@ -378,6 +384,7 @@ def _register_configuration_specific_link_actions_with_cpp_variables(
378384
apple_platform_info,
379385
attr_linkopts,
380386
binary,
387+
bundle_name,
381388
cc_linking_context,
382389
common_variables,
383390
extra_link_args,
@@ -434,6 +441,8 @@ def _register_configuration_specific_link_actions_with_cpp_variables(
434441
ctx = ctx,
435442
apple_platform_info = apple_platform_info,
436443
binary = binary,
444+
bundle_name = bundle_name,
445+
cc_toolchain = common_variables.toolchain,
437446
extra_link_args = extra_link_args,
438447
feature_configuration = feature_configuration,
439448
name = name,

apple/internal/intermediates.bzl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616

1717
load("@bazel_skylib//lib:paths.bzl", "paths")
1818

19-
def _intermediates_path_string(*, target_name, output_discriminator):
19+
def _intermediates_path_string(*, target_name, output_discriminator, no_intermediates = False):
2020
"""Returns a preferred path string given a target name and an optional output discriminator."""
21-
if not output_discriminator:
22-
return "%s-intermediates" % target_name
23-
return "%s-intermediates-%s" % (target_name, output_discriminator)
21+
return "{target_name}{intermediates}{output_discriminator}".format(
22+
target_name = target_name,
23+
intermediates = "-intermediates" if not no_intermediates else "",
24+
output_discriminator = "-%s" % output_discriminator if output_discriminator else "",
25+
)
2426

25-
def _directory(*, actions, target_name, output_discriminator, dir_name):
27+
def _directory(*, actions, target_name, output_discriminator, dir_name, no_intermediates = False):
2628
"""Declares an intermediate directory with the given name.
2729
2830
Args:
@@ -32,19 +34,21 @@ def _directory(*, actions, target_name, output_discriminator, dir_name):
3234
output_discriminator: A string to differentiate between different target intermediate files
3335
or `None`.
3436
dir_name: Name of the directory to declare.
37+
no_intermediates: Whether to omit the "-intermediates" component of the path.
3538
3639
Returns:
3740
A new File object that represents an intermediate directory.
3841
"""
3942
intermediates_path = _intermediates_path_string(
4043
target_name = target_name,
4144
output_discriminator = output_discriminator,
45+
no_intermediates = no_intermediates,
4246
)
4347
return actions.declare_directory(
4448
paths.join(intermediates_path, dir_name),
4549
)
4650

47-
def _file(*, actions, target_name, output_discriminator, file_name):
51+
def _file(*, actions, target_name, output_discriminator, file_name, no_intermediates = False):
4852
"""Declares an intermediate file with the given name.
4953
5054
Args:
@@ -54,13 +58,15 @@ def _file(*, actions, target_name, output_discriminator, file_name):
5458
output_discriminator: A string to differentiate between different target intermediate files
5559
or `None`.
5660
file_name: Name of the file to declare.
61+
no_intermediates: Whether to omit the "-intermediates" component of the path.
5762
5863
Returns:
5964
A new File object that represents an intermediate file.
6065
"""
6166
intermediates_path = _intermediates_path_string(
6267
target_name = target_name,
6368
output_discriminator = output_discriminator,
69+
no_intermediates = no_intermediates,
6470
)
6571
return actions.declare_file(
6672
paths.join(intermediates_path, file_name),

apple/internal/ios_rules.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def _ios_application_impl(ctx):
249249
cc_toolchains = cc_toolchain_forwarder,
250250
avoid_deps = ctx.attr.frameworks,
251251
build_settings = apple_xplat_toolchain_info.build_settings,
252+
bundle_name = bundle_name,
252253
entitlements = entitlements.linking,
253254
exported_symbols_lists = ctx.files.exported_symbols_lists,
254255
extra_linkopts = extra_linkopts,
@@ -632,6 +633,7 @@ def _ios_app_clip_impl(ctx):
632633
cc_toolchains = cc_toolchain_forwarder,
633634
avoid_deps = ctx.attr.frameworks,
634635
build_settings = apple_xplat_toolchain_info.build_settings,
636+
bundle_name = bundle_name,
635637
entitlements = entitlements.linking,
636638
exported_symbols_lists = ctx.files.exported_symbols_lists,
637639
platform_prerequisites = platform_prerequisites,
@@ -948,6 +950,7 @@ def _ios_framework_impl(ctx):
948950
cc_toolchains = cc_toolchain_forwarder,
949951
avoid_deps = ctx.attr.frameworks,
950952
build_settings = apple_xplat_toolchain_info.build_settings,
953+
bundle_name = bundle_name,
951954
# Frameworks do not have entitlements.
952955
entitlements = None,
953956
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1224,6 +1227,7 @@ def _ios_extension_impl(ctx):
12241227
cc_toolchains = cc_toolchain_forwarder,
12251228
avoid_deps = ctx.attr.frameworks,
12261229
build_settings = apple_xplat_toolchain_info.build_settings,
1230+
bundle_name = bundle_name,
12271231
entitlements = entitlements.linking,
12281232
exported_symbols_lists = ctx.files.exported_symbols_lists,
12291233
extra_linkopts = extra_linkopts,
@@ -1539,6 +1543,7 @@ def _ios_dynamic_framework_impl(ctx):
15391543
cc_toolchains = cc_toolchain_forwarder,
15401544
avoid_deps = ctx.attr.frameworks,
15411545
build_settings = apple_xplat_toolchain_info.build_settings,
1546+
bundle_name = bundle_name,
15421547
# Frameworks do not have entitlements.
15431548
entitlements = None,
15441549
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -2176,6 +2181,7 @@ def _ios_imessage_extension_impl(ctx):
21762181
cc_toolchains = cc_toolchain_forwarder,
21772182
avoid_deps = ctx.attr.frameworks,
21782183
build_settings = apple_xplat_toolchain_info.build_settings,
2184+
bundle_name = bundle_name,
21792185
entitlements = entitlements.linking,
21802186
exported_symbols_lists = ctx.files.exported_symbols_lists,
21812187
extra_linkopts = extra_linkopts,

apple/internal/linking_support.bzl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def _link_multi_arch_binary(
135135
ctx,
136136
avoid_deps = [],
137137
build_settings,
138+
bundle_name,
138139
cc_toolchains,
139140
extra_linkopts = [],
140141
extra_link_inputs = [],
@@ -153,6 +154,7 @@ def _link_multi_arch_binary(
153154
bundle loader or any dynamic libraries/frameworks that will be loaded by
154155
this binary.
155156
build_settings: A struct with build settings info from AppleXplatToolsToolchainInfo.
157+
bundle_name: The name of the bundle name that the linked binary will be a part of, if any.
156158
cc_toolchains: Dictionary of CcToolchainInfo and ApplePlatformInfo providers under a split
157159
transition to relay target platform information for related deps.
158160
extra_linkopts: A list of strings: Extra linkopts to add to the linking action.
@@ -266,14 +268,14 @@ def _link_multi_arch_binary(
266268
dsym_variants = build_settings.dsym_variant_flag
267269
if dsym_variants == "bundle":
268270
if rule_descriptor:
269-
dsym_bundle_name = ctx.label.name + rule_descriptor.bundle_extension
271+
dsym_bundle_name = bundle_name + rule_descriptor.bundle_extension
270272
else:
271-
dsym_bundle_name = ctx.label.name
273+
dsym_bundle_name = bundle_name
272274

273275
if multi_arch_build:
274276
dsym_output = intermediates.directory(
275277
actions = ctx.actions,
276-
target_name = ctx.label.name,
278+
target_name = bundle_name,
277279
output_discriminator = cc_toolchain.target_gnu_system_name,
278280
dir_name = dsym_bundle_name,
279281
)
@@ -294,13 +296,13 @@ Please report this as a bug to the Apple BUILD Rules team.
294296
))
295297
else:
296298
main_binary_unstripped_basename = outputs.main_binary_basename(
299+
bundle_name = bundle_name,
297300
cpp_fragment = ctx.fragments.cpp,
298-
label_name = ctx.label.name,
299301
unstripped = True,
300302
)
301303
dsym_output = intermediates.file(
302304
actions = ctx.actions,
303-
target_name = ctx.label.name,
305+
target_name = bundle_name,
304306
output_discriminator = cc_toolchain.target_gnu_system_name,
305307
file_name = "{}.dwarf".format(main_binary_unstripped_basename),
306308
)
@@ -320,15 +322,16 @@ Please report this as a bug to the Apple BUILD Rules team.
320322
additional_outputs.append(linkmap)
321323

322324
main_binary_basename = outputs.main_binary_basename(
325+
bundle_name = bundle_name,
323326
cpp_fragment = ctx.fragments.cpp,
324-
label_name = ctx.label.name,
325327
unstripped = False,
326328
)
327329

328330
executable = compilation_support.register_configuration_specific_link_actions(
329331
additional_outputs = additional_outputs,
330332
apple_platform_info = platform_info,
331333
attr_linkopts = attr_linkopts,
334+
bundle_name = bundle_name,
332335
cc_linking_context = subtracted_cc_linking_context,
333336
common_variables = common_variables,
334337
extra_link_args = extra_linkopts,
@@ -435,6 +438,7 @@ def _register_binary_linking_action(
435438
*,
436439
avoid_deps = [],
437440
build_settings,
441+
bundle_name,
438442
bundle_loader = None,
439443
cc_toolchains,
440444
entitlements = None,
@@ -456,6 +460,7 @@ def _register_binary_linking_action(
456460
avoid_deps: A list of `Target`s representing dependencies of the binary but whose
457461
symbols should not be linked into it.
458462
build_settings: A struct with build settings info from AppleXplatToolsToolchainInfo.
463+
bundle_name: The name of the bundle name that the linked binary will be a part of, if any.
459464
bundle_loader: For Mach-O bundles, the `Target` whose binary will load this bundle.
460465
This target must propagate the `AppleExecutableBinaryInfo` provider.
461466
This simplifies the process of passing the bundle loader to all the arguments
@@ -567,6 +572,7 @@ def _register_binary_linking_action(
567572
ctx = ctx,
568573
avoid_deps = all_avoid_deps,
569574
build_settings = build_settings,
575+
bundle_name = bundle_name,
570576
cc_toolchains = cc_toolchains,
571577
extra_linkopts = linkopts,
572578
extra_link_inputs = link_inputs,

apple/internal/macos_rules.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def _macos_application_impl(ctx):
242242
cc_toolchains = cc_toolchain_forwarder,
243243
avoid_deps = ctx.attr.frameworks,
244244
build_settings = apple_xplat_toolchain_info.build_settings,
245+
bundle_name = bundle_name,
245246
entitlements = entitlements.linking,
246247
exported_symbols_lists = ctx.files.exported_symbols_lists,
247248
platform_prerequisites = platform_prerequisites,
@@ -552,6 +553,7 @@ def _macos_bundle_impl(ctx):
552553
cc_toolchains = cc_toolchain_forwarder,
553554
build_settings = apple_xplat_toolchain_info.build_settings,
554555
bundle_loader = ctx.attr.bundle_loader,
556+
bundle_name = bundle_name,
555557
entitlements = entitlements.linking,
556558
exported_symbols_lists = ctx.files.exported_symbols_lists,
557559
extra_linkopts = ["-bundle"],
@@ -803,6 +805,7 @@ def _macos_extension_impl(ctx):
803805
cc_toolchains = cc_toolchain_forwarder,
804806
avoid_deps = ctx.attr.frameworks,
805807
build_settings = apple_xplat_toolchain_info.build_settings,
808+
bundle_name = bundle_name,
806809
entitlements = entitlements.linking,
807810
exported_symbols_lists = ctx.files.exported_symbols_lists,
808811
extra_linkopts = extra_linkopts,
@@ -1074,6 +1077,7 @@ def _macos_quick_look_plugin_impl(ctx):
10741077
link_result = linking_support.register_binary_linking_action(
10751078
ctx,
10761079
build_settings = apple_xplat_toolchain_info.build_settings,
1080+
bundle_name = bundle_name,
10771081
cc_toolchains = cc_toolchain_forwarder,
10781082
entitlements = entitlements.linking,
10791083
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1326,6 +1330,7 @@ def _macos_kernel_extension_impl(ctx):
13261330
link_result = linking_support.register_binary_linking_action(
13271331
ctx,
13281332
build_settings = apple_xplat_toolchain_info.build_settings,
1333+
bundle_name = bundle_name,
13291334
cc_toolchains = cc_toolchain_forwarder,
13301335
entitlements = entitlements.linking,
13311336
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1567,6 +1572,7 @@ def _macos_spotlight_importer_impl(ctx):
15671572
link_result = linking_support.register_binary_linking_action(
15681573
ctx,
15691574
build_settings = apple_xplat_toolchain_info.build_settings,
1575+
bundle_name = bundle_name,
15701576
cc_toolchains = cc_toolchain_forwarder,
15711577
entitlements = entitlements.linking,
15721578
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -1806,6 +1812,7 @@ def _macos_xpc_service_impl(ctx):
18061812
link_result = linking_support.register_binary_linking_action(
18071813
ctx,
18081814
build_settings = apple_xplat_toolchain_info.build_settings,
1815+
bundle_name = bundle_name,
18091816
cc_toolchains = cc_toolchain_forwarder,
18101817
entitlements = entitlements.linking,
18111818
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -2020,6 +2027,7 @@ def _macos_command_line_application_impl(ctx):
20202027
link_result = linking_support.register_binary_linking_action(
20212028
ctx,
20222029
build_settings = apple_xplat_toolchain_info.build_settings,
2030+
bundle_name = bundle_name,
20232031
cc_toolchains = cc_toolchain_forwarder,
20242032
# Command-line applications do not have entitlements.
20252033
entitlements = None,
@@ -2173,6 +2181,7 @@ def _macos_dylib_impl(ctx):
21732181
link_result = linking_support.register_binary_linking_action(
21742182
ctx,
21752183
build_settings = apple_xplat_toolchain_info.build_settings,
2184+
bundle_name = bundle_name,
21762185
cc_toolchains = cc_toolchain_forwarder,
21772186
# Dynamic libraries do not have entitlements.
21782187
entitlements = None,
@@ -2864,6 +2873,7 @@ def _macos_framework_impl(ctx):
28642873
cc_toolchains = cc_toolchain_forwarder,
28652874
avoid_deps = ctx.attr.frameworks,
28662875
build_settings = apple_xplat_toolchain_info.build_settings,
2876+
bundle_name = bundle_name,
28672877
# Frameworks do not have entitlements.
28682878
entitlements = None,
28692879
exported_symbols_lists = ctx.files.exported_symbols_lists,
@@ -3147,6 +3157,7 @@ def _macos_dynamic_framework_impl(ctx):
31473157
cc_toolchains = cc_toolchain_forwarder,
31483158
avoid_deps = ctx.attr.frameworks,
31493159
build_settings = apple_xplat_toolchain_info.build_settings,
3160+
bundle_name = bundle_name,
31503161
# Frameworks do not have entitlements.
31513162
entitlements = None,
31523163
exported_symbols_lists = ctx.files.exported_symbols_lists,

0 commit comments

Comments
 (0)