Minimize the cost of Skyframe restarts during CC autoconfiguration.
Repository functions restart whenever they have to resolve a label due
to the way Skyframe currently works. This is problematic because such
functions are often costly: they try to detect features of the host
system by building and running tools, and they touch the file system.
To minimize the cost of these restarts, which are unavoidable, resolve
the paths to all necessary labels upfront. This way, while the restarts
still happen, they have no side-effects and thus are cheap. As a
side-effect of this work, remove the strange and undocumented "tpl"
function, which only made things more cryptic and harder to refactor.
This cuts down Bazel's own analysis time on macOS on my Mac Pro 2013
from 14 seconds to 6 seconds by trimming about 15 unnecessary rebuilds
and executions of the xcode-locator-bin tool to just 1. In other
words: one fewer awkward pause during analysis time.
Additionally, there is the hope that this will fix the problems users
observe where Bazel writes persistent garbage during autoconfiguration
(needing "clean --expunge" to recover) when Visual Studio Code is
running and Santa is enabled on macOS; see
https://github.com/bazelbuild/bazel/issues/4603. This is most likely
a bug in Santa (see https://github.com/google/santa/issues/260) but
we were tickling it due to our apparently-abusive behavior of building,
executing, and then removing the same thing over and over again.
Fixes https://github.com/bazelbuild/bazel/issues/5196 and should also
fix https://github.com/bazelbuild/bazel/issues/4603.
RELNOTES: None.
PiperOrigin-RevId: 198434395
diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl
index 037860c..01736aa 100644
--- a/tools/cpp/cc_configure.bzl
+++ b/tools/cpp/cc_configure.bzl
@@ -16,11 +16,21 @@
load("@bazel_tools//tools/cpp:windows_cc_configure.bzl", "configure_windows_toolchain")
load("@bazel_tools//tools/cpp:osx_cc_configure.bzl", "configure_osx_toolchain")
load("@bazel_tools//tools/cpp:unix_cc_configure.bzl", "configure_unix_toolchain")
-load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value")
+load(
+ "@bazel_tools//tools/cpp:lib_cc_configure.bzl",
+ "get_cpu_value",
+ "resolve_labels",
+)
def cc_autoconf_impl(repository_ctx, overriden_tools = dict()):
+ paths = resolve_labels(repository_ctx, [
+ "@bazel_tools//tools/cpp:BUILD.static.freebsd",
+ "@bazel_tools//tools/cpp:CROSSTOOL",
+ "@bazel_tools//tools/cpp:dummy_toolchain.bzl",
+ ])
+
repository_ctx.symlink(
- Label("@bazel_tools//tools/cpp:dummy_toolchain.bzl"), "dummy_toolchain.bzl")
+ paths["@bazel_tools//tools/cpp:dummy_toolchain.bzl"], "dummy_toolchain.bzl")
env = repository_ctx.os.environ
cpu_value = get_cpu_value(repository_ctx)
if "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" in env and env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] == "1":
@@ -31,8 +41,8 @@
# autoconfigure this platform too. Theorically, FreeBSD should be
# straightforward to add but we cannot run it in a docker container so
# skipping until we have proper tests for FreeBSD.
- repository_ctx.symlink(Label("@bazel_tools//tools/cpp:CROSSTOOL"), "CROSSTOOL")
- repository_ctx.symlink(Label("@bazel_tools//tools/cpp:BUILD.static.freebsd"), "BUILD")
+ repository_ctx.symlink(paths["@bazel_tools//tools/cpp:CROSSTOOL"], "CROSSTOOL")
+ repository_ctx.symlink(paths["@bazel_tools//tools/cpp:BUILD.static.freebsd"], "BUILD")
elif cpu_value == "x64_windows":
# TODO(ibiryukov): overriden_tools are only supported in configure_unix_toolchain.
# We might want to add that to Windows too(at least for msys toolchain).
diff --git a/tools/cpp/lib_cc_configure.bzl b/tools/cpp/lib_cc_configure.bzl
index 6e43342..8999806 100644
--- a/tools/cpp/lib_cc_configure.bzl
+++ b/tools/cpp/lib_cc_configure.bzl
@@ -15,6 +15,30 @@
"""Base library for configuring the C++ toolchain."""
+def resolve_labels(repository_ctx, labels):
+ """Resolves a collection of labels to their paths.
+
+ Label resolution can cause the evaluation of Skylark functions to restart.
+ For functions with side-effects (like the auto-configuration functions, which
+ inspect the system and touch the file system), such restarts are costly.
+ We cannot avoid the restarts, but we can minimize their penalty by resolving
+ all labels upfront.
+
+ Among other things, doing less work on restarts can cut analysis times by
+ several seconds and may also prevent tickling kernel conditions that cause
+ build failures. See https://github.com/bazelbuild/bazel/issues/5196 for
+ more details.
+
+ Args:
+ repository_ctx: The context with which to resolve the labels.
+ labels: Labels to be resolved expressed as a list of strings.
+
+ Returns:
+ A dictionary with the labels as keys and their paths as values.
+ """
+ return dict([(label, repository_ctx.path(Label(label))) for label in labels])
+
+
def escape_string(arg):
"""Escape percent sign (%) in the string so it can appear in the Crosstool."""
if arg != None:
@@ -22,6 +46,7 @@
else:
return None
+
def split_escaped(string, delimiter):
"""Split string on the delimiter unless %-escaped.
@@ -39,11 +64,12 @@
split_escaped("a::b", ":") -> [ "a", "", "", "b" ]
Args:
- string: a string to be splitted
- delimiter: non-empty string not containing %-sign to be used as a delimiter
+ string: The string to be split.
+ delimiter: Non-empty string not containing %-sign to be used as a
+ delimiter.
Returns:
- a list of substrings
+ A list of substrings.
"""
if delimiter == "": fail("Delimiter cannot be empty")
if delimiter.find("%") != -1: fail("Delimiter cannot contain %-sign")
@@ -162,15 +188,6 @@
return "k8" if result.stdout.strip() in ["amd64", "x86_64", "x64"] else "piii"
-def tpl(repository_ctx, template, substitutions={}, out=None):
- if not out:
- out = template
- repository_ctx.template(
- out,
- Label("@bazel_tools//tools/cpp:%s.tpl" % template),
- substitutions)
-
-
def is_cc_configure_debug(repository_ctx):
"""Returns True if CC_CONFIGURE_DEBUG is set to 1."""
env = repository_ctx.os.environ
diff --git a/tools/cpp/osx_cc_configure.bzl b/tools/cpp/osx_cc_configure.bzl
index 48d5681..6787141 100644
--- a/tools/cpp/osx_cc_configure.bzl
+++ b/tools/cpp/osx_cc_configure.bzl
@@ -19,12 +19,12 @@
load(
"@bazel_tools//tools/cpp:lib_cc_configure.bzl",
"escape_string",
+ "resolve_labels",
)
load(
"@bazel_tools//tools/cpp:unix_cc_configure.bzl",
"get_escaped_cxx_inc_directories",
- "tpl",
"get_env",
"find_cc",
"configure_unix_toolchain"
@@ -52,35 +52,53 @@
def configure_osx_toolchain(repository_ctx, overriden_tools):
"""Configure C++ toolchain on macOS."""
+ paths = resolve_labels(repository_ctx, [
+ "@bazel_tools//tools/cpp:osx_cc_wrapper.sh.tpl",
+ "@bazel_tools//tools/objc:libtool.sh",
+ "@bazel_tools//tools/objc:make_hashed_objlist.py",
+ "@bazel_tools//tools/objc:xcrunwrapper.sh",
+ "@bazel_tools//tools/osx/crosstool:BUILD.tpl",
+ "@bazel_tools//tools/osx/crosstool:CROSSTOOL.tpl",
+ "@bazel_tools//tools/osx/crosstool:osx_archs.bzl",
+ "@bazel_tools//tools/osx/crosstool:wrapped_ar.tpl",
+ "@bazel_tools//tools/osx/crosstool:wrapped_clang.cc",
+ "@bazel_tools//tools/osx/crosstool:wrapped_clang.tpl",
+ "@bazel_tools//tools/osx/crosstool:wrapped_clang_pp.tpl",
+ "@bazel_tools//tools/osx:xcode_locator.m",
+ ])
+
xcode_toolchains = []
(xcode_toolchains, xcodeloc_err) = run_xcode_locator(
repository_ctx,
- Label("@bazel_tools//tools/osx:xcode_locator.m"))
+ paths["@bazel_tools//tools/osx:xcode_locator.m"])
if xcode_toolchains:
cc = find_cc(repository_ctx, overriden_tools = {})
- tpl(repository_ctx, "osx_cc_wrapper.sh", {
- "%{cc}": escape_string(str(cc)),
- "%{env}": escape_string(get_env(repository_ctx))
- }, "cc_wrapper.sh")
+ repository_ctx.template(
+ "cc_wrapper.sh",
+ paths["@bazel_tools//tools/cpp:osx_cc_wrapper.sh.tpl"],
+ {
+ "%{cc}": escape_string(str(cc)),
+ "%{env}": escape_string(get_env(repository_ctx)),
+ })
repository_ctx.symlink(
- Label("@bazel_tools//tools/objc:xcrunwrapper.sh"), "xcrunwrapper.sh")
+ paths["@bazel_tools//tools/objc:xcrunwrapper.sh"], "xcrunwrapper.sh")
repository_ctx.symlink(
- Label("@bazel_tools//tools/objc:libtool.sh"), "libtool")
+ paths["@bazel_tools//tools/objc:libtool.sh"], "libtool")
repository_ctx.symlink(
- Label("@bazel_tools//tools/objc:make_hashed_objlist.py"),
+ paths["@bazel_tools//tools/objc:make_hashed_objlist.py"],
"make_hashed_objlist.py")
repository_ctx.symlink(
- Label("@bazel_tools//tools/osx/crosstool:wrapped_ar.tpl"),
+ paths["@bazel_tools//tools/osx/crosstool:wrapped_ar.tpl"],
"wrapped_ar")
repository_ctx.symlink(
- Label("@bazel_tools//tools/osx/crosstool:BUILD.tpl"),
+ paths["@bazel_tools//tools/osx/crosstool:BUILD.tpl"],
"BUILD")
repository_ctx.symlink(
- Label("@bazel_tools//tools/osx/crosstool:osx_archs.bzl"),
+ paths["@bazel_tools//tools/osx/crosstool:osx_archs.bzl"],
"osx_archs.bzl")
wrapped_clang_src_path = str(repository_ctx.path(
- Label("@bazel_tools//tools/osx/crosstool:wrapped_clang.cc")))
+ paths["@bazel_tools//tools/osx/crosstool:wrapped_clang.cc"]))
xcrun_result = repository_ctx.execute(["env", "-i", "xcrun", "clang", "-std=c++11", "-lc++",
"-o", "wrapped_clang", wrapped_clang_src_path], 30)
if (xcrun_result.return_code == 0):
@@ -101,10 +119,10 @@
"https://github.com/bazelbuild/bazel/issues with the following:\n" +
error_msg)
repository_ctx.symlink(
- Label("@bazel_tools//tools/osx/crosstool:wrapped_clang.tpl"),
+ paths["@bazel_tools//tools/osx/crosstool:wrapped_clang.tpl"],
"wrapped_clang")
repository_ctx.symlink(
- Label("@bazel_tools//tools/osx/crosstool:wrapped_clang_pp.tpl"),
+ paths["@bazel_tools//tools/osx/crosstool:wrapped_clang_pp.tpl"],
"wrapped_clang_pp")
escaped_include_paths = _get_escaped_xcode_cxx_inc_directories(repository_ctx, cc, xcode_toolchains)
@@ -115,7 +133,7 @@
escaped_cxx_include_directories.append("# Error: " + xcodeloc_err + "\n")
repository_ctx.template(
"CROSSTOOL",
- Label("@bazel_tools//tools/osx/crosstool:CROSSTOOL.tpl"),
+ paths["@bazel_tools//tools/osx/crosstool:CROSSTOOL.tpl"],
{"%{cxx_builtin_include_directory}": "\n".join(escaped_cxx_include_directories)})
else:
configure_unix_toolchain(repository_ctx, cpu_value = "darwin", overriden_tools = overriden_tools)
diff --git a/tools/cpp/unix_cc_configure.bzl b/tools/cpp/unix_cc_configure.bzl
index b53346e..d4b25c8 100644
--- a/tools/cpp/unix_cc_configure.bzl
+++ b/tools/cpp/unix_cc_configure.bzl
@@ -21,9 +21,9 @@
"auto_configure_fail",
"escape_string",
"get_env_var",
+ "resolve_labels",
"split_escaped",
"which",
- "tpl",
)
def _uniq(iterable):
@@ -423,6 +423,13 @@
def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
"""Configure C++ toolchain on Unix platforms."""
+ paths = resolve_labels(repository_ctx, [
+ "@bazel_tools//tools/cpp:BUILD.tpl",
+ "@bazel_tools//tools/cpp:CROSSTOOL.tpl",
+ "@bazel_tools//tools/cpp:linux_cc_wrapper.sh.tpl",
+ "@bazel_tools//tools/cpp:osx_cc_wrapper.sh.tpl",
+ ])
+
repository_ctx.file("tools/cpp/empty.cc", "int main() {}")
darwin = cpu_value == "darwin"
@@ -439,42 +446,57 @@
crosstool_content = _crosstool_content(repository_ctx, cc, cpu_value, darwin)
opt_content = _opt_content(darwin)
dbg_content = _dbg_content()
- tpl(repository_ctx, "BUILD", {
- "%{name}": cpu_value,
- "%{supports_param_files}": "0" if darwin else "1",
- "%{cc_compiler_deps}": ":cc_wrapper" if darwin else ":empty",
- "%{compiler}": get_env_var(repository_ctx, "BAZEL_COMPILER", "compiler", False),
- })
- tpl(repository_ctx,
- "osx_cc_wrapper.sh" if darwin else "linux_cc_wrapper.sh",
- {"%{cc}": escape_string(str(cc)),
- "%{env}": escape_string(get_env(repository_ctx))},
- "cc_wrapper.sh")
- tpl(repository_ctx, "CROSSTOOL", {
- "%{cpu}": escape_string(cpu_value),
- "%{default_toolchain_name}": escape_string(
- get_env_var(repository_ctx,
- "CC_TOOLCHAIN_NAME",
- "local",
- False)),
- "%{toolchain_name}": escape_string(
- get_env_var(repository_ctx, "CC_TOOLCHAIN_NAME", "local", False)),
- "%{content}": _build_crosstool(crosstool_content) + "\n" +
- _build_tool_path(tool_paths),
- "%{opt_content}": _build_crosstool(opt_content, " "),
- "%{dbg_content}": _build_crosstool(dbg_content, " "),
- "%{cxx_builtin_include_directory}": "",
- "%{coverage}": _coverage_feature(repository_ctx, darwin),
- "%{msvc_env_tmp}": "",
- "%{msvc_env_path}": "",
- "%{msvc_env_include}": "",
- "%{msvc_env_lib}": "",
- "%{msvc_cl_path}": "",
- "%{msvc_ml_path}": "",
- "%{msvc_link_path}": "",
- "%{msvc_lib_path}": "",
- "%{msys_x64_mingw_content}": "",
- "%{dbg_mode_debug}": "",
- "%{fastbuild_mode_debug}": "",
- "%{compilation_mode_content}": "",
- })
+
+ repository_ctx.template(
+ "BUILD",
+ paths["@bazel_tools//tools/cpp:BUILD.tpl"],
+ {
+ "%{name}": cpu_value,
+ "%{supports_param_files}": "0" if darwin else "1",
+ "%{cc_compiler_deps}": ":cc_wrapper" if darwin else ":empty",
+ "%{compiler}": get_env_var(
+ repository_ctx, "BAZEL_COMPILER", "compiler", False),
+ })
+
+ cc_wrapper_src = (
+ "@bazel_tools//tools/cpp:osx_cc_wrapper.sh.tpl"
+ if darwin else "@bazel_tools//tools/cpp:linux_cc_wrapper.sh.tpl")
+ repository_ctx.template(
+ "cc_wrapper.sh",
+ paths[cc_wrapper_src],
+ {
+ "%{cc}": escape_string(str(cc)),
+ "%{env}": escape_string(get_env(repository_ctx)),
+ })
+
+ repository_ctx.template(
+ "CROSSTOOL",
+ paths["@bazel_tools//tools/cpp:CROSSTOOL.tpl"],
+ {
+ "%{cpu}": escape_string(cpu_value),
+ "%{default_toolchain_name}": escape_string(
+ get_env_var(repository_ctx,
+ "CC_TOOLCHAIN_NAME",
+ "local",
+ False)),
+ "%{toolchain_name}": escape_string(
+ get_env_var(repository_ctx, "CC_TOOLCHAIN_NAME", "local", False)),
+ "%{content}": _build_crosstool(crosstool_content) + "\n" +
+ _build_tool_path(tool_paths),
+ "%{opt_content}": _build_crosstool(opt_content, " "),
+ "%{dbg_content}": _build_crosstool(dbg_content, " "),
+ "%{cxx_builtin_include_directory}": "",
+ "%{coverage}": _coverage_feature(repository_ctx, darwin),
+ "%{msvc_env_tmp}": "",
+ "%{msvc_env_path}": "",
+ "%{msvc_env_include}": "",
+ "%{msvc_env_lib}": "",
+ "%{msvc_cl_path}": "",
+ "%{msvc_ml_path}": "",
+ "%{msvc_link_path}": "",
+ "%{msvc_lib_path}": "",
+ "%{msys_x64_mingw_content}": "",
+ "%{dbg_mode_debug}": "",
+ "%{fastbuild_mode_debug}": "",
+ "%{compilation_mode_content}": "",
+ })
diff --git a/tools/cpp/windows_cc_configure.bzl b/tools/cpp/windows_cc_configure.bzl
index a22cca1..8c32102 100644
--- a/tools/cpp/windows_cc_configure.bzl
+++ b/tools/cpp/windows_cc_configure.bzl
@@ -23,8 +23,8 @@
"which",
"which_cmd",
"execute",
- "tpl",
"is_cc_configure_debug",
+ "resolve_labels",
)
def _get_escaped_windows_msys_crosstool_content(repository_ctx, use_mingw = False):
@@ -294,49 +294,66 @@
def configure_windows_toolchain(repository_ctx):
"""Configure C++ toolchain on Windows."""
- repository_ctx.symlink(Label("@bazel_tools//tools/cpp:BUILD.static.windows"), "BUILD")
+ paths = resolve_labels(repository_ctx, [
+ "@bazel_tools//tools/cpp:BUILD.static.windows",
+ "@bazel_tools//tools/cpp:CROSSTOOL",
+ "@bazel_tools//tools/cpp:CROSSTOOL.tpl",
+ "@bazel_tools//tools/cpp:vc_installation_error.bat.tpl",
+ "@bazel_tools//tools/cpp:wrapper/bin/call_python.bat.tpl",
+ "@bazel_tools//tools/cpp:wrapper/bin/pydir/msvc_tools.py.tpl",
+ ])
+
+ repository_ctx.symlink(paths["@bazel_tools//tools/cpp:BUILD.static.windows"], "BUILD")
vc_path = find_vc_path(repository_ctx)
missing_tools = None
- vc_installation_error_script = "vc_installation_error.bat"
if not vc_path:
- tpl(repository_ctx, vc_installation_error_script, {"%{vc_error_message}" : ""})
+ repository_ctx.template(
+ "vc_installation_error.bat",
+ paths["@bazel_tools//tools/cpp:vc_installation_error.bat.tpl"],
+ {"%{vc_error_message}": ""})
else:
missing_tools = _find_missing_vc_tools(repository_ctx, vc_path)
if missing_tools:
- tpl(repository_ctx, vc_installation_error_script, {
- "%{vc_error_message}" : "\r\n".join([
+ message = "\r\n".join([
"echo. 1>&2",
"echo Visual C++ build tools seems to be installed at %s 1>&2" % vc_path,
"echo But Bazel can't find the following tools: 1>&2",
"echo %s 1>&2" % ", ".join(missing_tools),
"echo. 1>&2",
- ])})
+ ])
+ repository_ctx.template(
+ "vc_installation_error.bat",
+ paths["@bazel_tools//tools/cpp:vc_installation_error.bat.tpl"],
+ {"%{vc_error_message}": message})
if not vc_path or missing_tools:
- tpl(repository_ctx, "CROSSTOOL", {
- "%{cpu}": "x64_windows",
- "%{default_toolchain_name}": "msvc_x64",
- "%{toolchain_name}": "msys_x64",
- "%{msvc_env_tmp}": "",
- "%{msvc_env_path}": "",
- "%{msvc_env_include}": "",
- "%{msvc_env_lib}": "",
- "%{msvc_cl_path}": vc_installation_error_script,
- "%{msvc_ml_path}": vc_installation_error_script,
- "%{msvc_link_path}": vc_installation_error_script,
- "%{msvc_lib_path}": vc_installation_error_script,
- "%{dbg_mode_debug}": "/DEBUG",
- "%{fastbuild_mode_debug}": "/DEBUG",
- "%{compilation_mode_content}": "",
- "%{content}": _get_escaped_windows_msys_crosstool_content(repository_ctx),
- "%{msys_x64_mingw_content}": _get_escaped_windows_msys_crosstool_content(repository_ctx, use_mingw = True),
- "%{opt_content}": "",
- "%{dbg_content}": "",
- "%{link_content}": "",
- "%{cxx_builtin_include_directory}": "",
- "%{coverage}": "",
- })
+ repository_ctx.template(
+ "CROSSTOOL",
+ paths["@bazel_tools//tools/cpp:CROSSTOOL.tpl"],
+ {
+ "%{cpu}": "x64_windows",
+ "%{default_toolchain_name}": "msvc_x64",
+ "%{toolchain_name}": "msys_x64",
+ "%{msvc_env_tmp}": "",
+ "%{msvc_env_path}": "",
+ "%{msvc_env_include}": "",
+ "%{msvc_env_lib}": "",
+ "%{msvc_cl_path}": "vc_installation_error.bat",
+ "%{msvc_ml_path}": "vc_installation_error.bat",
+ "%{msvc_link_path}": "vc_installation_error.bat",
+ "%{msvc_lib_path}": "vc_installation_error.bat",
+ "%{dbg_mode_debug}": "/DEBUG",
+ "%{fastbuild_mode_debug}": "/DEBUG",
+ "%{compilation_mode_content}": "",
+ "%{content}": _get_escaped_windows_msys_crosstool_content(repository_ctx),
+ "%{msys_x64_mingw_content}": _get_escaped_windows_msys_crosstool_content(repository_ctx, use_mingw = True),
+ "%{opt_content}": "",
+ "%{dbg_content}": "",
+ "%{link_content}": "",
+ "%{cxx_builtin_include_directory}": "",
+ "%{coverage}": "",
+ })
return
env = setup_vc_env_vars(repository_ctx, vc_path)
@@ -363,24 +380,32 @@
if cuda_path:
escaped_paths = escape_string(cuda_path.replace("\\", "\\\\") + "/bin;") + escaped_paths
escaped_compute_capabilities = _escaped_cuda_compute_capabilities(repository_ctx)
- tpl(repository_ctx, "wrapper/bin/pydir/msvc_tools.py", {
- "%{lib_tool}": escape_string(msvc_lib_path),
- "%{support_whole_archive}": support_whole_archive,
- "%{cuda_compute_capabilities}": ", ".join(
- ["\"%s\"" % c for c in escaped_compute_capabilities]),
- "%{nvcc_tmp_dir_name}": nvcc_tmp_dir_name,
- })
+ repository_ctx.template(
+ "wrapper/bin/pydir/msvc_tools.py",
+ paths["@bazel_tools//tools/cpp:wrapper/bin/pydir/msvc_tools.py.tpl"],
+ {
+ "%{lib_tool}": escape_string(msvc_lib_path),
+ "%{support_whole_archive}": support_whole_archive,
+ "%{cuda_compute_capabilities}": ", ".join(
+ ["\"%s\"" % c for c in escaped_compute_capabilities]),
+ "%{nvcc_tmp_dir_name}": nvcc_tmp_dir_name,
+ })
# nvcc will generate some source files under %{nvcc_tmp_dir_name}
# The generated files are guranteed to have unique name, so they can share the same tmp directory
escaped_cxx_include_directories += [ "cxx_builtin_include_directory: \"%s\"" % nvcc_tmp_dir_name ]
- msvc_wrapper = repository_ctx.path(Label("@bazel_tools//tools/cpp:CROSSTOOL")).dirname.get_child("wrapper").get_child("bin")
+ msvc_wrapper = repository_ctx.path(
+ paths["@bazel_tools//tools/cpp:CROSSTOOL"]).dirname.get_child(
+ "wrapper").get_child("bin")
for f in ["msvc_cl.bat", "msvc_link.bat", "msvc_nop.bat"]:
repository_ctx.symlink(msvc_wrapper.get_child(f), "wrapper/bin/" + f)
msvc_wrapper = msvc_wrapper.get_child("pydir")
for f in ["msvc_cl.py", "msvc_link.py"]:
repository_ctx.symlink(msvc_wrapper.get_child(f), "wrapper/bin/pydir/" + f)
python_binary = _find_python(repository_ctx)
- tpl(repository_ctx, "wrapper/bin/call_python.bat", {"%{python_binary}": escape_string(python_binary)})
+ repository_ctx.template(
+ "wrapper/bin/call_python.bat",
+ paths["@bazel_tools//tools/cpp:wrapper/bin/call_python.bat.tpl"],
+ {"%{python_binary}": escape_string(python_binary)})
msvc_cl_path = "wrapper/bin/msvc_cl.bat"
msvc_link_path = "wrapper/bin/msvc_link.bat"
msvc_lib_path = "wrapper/bin/msvc_link.bat"
@@ -392,26 +417,29 @@
support_debug_fastlink = _is_support_debug_fastlink(repository_ctx, vc_path)
- tpl(repository_ctx, "CROSSTOOL", {
- "%{cpu}": "x64_windows",
- "%{default_toolchain_name}": "msvc_x64",
- "%{toolchain_name}": "msys_x64",
- "%{msvc_env_tmp}": escaped_tmp_dir,
- "%{msvc_env_path}": escaped_paths,
- "%{msvc_env_include}": escaped_include_paths,
- "%{msvc_env_lib}": escaped_lib_paths,
- "%{msvc_cl_path}": msvc_cl_path,
- "%{msvc_ml_path}": msvc_ml_path,
- "%{msvc_link_path}": msvc_link_path,
- "%{msvc_lib_path}": msvc_lib_path,
- "%{dbg_mode_debug}": "/DEBUG:FULL" if support_debug_fastlink else "/DEBUG",
- "%{fastbuild_mode_debug}": "/DEBUG:FASTLINK" if support_debug_fastlink else "/DEBUG",
- "%{compilation_mode_content}": compilation_mode_content,
- "%{content}": _get_escaped_windows_msys_crosstool_content(repository_ctx),
- "%{msys_x64_mingw_content}": _get_escaped_windows_msys_crosstool_content(repository_ctx, use_mingw = True),
- "%{opt_content}": "",
- "%{dbg_content}": "",
- "%{link_content}": "",
- "%{cxx_builtin_include_directory}": "\n".join(escaped_cxx_include_directories),
- "%{coverage}": "",
- })
+ repository_ctx.template(
+ "CROSSTOOL",
+ paths["@bazel_tools//tools/cpp:CROSSTOOL.tpl"],
+ {
+ "%{cpu}": "x64_windows",
+ "%{default_toolchain_name}": "msvc_x64",
+ "%{toolchain_name}": "msys_x64",
+ "%{msvc_env_tmp}": escaped_tmp_dir,
+ "%{msvc_env_path}": escaped_paths,
+ "%{msvc_env_include}": escaped_include_paths,
+ "%{msvc_env_lib}": escaped_lib_paths,
+ "%{msvc_cl_path}": msvc_cl_path,
+ "%{msvc_ml_path}": msvc_ml_path,
+ "%{msvc_link_path}": msvc_link_path,
+ "%{msvc_lib_path}": msvc_lib_path,
+ "%{dbg_mode_debug}": "/DEBUG:FULL" if support_debug_fastlink else "/DEBUG",
+ "%{fastbuild_mode_debug}": "/DEBUG:FASTLINK" if support_debug_fastlink else "/DEBUG",
+ "%{compilation_mode_content}": compilation_mode_content,
+ "%{content}": _get_escaped_windows_msys_crosstool_content(repository_ctx),
+ "%{msys_x64_mingw_content}": _get_escaped_windows_msys_crosstool_content(repository_ctx, use_mingw = True),
+ "%{opt_content}": "",
+ "%{dbg_content}": "",
+ "%{link_content}": "",
+ "%{cxx_builtin_include_directory}": "\n".join(escaped_cxx_include_directories),
+ "%{coverage}": "",
+ })