Align action configs with legacy ones to allow LtoBackend actions to succeed

Copybara Import from https://github.com/bazelbuild/rules_cc/pull/528

BEGIN_PUBLIC
Align action configs with legacy ones to allow LtoBackend actions to succeed (#528)

This matches how it was previously setup: https://github.com/bazelbuild/rules_cc/blob/933844609a1c1f0ea0ddb64c28d463e901f36f57/cc/private/toolchain_config/legacy_features.bzl#L169-L187

Without this, we get:

```
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.AssertionError: LtoBackendAction command line expansion cannot fail
	at com.google.devtools.build.lib.rules.cpp.LtoBackendAction.computeKey(LtoBackendAction.java:288)
	at com.google.devtools.build.lib.actions.ActionKeyComputer.getKey(ActionKeyComputer.java:43)
	at com.google.devtools.build.lib.actions.ActionCacheChecker.mustExecute(ActionCacheChecker.java:575)
	at com.google.devtools.build.lib.actions.ActionCacheChecker.getTokenIfNeedToExecute(ActionCacheChecker.java:507)
	at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.checkActionCache(SkyframeActionExecutor.java:764)
	at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.checkCacheAndExecuteIfNeeded(ActionExecutionFunction.java:706)
	at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.computeInternal(ActionExecutionFunction.java:345)
	at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.compute(ActionExecutionFunction.java:202)
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:471)
	at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:435)
	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.compute(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinTask$InterruptibleTask.exec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Caused by: com.google.devtools.build.lib.actions.CommandLineExpansionException: Invalid toolchain configuration: Cannot find variable named 'preprocessor_defines'.
	at com.google.devtools.build.lib.rules.cpp.LtoBackendArtifacts$1.arguments(LtoBackendArtifacts.java:129)
	at com.google.devtools.build.lib.rules.cpp.LtoBackendArtifacts$1.arguments(LtoBackendArtifacts.java:109)
	at com.google.devtools.build.lib.actions.CommandLines.allArguments(CommandLines.java:171)
	at com.google.devtools.build.lib.analysis.actions.SpawnAction.getArguments(SpawnAction.java:208)
	at com.google.devtools.build.lib.rules.cpp.LtoBackendAction.computeKey(LtoBackendAction.java:286)
```

I now have this fully working e2e at https://github.com/cerisier/toolchains_llvm_bootstrapped/pull/56/files#diff-cce4f0083471dff12279a3b4e3b3206404e4932a3d60f3443c0f60900706093e so happy to contribute those feature targets as well if someone tells me where to put them :)

Closes #528
END_PUBLIC

COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_cc/pull/528 from dzbarsky:zbarsky/fix-lto 505202d995075b2d786760e41adccf5e7d2771ea
PiperOrigin-RevId: 835974414
Change-Id: Idc2c40ec66a48e679417edaddf545b889d717fc2
5 files changed
tree: beb3bdd838bd0467b1dc53dd7223ed925e7be633
  1. .bazelci/
  2. .bcr/
  3. .github/
  4. cc/
  5. docs/
  6. examples/
  7. tests/
  8. .bazelignore
  9. .bazelrc
  10. .gitignore
  11. AUTHORS
  12. BUILD
  13. CODEOWNERS
  14. CONTRIBUTING.md
  15. googletest.patch
  16. ISSUE_TEMPLATE.md
  17. LICENSE
  18. MODULE.bazel
  19. README.md
  20. renovate.json
  21. WORKSPACE
  22. WORKSPACE.bzlmod
README.md

C++ rules for Bazel

  • Postsubmit Build status

This repository contains a Starlark implementation of C++ rules in Bazel.

The rules are being incrementally converted from their native implementations in the Bazel source tree.

For the list of C++ rules, see the Bazel documentation.

Getting Started

Add the following to your WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "rules_cc",
    urls = ["https://github.com/bazelbuild/rules_cc/archive/refs/tags/<VERSION>.tar.gz"],
    sha256 = "...",
)

Then, in your BUILD files, import and use the rules:

load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
    ...
)

Using the rules_cc toolchain

This repo contains an auto-detecting toolchain that expects to find tools installed on your host machine. This is non-hermetic, and may have varying behaviors depending on the versions of tools found.

There are third-party contributed hermetic toolchains you may want to investigate:

If you'd like to use the cc toolchain defined in this repo, add this to your WORKSPACE after you include rules_cc:

load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolchains")

rules_cc_dependencies()

rules_cc_toolchains()

Migration Tools

This repository also contains migration tools that can be used to migrate your project for Bazel incompatible changes.

Legacy fields migrator

Script that migrates legacy crosstool fields into features (incompatible flag, tracking issue).

TLDR:

bazel run @rules_cc//tools/migration:legacy_fields_migrator -- \
  --input=my_toolchain/CROSSTOOL \
  --inline

Contributing

Bazel and rules_cc are the work of many contributors. We appreciate your help!

To contribute, please read the contribution guidelines: CONTRIBUTING.md.

Note that the rules_cc use the GitHub issue tracker for bug reports and feature requests only. For asking questions see: