Skip to content

Commit c0cf097

Browse files
mzleemeta-codesync[bot]
authored andcommitted
Support frameworks in cxx_library for apple_library swap
Summary: Move framework search path preprocessor creation from apple_library and apple_binary into cxx_library_parameterized and cxx_executable respectively. This eliminates duplication when apple_library calls cxx_library_parameterized (or apple_binary calls cxx_executable), and enables cxx_library/cxx_binary/cxx_test to properly handle the frameworks attribute when used as replacements for apple rules in fb_xplat_cxx_library. Changes: - cxx_library.bzl: Add framework search path flags (-F) to both own_preprocessors and own_exported_preprocessors when frameworks attribute is set - cxx_executable.bzl: Add framework search path flags to own_preprocessors for cxx_binary/cxx_test support - apple_library.bzl: Remove duplicate framework_search_path_pre creation (now handled by cxx_library_parameterized) - apple_binary.bzl: Remove duplicate framework_search_path_pre creation (now handled by cxx_executable) - Add integration tests: build tests for apple_library, cxx_library, and cxx_binary with frameworks; compilation database test verifying -F flags are present and not duplicated This unblocks D90707637 which swaps apple_library -> cxx_library in fb_xplat_cxx_library. Reviewed By: milend Differential Revision: D91696908 fbshipit-source-id: b938cf1a3a2e203cac5b45efd76fa486da84cd2e
1 parent fb9dca9 commit c0cf097

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

prelude/apple/apple_binary.bzl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ load(
6060
"get_link_group_info",
6161
)
6262
load("@prelude//cxx:link_types.bzl", "ExtraLinkerOutputCategory")
63-
load(
64-
"@prelude//cxx:preprocessor.bzl",
65-
"CPreprocessor",
66-
"CPreprocessorArgs",
67-
)
6863
load(
6964
"@prelude//linking:link_info.bzl",
7065
"CxxSanitizerRuntimeInfo",
@@ -129,10 +124,6 @@ def apple_binary_impl(ctx: AnalysisContext) -> [list[Provider], Promise]:
129124
]
130125
extension_compiler_flags = ["-fapplication-extension"]
131126

132-
framework_search_path_pre = CPreprocessor(
133-
args = CPreprocessorArgs(args = [framework_search_path_flags]),
134-
)
135-
136127
swift_dependency_info = swift_compile.dependency_info if swift_compile else get_swift_dependency_info(ctx, None, deps_providers, False)
137128
swift_debug_info = get_swift_debug_infos(
138129
ctx,
@@ -174,7 +165,7 @@ def apple_binary_impl(ctx: AnalysisContext) -> [list[Provider], Promise]:
174165
),
175166
extra_link_input = swift_object_files,
176167
extra_link_input_has_external_debug_info = True,
177-
extra_preprocessors = [framework_search_path_pre] + swift_preprocessor,
168+
extra_preprocessors = swift_preprocessor,
178169
strip_executable = stripped,
179170
strip_args_factory = apple_strip_args,
180171
cxx_populate_xcode_attributes_func = lambda local_ctx, **kwargs: apple_populate_xcode_attributes(local_ctx, contains_swift_sources = contains_swift_sources, **kwargs),

prelude/apple/apple_library.bzl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ load(
9090
load(
9191
"@prelude//cxx:preprocessor.bzl",
9292
"CPreprocessor",
93-
"CPreprocessorArgs",
9493
"CPreprocessorInfo", # @unused Used as a type
9594
)
9695
load("@prelude//cxx:target_sdk_version.bzl", "get_unversioned_target_triple")
@@ -445,10 +444,6 @@ def apple_library_rule_constructor_params_and_swift_providers(ctx: AnalysisConte
445444

446445
return providers
447446

448-
framework_search_path_pre = CPreprocessor(
449-
args = CPreprocessorArgs(args = [framework_search_paths_flags]),
450-
)
451-
452447
validation_deps_outputs = get_validation_deps_outputs(ctx)
453448
if swift_compile:
454449
swift_objc_header = swift_compile.exported_swift_header
@@ -528,7 +523,7 @@ def apple_library_rule_constructor_params_and_swift_providers(ctx: AnalysisConte
528523
extra_link_input = swift_object_files,
529524
extra_link_input_has_external_debug_info = True,
530525
extra_preprocessors = [swift_pre, modular_pre],
531-
extra_exported_preprocessors = filter(None, [framework_search_path_pre, exported_pre]),
526+
extra_exported_preprocessors = filter(None, [exported_pre]),
532527
srcs = cxx_srcs,
533528
additional = CxxRuleAdditionalParams(
534529
srcs = swift_srcs,

prelude/cxx/cxx_executable.bzl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ load(
2525
"apple_build_link_args_with_deduped_flags",
2626
"apple_create_frameworks_linkable",
2727
"apple_get_link_info_by_deduping_link_infos",
28+
"get_framework_search_path_flags",
2829
)
2930
load(
3031
"@prelude//cxx:cxx_bolt.bzl",
@@ -196,6 +197,8 @@ load(
196197
)
197198
load(
198199
":preprocessor.bzl",
200+
"CPreprocessor",
201+
"CPreprocessorArgs",
199202
"cxx_inherited_preprocessor_infos",
200203
"cxx_private_preprocessor_info",
201204
)
@@ -247,19 +250,32 @@ def cxx_executable(ctx: AnalysisContext, impl_params: CxxRuleConstructorParams,
247250
)
248251
inherited_preprocessor_infos = cxx_inherited_preprocessor_infos(preprocessor_deps) + impl_params.extra_preprocessors_info
249252

253+
# Add framework search paths if frameworks attribute is set.
254+
# This is needed for the apple_test/apple_binary -> cxx_test/cxx_binary swap.
255+
frameworks = getattr(ctx.attrs, "frameworks", [])
256+
framework_search_path_pre = None
257+
if frameworks:
258+
framework_search_paths_flags = get_framework_search_path_flags(ctx)
259+
framework_search_path_pre = CPreprocessor(
260+
args = CPreprocessorArgs(args = [framework_search_paths_flags]),
261+
)
262+
250263
# The link style to use.
251264
link_strategy = to_link_strategy(cxx_attr_link_style(ctx))
252265
link_strategy = process_link_strategy_for_pic_behavior(link_strategy, get_cxx_toolchain_info(ctx).pic_behavior)
253266

254267
sub_targets = {}
255268

256269
# Compile objects.
270+
own_preprocessors = [own_preprocessor_info] + test_preprocessor_infos
271+
if framework_search_path_pre:
272+
own_preprocessors.insert(0, framework_search_path_pre)
257273
compile_cmd_output = create_compile_cmds(
258274
ctx.actions,
259275
ctx.label,
260276
get_cxx_toolchain_info(ctx),
261277
impl_params,
262-
[own_preprocessor_info] + test_preprocessor_infos,
278+
own_preprocessors,
263279
inherited_preprocessor_infos,
264280
is_coverage_enabled_by_any_dep(ctx, preprocessor_deps),
265281
)

prelude/cxx/cxx_library.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ load(
2727
"apple_build_link_args_with_deduped_flags",
2828
"apple_create_frameworks_linkable",
2929
"apple_get_link_info_by_deduping_link_infos",
30+
"get_framework_search_path_flags",
3031
)
3132
load(
3233
"@prelude//apple:apple_resource_types.bzl",
@@ -233,6 +234,7 @@ load(
233234
load(
234235
":preprocessor.bzl",
235236
"CPreprocessor", # @unused Used as a type
237+
"CPreprocessorArgs",
236238
"CPreprocessorForTestsInfo",
237239
"CPreprocessorInfo", # @unused Used as a type
238240
"cxx_exported_preprocessor_info",
@@ -467,6 +469,17 @@ def cxx_library_parameterized(ctx: AnalysisContext, impl_params: CxxRuleConstruc
467469
own_preprocessors = [own_non_exported_preprocessor_info, own_exported_preprocessor_info] + test_preprocessor_infos
468470
own_exported_preprocessors = [own_exported_preprocessor_info]
469471

472+
# Add framework search paths to exported preprocessors if frameworks attribute is set.
473+
# This is needed for the apple_library -> cxx_library swap in fb_xplat_cxx_library.
474+
frameworks = getattr(ctx.attrs, "frameworks", [])
475+
if frameworks:
476+
framework_search_paths_flags = get_framework_search_path_flags(ctx)
477+
framework_search_path_pre = CPreprocessor(
478+
args = CPreprocessorArgs(args = [framework_search_paths_flags]),
479+
)
480+
own_exported_preprocessors.insert(0, framework_search_path_pre)
481+
own_preprocessors.insert(0, framework_search_path_pre)
482+
470483
inherited_non_exported_preprocessor_infos = cxx_inherited_preprocessor_infos(
471484
# Legacy precompiled_header implementation is not exported. Proper precompiled headers can have exported linkables.
472485
non_exported_deps + filter(None, [impl_params.precompiled_header if impl_params.precompiled_header and not impl_params.precompiled_header[CPrecompiledHeaderInfo].compiled else None]),

0 commit comments

Comments
 (0)