Skip to content

Commit 00d5bd0

Browse files
committed
Add linkopts to build_variables.bzl.
We may want to use shared/dynamic libraries shortly in order to deal with shared code being duplicated by being statically linked to multiple binaries. This changelist doesn't deal with that business yet, but it prepares the way by adding some infrastructure to the cf_cc_binary rule. Namely, that infrastructure allows setting default linkopts in the build_variables.bzl like copts does. We need to do this because Bazel's rpath settings will not be correct when we take binaries built in the Bazel workspace and pull them into the Debian packaging. We will eventually just add $ORIGIN/../lib to the rpath to solve that problem. This may still result in binaries with odd Bazel-generated rpaths, which might be a bit messy, but there might also be ways to clean that up in the future. Bug: 509968291
1 parent f1d672b commit 00d5bd0

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

base/cvd/build_variables.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ COPTS = [
44
"-ftrivial-auto-var-init=zero",
55
"-DNODISCARD_EXPECTED",
66
]
7+
8+
LINKOPTS = [
9+
]

base/cvd/cuttlefish/bazel/rules.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@
1414

1515
load("@aspect_rules_lint//format:defs.bzl", "format_test")
1616
load("@cc_compatibility_proxy//:proxy.bzl", "cc_binary", "cc_library", "cc_test")
17-
load("//:build_variables.bzl", BUILD_VAR_COPTS = "COPTS")
17+
load("//:build_variables.bzl", BUILD_VAR_COPTS = "COPTS", BUILD_VAR_LINKOPTS = "LINKOPTS")
1818
load("//tools/lint:linters.bzl", "clang_tidy_test")
1919

2020
visibility(["//..."])
2121

2222
COPTS = BUILD_VAR_COPTS
23+
LINKOPTS = BUILD_VAR_LINKOPTS
2324

24-
def _cf_cc_binary_implementation(name, clang_format_enabled, clang_tidy_enabled, copts, **kwargs):
25+
def _cf_cc_binary_implementation(name, clang_format_enabled, clang_tidy_enabled, copts, linkopts, **kwargs):
2526
if not clang_tidy_enabled and not kwargs["deprecation"]:
2627
kwargs["deprecation"] = "Not covered by clang-tidy"
2728
cc_binary(
2829
name = name,
2930
copts = (copts or []) + COPTS,
31+
linkopts = (linkopts or []) + LINKOPTS,
3032
**kwargs,
3133
)
3234
if clang_format_enabled:
@@ -51,6 +53,7 @@ cf_cc_binary = macro(
5153
"clang_format_enabled": attr.bool(configurable = False, default = False, doc = "Decide if a corresponding format_test target is generated"),
5254
"clang_tidy_enabled": attr.bool(configurable = False, default = True, doc = "Decide if a corresponding clang_tidy_test target is generated"),
5355
"copts": attr.string_list(configurable = False, default = []),
56+
"linkopts": attr.string_list(configurable = False, default = []),
5457
},
5558
implementation = _cf_cc_binary_implementation,
5659
)

0 commit comments

Comments
 (0)