-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speed up build by avoiding build config duplication
Compile substantially all of workerd in the bazel 'target' configuration instead of 'exec', which allows us to avoid compiling major components twice. This should offer a large performance improvement, especially when rebuilding after a V8 update or building all targets and drive down the worst-case CI build time significantly. Bazel supports an exec configuration for building code that needs to run on the host machine during the build, e.g. tools used to generate source files or type definitions. When not cross-compiling exec and target will be the same, but bazel does not offer a flag to use just one configuration when the configurations are identical (bazelbuild/bazel#14848), making manual changes necessary. Bazel appears to offer no way to detect if exec and host are the same, so this feature is implemented through an opt-in command line flag enabled in .bazelrc, which makes it possible to easily disable the change when cross-compilation support is needed.
- Loading branch information
Showing
6 changed files
with
501 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Workaround for bazel not supporting a shared exec and target configuration, even when they are | ||
# identical. https://github.com/bazelbuild/bazel/issues/14848 | ||
# Derived from the tensorflow project (https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/api/generator/api_gen.bzl) | ||
# See https://github.com/tensorflow/tensorflow/issues/60167 for discussion | ||
|
||
def _run_binary_target_impl(ctx): | ||
tool = ctx.attr.tool[DefaultInfo].files_to_run.executable | ||
flags = [ ctx.expand_location(a) if "$(location" in a else a for a in ctx.attr.args ] | ||
|
||
cmd = " ".join([tool.path] + flags) | ||
ctx.actions.run_shell( | ||
inputs = ctx.files.srcs, | ||
outputs = ctx.outputs.outs, | ||
tools = [tool], | ||
use_default_shell_env = True, | ||
command = cmd, | ||
) | ||
|
||
run_binary_target = rule( | ||
implementation = _run_binary_target_impl, | ||
attrs = { | ||
"outs": attr.output_list(mandatory = True), | ||
"srcs": attr.label_list(allow_files = True), | ||
"args": attr.string_list(), | ||
# Conditionally set cfg based on use_cfg_target to support cross-platform build when needed | ||
"tool": attr.label( | ||
executable = True, | ||
# TODO: The select() statement works locally yet produces an error on CI. Investigate | ||
# what's causing this. | ||
cfg = "target", | ||
# cfg = select({ | ||
# "@//:use_cfg_target": "target", | ||
# "//conditions:default": "exec", | ||
# }), | ||
mandatory = True), | ||
}, | ||
) |
Oops, something went wrong.