From 859bd659df647824ccaaf3d1e3ffc8b8c2729905 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Thu, 16 May 2024 11:40:56 +0200 Subject: [PATCH] Restructure to avoid WORKSPACE loads --- MODULE.bazel | 2 +- crosstool/apple_cc_configure_extension.bzl | 10 ++++++++++ crosstool/setup.bzl | 15 ++++----------- 3 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 crosstool/apple_cc_configure_extension.bzl diff --git a/MODULE.bazel b/MODULE.bazel index 1f5334d..b4ed672 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -17,7 +17,7 @@ bazel_dep( repo_name = "io_bazel_stardoc", ) -apple_cc_configure = use_extension("//crosstool:setup.bzl", "apple_cc_configure_extension") +apple_cc_configure = use_extension("//crosstool:apple_cc_configure_extension.bzl", "apple_cc_configure_extension") use_repo(apple_cc_configure, "local_config_apple_cc", "local_config_apple_cc_toolchains") register_toolchains("@local_config_apple_cc_toolchains//:all") diff --git a/crosstool/apple_cc_configure_extension.bzl b/crosstool/apple_cc_configure_extension.bzl new file mode 100644 index 0000000..8caeace --- /dev/null +++ b/crosstool/apple_cc_configure_extension.bzl @@ -0,0 +1,10 @@ +"""Extension configuring the C++ toolchain on macOS.""" + +load("@bazel_skylib//lib:modules.bzl", "modules") +load(":setup.bzl", "apple_cc_autoconf", "apple_cc_autoconf_toolchains") + +def _apple_cc_configure_extension_impl(): + apple_cc_autoconf_toolchains(name = "local_config_apple_cc_toolchains") + apple_cc_autoconf(name = "local_config_apple_cc") + +apple_cc_configure_extension = modules.as_extension(_apple_cc_configure_extension_impl) diff --git a/crosstool/setup.bzl b/crosstool/setup.bzl index 51ddeef..4c5f4ed 100644 --- a/crosstool/setup.bzl +++ b/crosstool/setup.bzl @@ -1,6 +1,5 @@ """Configure the Apple CC toolchain""" -load("@bazel_skylib//lib:modules.bzl", "modules") load("//crosstool:osx_cc_configure.bzl", "configure_osx_toolchain") _DISABLE_ENV_VAR = "BAZEL_NO_APPLE_CPP_TOOLCHAIN" @@ -28,7 +27,7 @@ def _apple_cc_autoconf_toolchains_impl(repository_ctx): else: repository_ctx.file("BUILD", "# Apple CC toolchain autoconfiguration was disabled because you're not running on macOS") -_apple_cc_autoconf_toolchains = repository_rule( +apple_cc_autoconf_toolchains = repository_rule( environ = [ _DISABLE_ENV_VAR, _OLD_DISABLE_ENV_VAR, @@ -53,7 +52,7 @@ def _apple_cc_autoconf_impl(repository_ctx): else: repository_ctx.file("BUILD", "# Apple CC autoconfiguration was disabled because you're not on macOS") -_apple_cc_autoconf = repository_rule( +apple_cc_autoconf = repository_rule( environ = [ _DISABLE_ENV_VAR, _OLD_DISABLE_ENV_VAR, @@ -71,15 +70,9 @@ _apple_cc_autoconf = repository_rule( # buildifier: disable=unnamed-macro def apple_cc_configure(): - _apple_cc_autoconf_toolchains(name = "local_config_apple_cc_toolchains") - _apple_cc_autoconf(name = "local_config_apple_cc") + apple_cc_autoconf_toolchains(name = "local_config_apple_cc_toolchains") + apple_cc_autoconf(name = "local_config_apple_cc") native.register_toolchains( # Use register_toolchain's target pattern expansion to register all toolchains in the package. "@local_config_apple_cc_toolchains//:all", ) - -def _apple_cc_configure_extension_impl(): - _apple_cc_autoconf_toolchains(name = "local_config_apple_cc_toolchains") - _apple_cc_autoconf(name = "local_config_apple_cc") - -apple_cc_configure_extension = modules.as_extension(_apple_cc_configure_extension_impl)