Skip to content

Commit 8cdb863

Browse files
nglevinluispadron
authored andcommitted
Start refactoring features in the rules_apple space to have a common point of origin, focusing on the supporting resources and code signing at this time before untangling linking itself.
Cherry-pick: f5297a1
1 parent 2688df3 commit 8cdb863

32 files changed

+512
-551
lines changed

apple/apple_binary.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ Resolved Xcode is version {xcode_version}.
8484
apple_xplat_toolchain_info = ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo]
8585
binary_type = ctx.attr.binary_type
8686
bundle_loader = ctx.attr.bundle_loader
87-
cc_configured_features_init = features_support.make_cc_configured_features_init(ctx)
87+
cc_configured_features = features_support.cc_configured_features(
88+
ctx = ctx,
89+
)
8890
cc_toolchain_forwarder = ctx.split_attr._cc_toolchain_forwarder
8991

9092
rule_label = ctx.label
9193
secure_features = ctx.attr.secure_features
9294

9395
# Check that the requested secure features are supported and enabled for the toolchain.
9496
secure_features_support.validate_secure_features_support(
95-
cc_configured_features_init = cc_configured_features_init,
97+
cc_configured_features = cc_configured_features,
9698
cc_toolchain_forwarder = cc_toolchain_forwarder,
9799
rule_label = rule_label,
98100
secure_features = secure_features,

apple/apple_static_library.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ load(
4949
)
5050

5151
def _apple_static_library_impl(ctx):
52-
cc_configured_features_init = features_support.make_cc_configured_features_init(ctx)
52+
cc_configured_features = features_support.cc_configured_features(
53+
ctx = ctx,
54+
)
5355
cc_toolchain_forwarder = ctx.split_attr._cc_toolchain_forwarder
5456
rule_label = ctx.label
5557

@@ -81,7 +83,7 @@ Expected Apple platform type of "{platform_type}", but that was not found in {to
8183

8284
# Check that the requested secure features are supported and enabled for the toolchain.
8385
secure_features_support.validate_secure_features_support(
84-
cc_configured_features_init = cc_configured_features_init,
86+
cc_configured_features = cc_configured_features,
8587
cc_toolchain_forwarder = cc_toolchain_forwarder,
8688
rule_label = rule_label,
8789
secure_features = secure_features,

apple/internal/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ bzl_library(
6060
],
6161
deps = [
6262
":cc_toolchain_info_support",
63+
":features_support",
6364
":framework_import_support",
6465
":resources",
6566
":rule_attrs",
@@ -118,6 +119,7 @@ bzl_library(
118119
deps = [
119120
":apple_toolchains",
120121
":cc_toolchain_info_support",
122+
":features_support",
121123
":framework_import_support",
122124
":intermediates",
123125
":rule_attrs",

apple/internal/apple_framework_import.bzl

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ load(
5353
"//apple/internal:experimental.bzl",
5454
"is_experimental_tree_artifact_enabled",
5555
)
56+
load(
57+
"//apple/internal:features_support.bzl",
58+
"features_support",
59+
)
5660
load(
5761
"//apple/internal:framework_import_support.bzl",
5862
"framework_import_support",
@@ -160,17 +164,18 @@ def _apple_dynamic_framework_import_impl(ctx):
160164
"""Implementation for the apple_dynamic_framework_import rule."""
161165
actions = ctx.actions
162166
apple_xplat_toolchain_info = ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo]
167+
cc_configured_features = features_support.cc_configured_features(
168+
ctx = ctx,
169+
)
163170
cc_toolchain = find_cpp_toolchain(ctx)
164171
deps = ctx.attr.deps
165-
disabled_features = ctx.disabled_features
166172
features = ctx.features
167173
framework_imports = ctx.files.framework_imports
168174
label = ctx.label
169175

170176
secure_features_support.validate_expected_secure_features(
171-
disabled_features = disabled_features,
177+
cc_configured_features = cc_configured_features,
172178
expected_secure_features = ctx.attr.expected_secure_features,
173-
features = features,
174179
rule_label = label,
175180
)
176181

@@ -220,11 +225,9 @@ def _apple_dynamic_framework_import_impl(ctx):
220225
# Create CcInfo provider.
221226
cc_info = framework_import_support.cc_info_with_dependencies(
222227
actions = actions,
228+
cc_configured_features = cc_configured_features,
223229
cc_toolchain = cc_toolchain,
224-
ctx = ctx,
225230
deps = deps,
226-
disabled_features = disabled_features,
227-
features = features,
228231
framework_includes = _framework_search_paths(
229232
framework.header_imports +
230233
framework.swift_interface_imports +
@@ -256,8 +259,8 @@ def _apple_dynamic_framework_import_impl(ctx):
256259
actions = actions,
257260
ctx = ctx,
258261
deps = deps,
259-
disabled_features = disabled_features,
260-
features = features,
262+
disabled_features = cc_configured_features.unsupported_features,
263+
features = cc_configured_features.requested_features,
261264
module_name = framework.bundle_name,
262265
swift_toolchain = swift_toolchain,
263266
swiftinterface_file = swiftinterface_files[0],
@@ -279,10 +282,12 @@ def _apple_static_framework_import_impl(ctx):
279282
"""Implementation for the apple_static_framework_import rule."""
280283
actions = ctx.actions
281284
alwayslink = ctx.attr.alwayslink or getattr(ctx.fragments.objc, "alwayslink_by_default", False)
285+
cc_configured_features = features_support.cc_configured_features(
286+
ctx = ctx,
287+
)
282288
cc_toolchain = find_cpp_toolchain(ctx)
283289
compilation_mode = ctx.var["COMPILATION_MODE"]
284290
deps = ctx.attr.deps
285-
disabled_features = ctx.disabled_features
286291
features = ctx.features
287292
framework_imports = ctx.files.framework_imports
288293
has_swift = ctx.attr.has_swift
@@ -292,9 +297,8 @@ def _apple_static_framework_import_impl(ctx):
292297
weak_sdk_frameworks = ctx.attr.weak_sdk_frameworks
293298

294299
secure_features_support.validate_expected_secure_features(
295-
disabled_features = disabled_features,
300+
cc_configured_features = cc_configured_features,
296301
expected_secure_features = ctx.attr.expected_secure_features,
297-
features = features,
298302
rule_label = label,
299303
)
300304

@@ -369,11 +373,9 @@ def _apple_static_framework_import_impl(ctx):
369373
actions = actions,
370374
additional_cc_infos = additional_cc_infos,
371375
alwayslink = alwayslink,
376+
cc_configured_features = cc_configured_features,
372377
cc_toolchain = cc_toolchain,
373-
ctx = ctx,
374378
deps = deps,
375-
disabled_features = disabled_features,
376-
features = features,
377379
framework_includes = _framework_search_paths(
378380
framework.header_imports +
379381
framework.swift_interface_imports +
@@ -401,8 +403,8 @@ def _apple_static_framework_import_impl(ctx):
401403
actions = actions,
402404
ctx = ctx,
403405
deps = deps,
404-
disabled_features = disabled_features,
405-
features = features,
406+
disabled_features = cc_configured_features.unsupported_features,
407+
features = cc_configured_features.requested_features,
406408
module_name = framework.bundle_name,
407409
swift_toolchain = swift_toolchain,
408410
swiftinterface_file = swiftinterface_files[0],

apple/internal/apple_xcframework_import.bzl

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ load(
3838
"//apple/internal:experimental.bzl",
3939
"is_experimental_tree_artifact_enabled",
4040
)
41+
load(
42+
"//apple/internal:features_support.bzl",
43+
"features_support",
44+
)
4145
load(
4246
"//apple/internal:framework_import_support.bzl",
4347
"framework_import_support",
@@ -486,18 +490,19 @@ def _apple_dynamic_xcframework_import_impl(ctx):
486490
apple_fragment = ctx.fragments.apple
487491
apple_mac_toolchain_info = ctx.attr._mac_toolchain[AppleMacToolsToolchainInfo]
488492
apple_xplat_toolchain_info = ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo]
493+
cc_configured_features = features_support.cc_configured_features(
494+
ctx = ctx,
495+
)
489496
cc_toolchain = find_cpp_toolchain(ctx)
490497
deps = ctx.attr.deps
491-
disabled_features = ctx.disabled_features
492-
features = ctx.features
498+
features = cc_configured_features.enabled_features
493499
label = ctx.label
494500
xcframework_imports = ctx.files.xcframework_imports
495501
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
496502

497503
secure_features_support.validate_expected_secure_features(
498-
disabled_features = disabled_features,
504+
cc_configured_features = cc_configured_features,
499505
expected_secure_features = ctx.attr.expected_secure_features,
500-
features = features,
501506
rule_label = label,
502507
)
503508

@@ -550,11 +555,9 @@ def _apple_dynamic_xcframework_import_impl(ctx):
550555
# Create CcInfo provider
551556
cc_info = framework_import_support.cc_info_with_dependencies(
552557
actions = actions,
558+
cc_configured_features = cc_configured_features,
553559
cc_toolchain = cc_toolchain,
554-
ctx = ctx,
555560
deps = deps,
556-
disabled_features = disabled_features,
557-
features = features,
558561
framework_includes = xcframework_library.framework_includes,
559562
header_imports = xcframework_library.headers,
560563
kind = "dynamic",
@@ -579,8 +582,8 @@ def _apple_dynamic_xcframework_import_impl(ctx):
579582
actions = actions,
580583
ctx = ctx,
581584
deps = deps,
582-
disabled_features = disabled_features,
583-
features = features,
585+
disabled_features = cc_configured_features.unsupported_features,
586+
features = cc_configured_features.requested_features,
584587
module_name = xcframework.bundle_name,
585588
swift_toolchain = swift_toolchain,
586589
swiftinterface_file = xcframework_library.swift_module_interface,
@@ -605,20 +608,21 @@ def _apple_static_xcframework_import_impl(ctx):
605608
apple_fragment = ctx.fragments.apple
606609
apple_mac_toolchain_info = ctx.attr._mac_toolchain[AppleMacToolsToolchainInfo]
607610
apple_xplat_toolchain_info = ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo]
611+
cc_configured_features = features_support.cc_configured_features(
612+
ctx = ctx,
613+
)
608614
cc_toolchain = find_cpp_toolchain(ctx)
609615
deps = ctx.attr.deps
610-
disabled_features = ctx.disabled_features
611-
features = ctx.features
616+
features = cc_configured_features.enabled_features
612617
has_swift = ctx.attr.has_swift
613618
label = ctx.label
614619
linkopts = ctx.attr.linkopts
615620
xcframework_imports = ctx.files.xcframework_imports
616621
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
617622

618623
secure_features_support.validate_expected_secure_features(
619-
disabled_features = disabled_features,
624+
cc_configured_features = cc_configured_features,
620625
expected_secure_features = ctx.attr.expected_secure_features,
621-
features = features,
622626
rule_label = label,
623627
)
624628

@@ -695,11 +699,9 @@ def _apple_static_xcframework_import_impl(ctx):
695699
actions = actions,
696700
additional_cc_infos = additional_cc_infos,
697701
alwayslink = alwayslink,
702+
cc_configured_features = cc_configured_features,
698703
cc_toolchain = cc_toolchain,
699-
ctx = ctx,
700704
deps = deps,
701-
disabled_features = disabled_features,
702-
features = features,
703705
header_imports = xcframework_library.headers,
704706
kind = "static",
705707
label = label,
@@ -720,8 +722,8 @@ def _apple_static_xcframework_import_impl(ctx):
720722
actions = actions,
721723
ctx = ctx,
722724
deps = deps,
723-
disabled_features = disabled_features,
724-
features = features,
725+
disabled_features = cc_configured_features.unsupported_features,
726+
features = cc_configured_features.requested_features,
725727
module_name = xcframework.bundle_name,
726728
swift_toolchain = swift_toolchain,
727729
swiftinterface_file = xcframework_library.swift_module_interface,

apple/internal/aspects/resource_aspect.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ def _platform_prerequisites_for_aspect(target, aspect_ctx):
8080
"""Return the set of platform prerequisites that can be determined from this aspect."""
8181
apple_xplat_toolchain_info = aspect_ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo]
8282
deps_and_target = getattr(aspect_ctx.rule.attr, "deps", []) + [target]
83-
uses_swift = swift_support.uses_swift(deps_and_target)
84-
features = features_support.compute_enabled_features(
85-
requested_features = aspect_ctx.features,
86-
unsupported_features = aspect_ctx.disabled_features,
83+
cc_configured_features = features_support.cc_configured_features(
84+
ctx = aspect_ctx,
8785
)
86+
features = cc_configured_features.enabled_features
87+
uses_swift = swift_support.uses_swift(deps_and_target)
8888

8989
# TODO(b/176548199): Support device_families when rule_descriptor can be accessed from an
9090
# aspect, or the list of allowed device families can be determined independently of the

0 commit comments

Comments
 (0)