Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also propagate linkstamps through rust_libraries #975

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def collect_deps(label, deps, proc_macro_deps, aliases, are_linkstamps_supported
cc_info = _get_cc_info(dep)
dep_build_info = _get_build_info(dep)

if cc_info and are_linkstamps_supported:
linkstamps.append(cc_info.linking_context.linkstamps())

if crate_info:
# This dependency is a rust_library

Expand Down Expand Up @@ -174,8 +177,6 @@ def collect_deps(label, deps, proc_macro_deps, aliases, are_linkstamps_supported
libs = [get_preferred_artifact(lib) for li in linker_inputs for lib in li.libraries]
transitive_noncrate_libs.append(depset(libs))
transitive_noncrates.append(cc_info.linking_context.linker_inputs)
if are_linkstamps_supported:
linkstamps.append(cc_info.linking_context.linkstamps())
elif dep_build_info:
if build_info:
fail("Several deps are providing build information, " +
Expand Down
51 changes: 34 additions & 17 deletions test/unit/linkstamps/linkstamps_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//rust:defs.bzl", "rust_binary", "rust_test")
load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
load("//test/unit:common.bzl", "assert_action_mnemonic")

def _is_running_on_linux(ctx):
Expand Down Expand Up @@ -64,50 +64,67 @@ def _linkstamps_test():
}),
)

cc_library(
name = "cc_lib_with_linkstamp_transitively",
deps = [":cc_lib_with_linkstamp"],
)

rust_binary(
name = "some_rust_binary",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp"],
)

rust_binary(
name = "some_rust_binary_with_multiple_paths_to_a_linkstamp",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp", ":cc_lib_with_linkstamp_transitively"],
supports_linkstamps_test(
name = "rust_binary_supports_linkstamps_test",
target_under_test = ":some_rust_binary",
)

rust_test(
name = "some_rust_test1",
rust_library(
name = "some_rust_library_with_linkstamp_transitively",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp"],
)

rust_test(
name = "some_rust_test2",
rust_binary(
name = "some_rust_binary_with_linkstamp_transitively",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp"],
deps = [":some_rust_library_with_linkstamp_transitively"],
)

supports_linkstamps_test(
name = "rust_binary_supports_linkstamps_test",
target_under_test = ":some_rust_binary",
name = "rust_binary_with_linkstamp_transitively",
target_under_test = ":some_rust_binary_with_linkstamp_transitively",
)

cc_library(
name = "cc_lib_with_linkstamp_transitively",
deps = [":cc_lib_with_linkstamp"],
)

rust_binary(
name = "some_rust_binary_with_multiple_paths_to_a_linkstamp",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp", ":cc_lib_with_linkstamp_transitively"],
)

supports_linkstamps_test(
name = "rust_binary_supports_duplicated_linkstamps",
target_under_test = ":some_rust_binary_with_multiple_paths_to_a_linkstamp",
)

rust_test(
name = "some_rust_test1",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp"],
)

supports_linkstamps_test(
name = "rust_test_supports_linkstamps_test1",
target_under_test = ":some_rust_test1",
)

rust_test(
name = "some_rust_test2",
srcs = ["foo.rs"],
deps = [":cc_lib_with_linkstamp"],
)

supports_linkstamps_test(
name = "rust_test_supports_linkstamps_test2",
target_under_test = ":some_rust_test2",
Expand Down