Skip to content

Commit

Permalink
Add support for BAZEL_USE_CPP_ONLY_TOOLCHAIN (#313)
Browse files Browse the repository at this point in the history
This is the same as BAZEL_NO_APPLE_CPP_TOOLCHAIN but this is the bazel
6.x naming. I don't remember why we didn't support this but this should
easy the upgrade for people using this old var who are also pulling in
apple_support for some reason and cannot easily remove it.
  • Loading branch information
keith committed Mar 4, 2024
1 parent 55c7701 commit e219316
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions crosstool/setup.bzl
Expand Up @@ -3,6 +3,7 @@
load("//crosstool:osx_cc_configure.bzl", "configure_osx_toolchain")

_DISABLE_ENV_VAR = "BAZEL_NO_APPLE_CPP_TOOLCHAIN"
_OLD_DISABLE_ENV_VAR = "BAZEL_USE_CPP_ONLY_TOOLCHAIN"

def _apple_cc_autoconf_toolchains_impl(repository_ctx):
"""Generate BUILD file with 'toolchain' targets for the local host C++ toolchain.
Expand All @@ -12,9 +13,12 @@ def _apple_cc_autoconf_toolchains_impl(repository_ctx):
"""
env = repository_ctx.os.environ
should_disable = _DISABLE_ENV_VAR in env and env[_DISABLE_ENV_VAR] == "1"
old_should_disable = _OLD_DISABLE_ENV_VAR in env and env[_OLD_DISABLE_ENV_VAR] == "1"

if should_disable:
repository_ctx.file("BUILD", "# Apple CC toolchain autoconfiguration was disabled by {} env variable.".format(_DISABLE_ENV_VAR))
if should_disable or old_should_disable:
repository_ctx.file("BUILD", "# Apple CC toolchain autoconfiguration was disabled by {} env variable.".format(
_DISABLE_ENV_VAR if should_disable else _OLD_DISABLE_ENV_VAR,
))
elif repository_ctx.os.name.startswith("mac os"):
repository_ctx.symlink(
repository_ctx.path(Label("@build_bazel_apple_support//crosstool:BUILD.toolchains")),
Expand All @@ -24,17 +28,23 @@ def _apple_cc_autoconf_toolchains_impl(repository_ctx):
repository_ctx.file("BUILD", "# Apple CC toolchain autoconfiguration was disabled because you're not running on macOS")

_apple_cc_autoconf_toolchains = repository_rule(
environ = [_DISABLE_ENV_VAR],
environ = [
_DISABLE_ENV_VAR,
_OLD_DISABLE_ENV_VAR,
],
implementation = _apple_cc_autoconf_toolchains_impl,
configure = True,
)

def _apple_cc_autoconf_impl(repository_ctx):
env = repository_ctx.os.environ
should_disable = _DISABLE_ENV_VAR in env and env[_DISABLE_ENV_VAR] == "1"
old_should_disable = _OLD_DISABLE_ENV_VAR in env and env[_OLD_DISABLE_ENV_VAR] == "1"

if should_disable:
repository_ctx.file("BUILD", "# Apple CC autoconfiguration was disabled by {} env variable.".format(_DISABLE_ENV_VAR))
if should_disable or old_should_disable:
repository_ctx.file("BUILD", "# Apple CC autoconfiguration was disabled by {} env variable.".format(
_DISABLE_ENV_VAR if should_disable else _OLD_DISABLE_ENV_VAR,
))
elif repository_ctx.os.name.startswith("mac os"):
success, error = configure_osx_toolchain(repository_ctx)
if not success:
Expand All @@ -45,6 +55,7 @@ def _apple_cc_autoconf_impl(repository_ctx):
_apple_cc_autoconf = repository_rule(
environ = [
_DISABLE_ENV_VAR,
_OLD_DISABLE_ENV_VAR,
"BAZEL_ALLOW_NON_APPLICATIONS_XCODE", # Signals to configure_osx_toolchain that some Xcodes may live outside of /Applications and we need to probe further when detecting/configuring them.
"DEVELOPER_DIR", # Used for making sure we use the right Xcode for compiling toolchain binaries
"GCOV", # TODO: Remove this
Expand Down

0 comments on commit e219316

Please sign in to comment.