Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions cc/private/toolchain/cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ load(
load(":unix_cc_configure.bzl", "configure_unix_toolchain")
load(":windows_cc_configure.bzl", "configure_windows_toolchain")

def _should_disable_toolchain(repository_ctx):
"""Returns true if the toolchain should be disabled based on environment variables."""
env = repository_ctx.os.environ
disabled_via_env = "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" in env and env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] == "1"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this is easier to read if you do early returns

    if "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" in env and env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] == "1":
        return True
    macos_legacy_support = env.get("BAZEL_USE_LEGACY_MACOS_TOOLCHAIN", "1") == "1"
    if repository_ctx.os.name.startswith("mac os") and not macos_legacy_support:
        return True
    return False

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed in #755

macos_legacy_support = env.get("BAZEL_USE_LEGACY_MACOS_TOOLCHAIN", "1") == "1"
return disabled_via_env or (repository_ctx.os.name.startswith("mac os") and not macos_legacy_support)

def cc_autoconf_toolchains_impl(repository_ctx):
"""Generate BUILD file with 'toolchain' targets for the local host C++ toolchain.

Args:
repository_ctx: repository context
"""
env = repository_ctx.os.environ

# Should we try to find C++ toolchain at all? If not, we don't have to generate toolchains for C++ at all.
should_detect_cpp_toolchain = "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" not in env or env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] != "1"

if should_detect_cpp_toolchain:
if not _should_disable_toolchain(repository_ctx):
if repository_ctx.os.name.lower().find("windows") != -1:
build_path = "@rules_cc//cc/private/toolchain:BUILD.windows_toolchains.tpl"
else:
Expand All @@ -47,11 +49,12 @@ def cc_autoconf_toolchains_impl(repository_ctx):
{"%{name}": get_cpu_value(repository_ctx)},
)
else:
repository_ctx.file("BUILD", "# C++ toolchain autoconfiguration was disabled by BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN env variable.")
repository_ctx.file("BUILD", "# C++ toolchain autoconfiguration was disabled by BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 or BAZEL_USE_LEGACY_MACOS_TOOLCHAIN=0.")

cc_autoconf_toolchains = repository_rule(
environ = [
"BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN",
"BAZEL_USE_LEGACY_MACOS_TOOLCHAIN",
],
implementation = cc_autoconf_toolchains_impl,
configure = True,
Expand All @@ -64,10 +67,8 @@ def cc_autoconf_impl(repository_ctx, overriden_tools = dict()):
repository_ctx: repository context
overriden_tools: dict of tool paths to use instead of autoconfigured tools
"""

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":
if _should_disable_toolchain(repository_ctx):
paths = resolve_labels(repository_ctx, [
"@rules_cc//cc/private/toolchain:BUILD.empty.tpl",
"@rules_cc//cc/private/toolchain:empty_cc_toolchain_config.bzl",
Expand Down Expand Up @@ -130,6 +131,7 @@ cc_autoconf = repository_rule(
"BAZEL_TARGET_LIBC",
"BAZEL_TARGET_SYSTEM",
"BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN",
"BAZEL_USE_LEGACY_MACOS_TOOLCHAIN",
"BAZEL_USE_LLVM_NATIVE_COVERAGE",
"BAZEL_WIN32_WINNT",
"BAZEL_LLVM",
Expand Down