Skip to content

Commit

Permalink
introduce runtime_dependency_handling
Browse files Browse the repository at this point in the history
Reviewed By: milend

Differential Revision: D67122935

fbshipit-source-id: dd5fcb3fb9cfe1c0a81753d561641c9acdb16abf
  • Loading branch information
jrodal98 authored and facebook-github-bot committed Dec 23, 2024
1 parent a8f23d7 commit 89e95a3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
6 changes: 6 additions & 0 deletions prelude/cxx/cxx.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ load(
"@prelude//cxx:link_groups_types.bzl",
"LinkGroupInfo", # @unused Used as a type
)
load(
"@prelude//cxx:runtime_dependency_handling.bzl",
"cxx_attr_runtime_dependency_handling",
)
load("@prelude//linking:execution_preference.bzl", "LinkExecutionPreference")
load(
"@prelude//linking:link_groups.bzl",
Expand Down Expand Up @@ -275,6 +279,7 @@ def cxx_binary_impl(ctx: AnalysisContext) -> list[Provider]:
platform_preprocessor_flags = ctx.attrs.platform_preprocessor_flags,
lang_platform_preprocessor_flags = ctx.attrs.lang_platform_preprocessor_flags,
use_header_units = ctx.attrs.use_header_units,
runtime_dependency_handling = cxx_attr_runtime_dependency_handling(ctx),
)
output = cxx_executable(ctx, params)

Expand Down Expand Up @@ -770,6 +775,7 @@ def cxx_test_impl(ctx: AnalysisContext) -> list[Provider]:
platform_preprocessor_flags = ctx.attrs.platform_preprocessor_flags,
lang_platform_preprocessor_flags = ctx.attrs.lang_platform_preprocessor_flags,
use_header_units = ctx.attrs.use_header_units,
runtime_dependency_handling = cxx_attr_runtime_dependency_handling(ctx),
)
output = cxx_executable(ctx, params, is_cxx_test = True)

Expand Down
6 changes: 5 additions & 1 deletion prelude/cxx/cxx_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ load(
"LinkGroupsDebugLinkInfo",
"LinkGroupsDebugLinkableItem",
)
load(
"@prelude//cxx:runtime_dependency_handling.bzl",
"RuntimeDependencyHandling",
)
load(
"@prelude//dist:dist_info.bzl",
"DistInfo",
Expand Down Expand Up @@ -508,7 +512,7 @@ def cxx_executable(ctx: AnalysisContext, impl_params: CxxRuleConstructorParams,
# Only setup a shared library symlink tree when shared linkage or link_groups is used
gnu_use_link_groups = cxx_is_gnu(ctx) and len(link_group_mappings) > 0
shlib_deps = []
if link_strategy == LinkStrategy("shared") or gnu_use_link_groups:
if impl_params.runtime_dependency_handling == RuntimeDependencyHandling("symlink") or link_strategy == LinkStrategy("shared") or gnu_use_link_groups:
shlib_deps = (
[d.shared_library_info for d in link_deps] +
[d.shared_library_info for d in impl_params.extra_link_roots]
Expand Down
6 changes: 6 additions & 0 deletions prelude/cxx/cxx_types.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ load(
"@prelude//cxx:link_groups_types.bzl",
"LinkGroupInfo", # @unused Used as a type
)
load(
"@prelude//cxx:runtime_dependency_handling.bzl",
"RuntimeDependencyHandling", # @unused Used as a type
)
load(
"@prelude//linking:link_info.bzl",
"LinkArgs",
Expand Down Expand Up @@ -242,4 +246,6 @@ CxxRuleConstructorParams = record(
export_header_unit = field([str, None], None),
# Filter what headers to include in header units.
export_header_unit_filter = field(list[str], []),
# Additional behavior for how to handle runtime dependencies
runtime_dependency_handling = field([RuntimeDependencyHandling, None], None),
)
18 changes: 18 additions & 0 deletions prelude/cxx/runtime_dependency_handling.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.

# Additional behavior for how to handle runtime dependencies
RuntimeDependencyHandling = enum(
# Do no additional handling
"none",
# Always include runtime dependencies in a symlink tree, regardless
# of whether shared linkage is used or not
"symlink",
)

def cxx_attr_runtime_dependency_handling(ctx: AnalysisContext) -> RuntimeDependencyHandling:
return RuntimeDependencyHandling(ctx.attrs.runtime_dependency_handling or "none")
2 changes: 2 additions & 0 deletions prelude/decls/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ TestType = ["junit", "junit5", "testng"]

UnusedDependenciesAction = ["unknown", "fail", "warn", "ignore", "unrecognized"]

RuntimeDependencyHandling = ["none", "symlink"]

def _name_arg(name_type):
return {
"name": name_type,
Expand Down
12 changes: 11 additions & 1 deletion prelude/decls/cxx_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# the generated docs, and so those should be verified to be accurate and
# well-formatted (and then delete this TODO)

load(":common.bzl", "CxxSourceType", "IncludeType", "RawHeadersAsHeadersMode")
load(":common.bzl", "CxxSourceType", "IncludeType", "RawHeadersAsHeadersMode", "RuntimeDependencyHandling")

def _srcs_arg():
return {
Expand Down Expand Up @@ -442,6 +442,15 @@ def _version_arg():
"""),
}

def _runtime_dependency_handling_arg():
return {
"runtime_dependency_handling": attrs.option(attrs.enum(RuntimeDependencyHandling), default = None, doc = """
When this is set to `symlink`, shared library dependencies are included in a symlink tree
alongside the resulting executable, even if the link style is not shared. Can be `none` or
`symlink`.
"""),
}

cxx_common = struct(
srcs_arg = _srcs_arg,
deps_arg = _deps_arg,
Expand Down Expand Up @@ -485,4 +494,5 @@ cxx_common = struct(
public_include_directories_arg = _public_include_directories_arg,
public_system_include_directories_arg = _public_system_include_directories_arg,
version_arg = _version_arg,
runtime_dependency_handling_arg = _runtime_dependency_handling_arg,
)
2 changes: 2 additions & 0 deletions prelude/decls/cxx_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ cxx_binary = prelude_rule(
cxx_common.raw_headers_arg() |
cxx_common.include_directories_arg() |
cxx_common.raw_headers_as_headers_mode_arg() |
cxx_common.runtime_dependency_handling_arg() |
{
"contacts": attrs.list(attrs.string(), default = []),
"cxx_runtime_type": attrs.option(attrs.enum(CxxRuntimeType), default = None),
Expand Down Expand Up @@ -863,6 +864,7 @@ cxx_test = prelude_rule(
cxx_common.raw_headers_arg() |
cxx_common.raw_headers_as_headers_mode_arg() |
cxx_common.include_directories_arg() |
cxx_common.runtime_dependency_handling_arg() |
{
"framework": attrs.option(attrs.enum(CxxTestType), default = None, doc = """
Unused.
Expand Down

0 comments on commit 89e95a3

Please sign in to comment.