-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to a
carbon_binary
rule with target config support. (#4076)
This switches from a macro that simply wraps genrules to a proper Starlark rule that runs first compile and then link actions. Most interestingly, this uses the rule structure to allow using the Carbon toolchain built either in the target config or the exec config. While the exec config is more principled and even necessary in a cross-compile situaiton, it is dramatically less efficient when developing Carbon as all the binaries and tests outside of our examples will be built with the target config. This triggers a complete second build of the toolchain in the exec config for examples before this PR. It is tempting to try to keep the exec config but make it not cause redundant actions, but the way Bazel sets up exec and target config makes it essentially impossible to share their artifacts. There used to be a hack in Bazel itself to force sharing but it was removed due to it violating the principled design. Instead, these rules are explicit about their intent to use the target config, much like a test would be. I have rigged up a flag that is carefully threaded through a wrapper macro with `select`s to allow easily switching to the exec configuration in case it is desired or needed. But the the `.bazelrc` sets the default to the target config. The `BUILD` file default is the principled `exec` in case these rules are used by importing into some other Bazel workspace where we might *only* need the exec config. The net outcome of this is shaving over 2500 actions off of a clean rebuild such as is triggered by a version bump to LLVM, including some of the very slow and expensive compiles of LLVM and Clang themselves. These would only be triggered if you built the examples so this may mostly impact our CI latency. --------- Co-authored-by: Jon Ross-Perkins <[email protected]>
- Loading branch information
Showing
3 changed files
with
129 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,24 @@ | ||
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM | ||
# Exceptions. See /LICENSE for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") | ||
|
||
# Flag controlling whether the target config is used for the `carbon_*` Bazel | ||
# rules. The default is to use the exec config as that is more correct in cases | ||
# where the target config is not compatible with the exec (cross compiling), and | ||
# for library users of Carbon likely the most efficient as it will provide an | ||
# optimized toolchain. | ||
# | ||
# However, for building the Carbon project itself, this will roughly double the | ||
# build cost by forcing a build in both target and exec config. As a consequence | ||
# we disable the flag in the `.bazelrc` of the project for its builds. | ||
bool_flag( | ||
name = "use_target_config_carbon_rules", | ||
build_setting_default = False, | ||
) | ||
|
||
config_setting( | ||
name = "use_target_config_carbon_rules_config", | ||
flag_values = {":use_target_config_carbon_rules": "True"}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters