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

[bug] fix coverage linker flags when using --@rules_rust//rust/settin… #2836

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ tasks:
- "//..."
# The with_global_alloc directory is a repository on its own tested in the 'Build via cc_common.link using a global allocator' task.
- "-//with_global_alloc/..."
coverage_targets:
- "--"
- "//..."
# The with_global_alloc directory is a repository on its own tested in the 'Build via cc_common.link using a global allocator' task.
- "-//with_global_alloc/..."
build_flags:
- "--@rules_rust//rust/settings:experimental_use_cc_common_link=True"
test_flags:
Expand All @@ -551,6 +556,8 @@ tasks:
- "//..."
test_targets:
- "//..."
coverage_targets:
- "//..."
build_flags:
- "--@rules_rust//rust/settings:experimental_use_cc_common_link=True"
- "--@rules_rust//rust/settings:experimental_use_global_allocator=True"
Expand All @@ -565,6 +572,8 @@ tasks:
- "//..."
test_targets:
- "//..."
# coverage_targets: # TODO: fix https://github.com/bazelbuild/rules_rust/issues/2838
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved
# - "//..."
build_flags:
- "--@rules_rust//rust/toolchain/channel=nightly"
- "--@rules_rust//rust/settings:experimental_use_cc_common_link=True"
Expand Down
6 changes: 6 additions & 0 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,11 @@ def rustc_compile_action(
# Append the name of the library
output_relative_to_package = output_relative_to_package + output_lib

coverage_link_flags = []
if include_coverage:
# fixes missing symbols coverage fails due to gcc lacking a few linker args
coverage_link_flags = ["-u", "__llvm_profile_runtime"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you're not using gcc?


cc_common.link(
actions = ctx.actions,
feature_configuration = feature_configuration,
Expand All @@ -1441,6 +1446,7 @@ def rustc_compile_action(
name = output_relative_to_package,
stamp = ctx.attr.stamp,
output_type = "executable" if crate_info.type == "bin" else "dynamic_library",
user_link_flags = coverage_link_flags,
)

outputs = [crate_info.output]
Expand Down