Skip to content

Commit f0aa4f6

Browse files
EscapeZerofacebook-github-bot
authored andcommitted
support for filtering shared library stubs in symlink tree
Summary: see context from D71155560 and D70927140 and https://fb.workplace.com/groups/930797200910874/permalink/1570732950250626/ This diff gives us the ability to mark cxx library targets as a "stub", which means we will use the shared library during building, but will not copy it to the output folder (letting system libs take precedence). I have confirmed this helps with packaging common OpenGL, X11, and Cuda libraries. Reviewed By: jrodal98 Differential Revision: D71352110 fbshipit-source-id: f320b1641f56361bd5e3f38f7beadf20df88223d
1 parent d978b4d commit f0aa4f6

File tree

6 files changed

+13
-2
lines changed

6 files changed

+13
-2
lines changed

prelude/cxx/cxx.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ def prebuilt_cxx_library_impl(ctx: AnalysisContext) -> list[Provider]:
721721
shared_libs = shared_libs,
722722
linker_flags = linker_flags,
723723
can_be_asset = getattr(ctx.attrs, "can_be_asset", False) or False,
724+
stub = getattr(ctx.attrs, "stub", False),
724725
),
725726
excluded = {ctx.label: None} if not value_or(ctx.attrs.supports_merged_linking, True) else {},
726727
),

prelude/cxx/cxx_executable.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def cxx_executable(ctx: AnalysisContext, impl_params: CxxRuleConstructorParams,
547547
continue
548548
preferred_linkage = linkable_node.linkable.preferred_linkage
549549
output_style = get_lib_output_style(link_strategy, preferred_linkage, PicBehavior("supported"))
550-
if output_style == LibOutputStyle("shared_lib"):
550+
if output_style == LibOutputStyle("shared_lib") and not linkable_node.linkable.stub:
551551
shlib_deps.append(merge_shared_libraries(ctx.actions, node = linkable_node.linkable.shared_libs))
552552
elif impl_params.runtime_dependency_handling == RuntimeDependencyHandling("symlink_single_level_only"):
553553
for d in link_deps + impl_params.extra_link_roots:

prelude/cxx/cxx_library.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ def cxx_library_parameterized(ctx: AnalysisContext, impl_params: CxxRuleConstruc
878878
can_be_asset = getattr(ctx.attrs, "can_be_asset", False) or False,
879879
# We don't want to propagate shared interaces across shared library boundaries.
880880
shared_interface_info = None if preferred_linkage == Linkage("shared") else create_shared_interface_info(ctx, exported_symbol_outputs, []),
881+
stub = getattr(ctx.attrs, "stub", False),
881882
),
882883
excluded = {ctx.label: None} if not value_or(ctx.attrs.supports_merged_linking, True) else {},
883884
),

prelude/cxx/cxx_types.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,6 @@ CxxRuleConstructorParams = record(
248248
export_header_unit_filter = field(list[str], []),
249249
# Additional behavior for how to handle runtime dependencies
250250
runtime_dependency_handling = field([RuntimeDependencyHandling, None], None),
251+
# Should this library only be used for build time linkage
252+
stub = field(bool, False),
251253
)

prelude/linking/linkable_graph.bzl

+6-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ LinkableNode = record(
116116
# It should be SharedInterfaceInfo | None
117117
shared_interface_info = field(typing.Any),
118118

119+
# Should this library only be used for build time linkage
120+
stub = field(bool),
121+
119122
# Only allow constructing within this file.
120123
_private = _DisallowConstruction,
121124
)
@@ -185,7 +188,8 @@ def create_linkable_node(
185188
# TODO(mattpayne): This type is incompatible with Autodeps.
186189
# Once the pyautotargets service is rolled out, we can change it back.
187190
# It should be SharedInterfaceInfo | None
188-
shared_interface_info: typing.Any = None) -> LinkableNode:
191+
shared_interface_info: typing.Any = None,
192+
stub: bool = False) -> LinkableNode:
189193
for output_style in _get_required_outputs_for_linkage(preferred_linkage):
190194
expect(
191195
output_style in link_infos,
@@ -211,6 +215,7 @@ def create_linkable_node(
211215
linker_flags = linker_flags,
212216
ignore_force_static_follows_dependents = ignore_force_static_follows_dependents,
213217
shared_interface_info = shared_interface_info,
218+
stub = stub,
214219
_private = _DisallowConstruction(),
215220
)
216221

prelude/rules_impl.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ inlined_extra_attributes = {
454454
),
455455
"resources": attrs.named_set(attrs.one_of(attrs.dep(), attrs.source(allow_directory = True)), sorted = True, default = []),
456456
"separate_debug_info": attrs.bool(default = False),
457+
"stub": attrs.bool(default = False),
457458
"supports_header_symlink_subtarget": attrs.bool(default = False),
458459
"supports_python_dlopen": attrs.option(attrs.bool(), default = None),
459460
"supports_shlib_interfaces": attrs.bool(default = True),
@@ -590,6 +591,7 @@ inlined_extra_attributes = {
590591
"public_include_directories": attrs.set(attrs.string(), sorted = True, default = []),
591592
"public_system_include_directories": attrs.set(attrs.string(), sorted = True, default = []),
592593
"raw_headers": attrs.set(attrs.source(), sorted = True, default = []),
594+
"stub": attrs.bool(default = False),
593595
"supports_lto": attrs.bool(default = False),
594596
"supports_python_dlopen": attrs.bool(default = True),
595597
"versioned_header_dirs": attrs.option(attrs.versioned(attrs.list(attrs.source(allow_directory = True))), default = None),

0 commit comments

Comments
 (0)