Skip to content

Commit c58176a

Browse files
committed
Respect runfiles of deps in cc_shared_library
One of the providers of `cc_shared_library` is `DefaultInfo`, so that one can use the produced library as a standalone artifact (without further consumption by CC rules). An example would be to just `dlopen` that from another program. For that to work, it needs to provide the complete runfiles as well, especially these needed by the (static) libraries it consists of. This change adds the missing collection of runfiles over `deps`.
1 parent 128cf88 commit c58176a

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

cc/private/rules_impl/cc_shared_library_impl.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,8 @@ def _cc_shared_library_impl(ctx):
729729
runfiles = ctx.runfiles(
730730
files = runfiles_files,
731731
)
732+
for dep in ctx.attr.deps:
733+
runfiles = runfiles.merge(dep[DefaultInfo].data_runfiles)
732734
for dep in ctx.attr.dynamic_deps:
733735
runfiles = runfiles.merge(dep[DefaultInfo].data_runfiles)
734736

tests/cc/common/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
load(":cc_binary_configured_target_tests.bzl", "cc_binary_configured_target_tests")
22
load(":cc_common_test.bzl", "cc_common_tests")
3+
load(":cc_shared_library_configured_target_tests.bzl", "cc_shared_library_configured_target_tests")
34

45
cc_binary_configured_target_tests(name = "cc_binary_configured_target_tests")
56

67
cc_common_tests(name = "cc_common_tests")
8+
9+
cc_shared_library_configured_target_tests(name = "cc_shared_library_configured_target_tests")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Tests for cc_shared_library."""
2+
3+
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
4+
load("@rules_testing//lib:truth.bzl", "matching")
5+
load("@rules_testing//lib:util.bzl", "util")
6+
load("//cc:cc_library.bzl", "cc_library")
7+
load("//cc:cc_shared_library.bzl", "cc_shared_library")
8+
load("//tests/cc/testutil:cc_analysis_test.bzl", "cc_analysis_test")
9+
10+
def _test_runfiles(name, **kwargs):
11+
util.helper_target(
12+
cc_shared_library,
13+
name = name + "/runfiles/0",
14+
deps = [name + "/runfiles/1"],
15+
)
16+
file1 = util.empty_file(name = name + "/runfiles/file1")
17+
util.helper_target(
18+
cc_library,
19+
name = name + "/runfiles/1",
20+
data = [file1],
21+
)
22+
cc_analysis_test(
23+
name = name,
24+
impl = _test_runfiles_impl,
25+
target = name + "/runfiles/0",
26+
**kwargs,
27+
)
28+
29+
def _test_runfiles_impl(env, target):
30+
env.expect.that_target(target).data_runfiles().contains_predicate(
31+
matching.str_endswith("lib0.so"))
32+
env.expect.that_target(target).data_runfiles().contains_predicate(
33+
matching.str_endswith("file1"))
34+
35+
def cc_shared_library_configured_target_tests(name):
36+
test_suite(
37+
name = name,
38+
tests = [
39+
_test_runfiles,
40+
],
41+
)

0 commit comments

Comments
 (0)