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

cc_library rule should support additional_linker_inputs option #17788

Closed
nicholasjng opened this issue Mar 15, 2023 · 1 comment
Closed

cc_library rule should support additional_linker_inputs option #17788

nicholasjng opened this issue Mar 15, 2023 · 1 comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: feature request

Comments

@nicholasjng
Copy link
Contributor

nicholasjng commented Mar 15, 2023

Description of the bug:

Relevant discussion: https://groups.google.com/g/bazel-discuss/c/1VFvNBDqzVU

I am trying to pass a (pre-generated) linker response file to a cc_library rule on MacOS, and was pointed to the additional_linker_inputs option in case of a cc_binary, which would allow me to make the file available to the linker.

Unfortunately, it seems the cc_library rule does not support the additional_linker_inputs option. So this can also be considered a feature request for linker file input support for cc_library rules.

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

The desired end result (adapted from the thread):

filegroup(
    name = "linker_response_file",
    srcs = ["linker_response_file.sym"],
)

cc_library(
    name = "main",
    srcs = ["main.cc"],
    additional_linker_inputs = [":linker_response_file.sym"],  # <- throws an ERROR: no such attribute 'additional_linker_inputs' in 'cc_library' rule
    linkopts = ["-Wl,@$(location :linker_response_file.sym)"],
)

Which operating system are you running Bazel on?

MacOS

What is the output of bazel info release?

release 6.1.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

This is a follow-up to https://groups.google.com/g/bazel-discuss/c/1VFvNBDqzVU

(The commenter there told me to open this bug report, but the message does not seem to appear for some reason.)

Any other information, logs, or outputs that you want to share?

No response

@buildbreaker2021 buildbreaker2021 added type: feature request P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed type: bug untriaged labels Mar 21, 2023
iancha1992 pushed a commit to iancha1992/bazel that referenced this issue Aug 16, 2023
This is achieved by the following related changes:

1) Moving the `additional_linker_inputs` attribute up from the `cc_binary_base` rule to the `cc_rule`. The rationale here is that any rule that allows `linkopts` to be set should also support `additional_linker_inputs`.

2) Adding the `additional_linker_inputs` attr to the `cc_library` rule context. This was copied verbatim from the existing `cc_binary` attribute list.

3) Appending the `ctx.files.additional_linker_inputs` list to the list of linker scripts wherever they are passed as `additional_inputs` in the `cc_library.bzl` builtin file corresponding to the `cc_library` rule.

----------------------

For context on this PR, see issue bazelbuild#17788 as well as the original [Google group discussion](https://groups.google.com/g/bazel-discuss/c/1VFvNBDqzVU/m/F5UmYO-RAAAJ), which inspired the feature request.

Resolves bazelbuild#17788.

Closes bazelbuild#18952.

PiperOrigin-RevId: 557505297
Change-Id: I4811b60e102c6426697efcb202296fe77a3d5f25
iancha1992 added a commit that referenced this issue Aug 22, 2023
…19264)

This is achieved by the following related changes:

1) Moving the `additional_linker_inputs` attribute up from the
`cc_binary_base` rule to the `cc_rule`. The rationale here is that any
rule that allows `linkopts` to be set should also support
`additional_linker_inputs`.

2) Adding the `additional_linker_inputs` attr to the `cc_library` rule
context. This was copied verbatim from the existing `cc_binary`
attribute list.

3) Appending the `ctx.files.additional_linker_inputs` list to the list
of linker scripts wherever they are passed as `additional_inputs` in the
`cc_library.bzl` builtin file corresponding to the `cc_library` rule.

----------------------

For context on this PR, see issue #17788 as well as the original [Google
group
discussion](https://groups.google.com/g/bazel-discuss/c/1VFvNBDqzVU/m/F5UmYO-RAAAJ),
which inspired the feature request.

Resolves #17788.

Closes #18952.

Commit
0589995

PiperOrigin-RevId: 557505297
Change-Id: I4811b60e102c6426697efcb202296fe77a3d5f25

Co-authored-by: Nicholas Junge <[email protected]>
@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 6.4.0 RC1. Please test out the release candidate and report any issues as soon as possible. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants