Skip to content

Commit 89d207b

Browse files
authored
Also propagate linkstamps through rust_libraries (#975)
Before this PR we were only propagating linkstamps from C++ dependency to Rust target, but we did not propagate from Rust to Rust. This PR fixes it by moving the logic to collect linkstamps from dependencies from the if branch that only covers C++ deps to a place that affects all deps.
1 parent 9d3303d commit 89d207b

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

rust/private/rustc.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ def collect_deps(label, deps, proc_macro_deps, aliases, are_linkstamps_supported
147147
cc_info = _get_cc_info(dep)
148148
dep_build_info = _get_build_info(dep)
149149

150+
if cc_info and are_linkstamps_supported:
151+
linkstamps.append(cc_info.linking_context.linkstamps())
152+
150153
if crate_info:
151154
# This dependency is a rust_library
152155

@@ -174,8 +177,6 @@ def collect_deps(label, deps, proc_macro_deps, aliases, are_linkstamps_supported
174177
libs = [get_preferred_artifact(lib) for li in linker_inputs for lib in li.libraries]
175178
transitive_noncrate_libs.append(depset(libs))
176179
transitive_noncrates.append(cc_info.linking_context.linker_inputs)
177-
if are_linkstamps_supported:
178-
linkstamps.append(cc_info.linking_context.linkstamps())
179180
elif dep_build_info:
180181
if build_info:
181182
fail("Several deps are providing build information, " +

test/unit/linkstamps/linkstamps_test.bzl

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
44
load("@rules_cc//cc:defs.bzl", "cc_library")
5-
load("//rust:defs.bzl", "rust_binary", "rust_test")
5+
load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
66
load("//test/unit:common.bzl", "assert_action_mnemonic")
77

88
def _is_running_on_linux(ctx):
@@ -64,50 +64,67 @@ def _linkstamps_test():
6464
}),
6565
)
6666

67-
cc_library(
68-
name = "cc_lib_with_linkstamp_transitively",
69-
deps = [":cc_lib_with_linkstamp"],
70-
)
71-
7267
rust_binary(
7368
name = "some_rust_binary",
7469
srcs = ["foo.rs"],
7570
deps = [":cc_lib_with_linkstamp"],
7671
)
7772

78-
rust_binary(
79-
name = "some_rust_binary_with_multiple_paths_to_a_linkstamp",
80-
srcs = ["foo.rs"],
81-
deps = [":cc_lib_with_linkstamp", ":cc_lib_with_linkstamp_transitively"],
73+
supports_linkstamps_test(
74+
name = "rust_binary_supports_linkstamps_test",
75+
target_under_test = ":some_rust_binary",
8276
)
8377

84-
rust_test(
85-
name = "some_rust_test1",
78+
rust_library(
79+
name = "some_rust_library_with_linkstamp_transitively",
8680
srcs = ["foo.rs"],
8781
deps = [":cc_lib_with_linkstamp"],
8882
)
8983

90-
rust_test(
91-
name = "some_rust_test2",
84+
rust_binary(
85+
name = "some_rust_binary_with_linkstamp_transitively",
9286
srcs = ["foo.rs"],
93-
deps = [":cc_lib_with_linkstamp"],
87+
deps = [":some_rust_library_with_linkstamp_transitively"],
9488
)
9589

9690
supports_linkstamps_test(
97-
name = "rust_binary_supports_linkstamps_test",
98-
target_under_test = ":some_rust_binary",
91+
name = "rust_binary_with_linkstamp_transitively",
92+
target_under_test = ":some_rust_binary_with_linkstamp_transitively",
93+
)
94+
95+
cc_library(
96+
name = "cc_lib_with_linkstamp_transitively",
97+
deps = [":cc_lib_with_linkstamp"],
98+
)
99+
100+
rust_binary(
101+
name = "some_rust_binary_with_multiple_paths_to_a_linkstamp",
102+
srcs = ["foo.rs"],
103+
deps = [":cc_lib_with_linkstamp", ":cc_lib_with_linkstamp_transitively"],
99104
)
100105

101106
supports_linkstamps_test(
102107
name = "rust_binary_supports_duplicated_linkstamps",
103108
target_under_test = ":some_rust_binary_with_multiple_paths_to_a_linkstamp",
104109
)
105110

111+
rust_test(
112+
name = "some_rust_test1",
113+
srcs = ["foo.rs"],
114+
deps = [":cc_lib_with_linkstamp"],
115+
)
116+
106117
supports_linkstamps_test(
107118
name = "rust_test_supports_linkstamps_test1",
108119
target_under_test = ":some_rust_test1",
109120
)
110121

122+
rust_test(
123+
name = "some_rust_test2",
124+
srcs = ["foo.rs"],
125+
deps = [":cc_lib_with_linkstamp"],
126+
)
127+
111128
supports_linkstamps_test(
112129
name = "rust_test_supports_linkstamps_test2",
113130
target_under_test = ":some_rust_test2",

0 commit comments

Comments
 (0)