Skip to content

Commit

Permalink
Restructure to avoid WORKSPACE loads
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed May 16, 2024
1 parent e934702 commit 859bd65
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
10 changes: 10 additions & 0 deletions crosstool/apple_cc_configure_extension.bzl
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 4 additions & 11 deletions crosstool/setup.bzl
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)

0 comments on commit 859bd65

Please sign in to comment.