bazel: `@bazel_tool//tools/cpp:link_extra_libs` should not propagate to exec config

Description of the feature request:

The C++ compilation rules have a neat feature: they allow you to specify a library that should be a linktime dependency of all cc_binary targets. That library is configured through a label flag, @bazel_tool//tools/cpp:link_extra_libs.

Unfortunately, this label flag persists across the transition from the target to the exec configuration. This is very inconvenient: if the link_extra_libs you want for the target platform include generated code, you run into circular dependencies when trying to build any binaries used in their generation. This tends to happen with some Pigweed libraries, preventing us from using link_extra_libs in most cases.

@gregestren I recall that internally we’ve done some work to restrict flag propagation to the exec config (b/292617118). What’s the status on the open source side?

Which category does this issue belong to?

Configurability

What underlying problem are you trying to solve with this feature?

No response

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

release 7.1.2

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 HEAD ?

No response

Have you found anything relevant by searching the web?

No response

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

No response

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I’m sure this is just a matter of flipping https://github.com/bazelbuild/bazel/blob/4d2250561fc7b16b35eb99cb51921ec530457a4a/src/main/java/com/google/devtools/build/lib/analysis/config/CoreOptions.java#L125-L126.

We flipped that in the org-wide .bazelrc in b/292617118 but not by default.

I think it’s reasonable to flip it here, combined with an announcement to bazel@head users on how to fix potential breakages.

How about I put up a PR and we’ll see if standard Bazel CI passes as a starting point?

Update:

I’m now confident we should follow the process described in the last two comments.

As this thread notes, the complication is if someone needs their Starlark flag to still propagate, you can only do that in a .bazelrc. Which doesn’t generalize well.

What I do feel strongly about (as a developer of a library that’s built in both places) is that we should set the flag to the same default value both internally and in open-source Bazel!

Agreed. The current discrepancy is because Google has its global .bazelc that solves this problem. Bazel of course doesn’t.

Here’s the sequence:

  1. Let @aranguyen 's customizable flag propagation support finish. This makes it possible for Bazel to understand and apply flag annotations like “only propagate to X”.
  2. Add a “propagate_to_exec” flag to build settings, as @fmeum notes
  3. Rename / flip --experimental_exclude_starlark_flags_from_exec_config

1 is well underway. We’ll follow up when the implementation lands.