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

Support alwayslink for linking with clang #2647

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,15 @@ _common_attrs = {
These are other `rust_library` targets and will be presented as the new name given.
"""),
),
"alwayslink": attr.bool(
doc = dedent("""\
If 1, any binary that depends (directly or indirectly) on this library
will link in all the object files even if some contain no symbols referenced by the binary.

This attribute is used by the C++ Starlark API when passing CcInfo providers.
"""),
default = False,
),
"compile_data": attr.label_list(
doc = dedent("""\
List of files used by this rule at compile time.
Expand Down
2 changes: 2 additions & 0 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,7 @@ def establish_cc_info(ctx, attr, crate_info, toolchain, cc_toolchain, feature_co
static_library = crate_info.output,
# TODO(hlopko): handle PIC/NOPIC correctly
pic_static_library = crate_info.output,
alwayslink = getattr(ctx.attr, "alwayslink", False),
cerisier marked this conversation as resolved.
Show resolved Hide resolved
)
elif crate_info.type in ("rlib", "lib"):
# bazel hard-codes a check for endswith((".a", ".pic.a",
Expand All @@ -1610,6 +1611,7 @@ def establish_cc_info(ctx, attr, crate_info, toolchain, cc_toolchain, feature_co
static_library = dot_a,
# TODO(hlopko): handle PIC/NOPIC correctly
pic_static_library = dot_a,
alwayslink = getattr(ctx.attr, "alwayslink", False),
cerisier marked this conversation as resolved.
Show resolved Hide resolved
)
elif crate_info.type == "cdylib":
library_to_link = cc_common.create_library_to_link(
Expand Down