Skip to content

Commit

Permalink
Update toolchain registration
Browse files Browse the repository at this point in the history
  • Loading branch information
jsharpe committed Apr 21, 2024
1 parent bbb54a6 commit 289b9c6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
12 changes: 2 additions & 10 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "rules_python", version = "0.23.1")

# Dev dependencies
Expand All @@ -23,23 +23,15 @@ use_repo(python, "python_3_9")
tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools")
use_repo(
tools,
"cmake_3.23.2_toolchains",
"cmake_src",
"gettext_runtime",
"glib_dev",
"glib_src",
"gnumake_src",
"meson_src",
"ninja_1.12.0_toolchains",
"ninja_build_src",
"pkgconfig_src",
"rules_foreign_cc_framework_toolchains",
)

register_toolchains(
"@rules_foreign_cc_framework_toolchains//:all",
"@cmake_3.23.2_toolchains//:all",
"@ninja_1.12.0_toolchains//:all",
"@python_3_9//:all",
"@rules_foreign_cc//toolchains:all",
)
8 changes: 4 additions & 4 deletions examples/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use_repo(
"meson_src",
)

bazel_dep(name = "platforms", version = "0.0.6")
bazel_dep(name = "rules_swift", version = "1.6.0", repo_name = "build_bazel_rules_swift")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "rules_swift", version = "1.17.0", repo_name = "build_bazel_rules_swift")
bazel_dep(name = "rules_apple", version = "3.4.0", repo_name = "build_bazel_rules_apple")
bazel_dep(name = "apple_support", version = "1.12.0", repo_name = "build_bazel_apple_support")
bazel_dep(name = "rules_python", version = "0.23.0")
bazel_dep(name = "apple_support", version = "1.14.0", repo_name = "build_bazel_apple_support")
bazel_dep(name = "rules_python", version = "0.23.1")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
Expand Down
44 changes: 30 additions & 14 deletions foreign_cc/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Entry point for extensions used by bzlmod."""

load("//foreign_cc:repositories.bzl", "DEFAULT_CMAKE_VERSION", "DEFAULT_MAKE_VERSION", "DEFAULT_MESON_VERSION", "DEFAULT_NINJA_VERSION", "DEFAULT_PKGCONFIG_VERSION", "rules_foreign_cc_dependencies")
load("//toolchains:built_toolchains.bzl", "make_toolchain", "meson_toolchain", "pkgconfig_toolchain")
load("//foreign_cc/private/framework:toolchain.bzl", "register_framework_toolchains")
load("//toolchains:built_toolchains.bzl", cmake_toolchains_src = "cmake_toolchain", "make_toolchain", "meson_toolchain", "pkgconfig_toolchain", ninja_toolchains_src = "ninja_toolchain")
load("//toolchains:prebuilt_toolchains.bzl", "cmake_toolchains", "ninja_toolchains")

cmake_toolchain_version = tag_class(attrs = {
Expand All @@ -25,36 +26,51 @@ pkgconfig_toolchain_version = tag_class(attrs = {
})

def _init(module_ctx):
cmake_registered = False
make_registered = False
meson_registered = False
ninja_registered = False
pkgconfig_registered = False

for mod in module_ctx.modules:
if mod.is_root:
for toolchain in mod.tags.cmake:
cmake_toolchains_src(toolchain.version, register_toolchains = False)
cmake_toolchains(toolchain.version, register_toolchains = False)
cmake_registered = True

for toolchain in mod.tags.make:
make_toolchain(toolchain.version, register_toolchains = False)
make_registered = True

for toolchain in mod.tags.meson:
meson_toolchain(toolchain.version, register_toolchains = False)
meson_registered = True

for toolchain in mod.tags.ninja:
ninja_toolchains(toolchain.version, register_toolchains = False)
ninja_toolchains_src(toolchain.version, register_toolchains = False)
ninja_registered = True

for toolchain in mod.tags.pkgconfig:
pkgconfig_toolchain(toolchain.version, register_toolchains = False)
pkgconfig_registered = True

if not cmake_registered:
cmake_toolchains_src(DEFAULT_CMAKE_VERSION, register_toolchains = False)
cmake_toolchains(DEFAULT_CMAKE_VERSION, register_toolchains = False)
if not make_registered:
make_toolchain(DEFAULT_MAKE_VERSION, register_toolchains = False)
if not meson_registered:
meson_toolchain(DEFAULT_MESON_VERSION, register_toolchains = False)
if not ninja_registered:
ninja_toolchains(DEFAULT_NINJA_VERSION, register_toolchains = False)
ninja_toolchains_src(DEFAULT_NINJA_VERSION, register_toolchains = False)
if not pkgconfig_registered:
pkgconfig_toolchain(DEFAULT_PKGCONFIG_VERSION, register_toolchains = False)

register_framework_toolchains(register_toolchains = False)

cmake_toolchains(DEFAULT_CMAKE_VERSION, register_toolchains = False)
make_toolchain(DEFAULT_MAKE_VERSION, register_toolchains = False)
meson_toolchain(DEFAULT_MESON_VERSION, register_toolchains = False)
ninja_toolchains(DEFAULT_NINJA_VERSION, register_toolchains = False)
pkgconfig_toolchain(DEFAULT_PKGCONFIG_VERSION, register_toolchains = False)

rules_foreign_cc_dependencies(
register_toolchains = False,
register_built_tools = True,
register_default_tools = False,
register_preinstalled_tools = False,
register_built_pkgconfig_toolchain = False,
)

tools = module_extension(
implementation = _init,
Expand Down
8 changes: 4 additions & 4 deletions toolchains/built_toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def built_toolchains(cmake_version, make_version, ninja_version, meson_version,
register_built_pkgconfig_toolchain: If true, the built pkgconfig toolchain will be registered.
"""
_cmake_toolchain(cmake_version, register_toolchains)
cmake_toolchain(cmake_version, register_toolchains)
make_toolchain(make_version, register_toolchains)
_ninja_toolchain(ninja_version, register_toolchains)
ninja_toolchain(ninja_version, register_toolchains)
meson_toolchain(meson_version, register_toolchains)

if register_built_pkgconfig_toolchain:
pkgconfig_toolchain(pkgconfig_version, register_toolchains)

def _cmake_toolchain(version, register_toolchains):
def cmake_toolchain(version, register_toolchains):
if register_toolchains:
native.register_toolchains(
"@rules_foreign_cc//toolchains:built_cmake_toolchain",
Expand Down Expand Up @@ -130,7 +130,7 @@ def make_toolchain(version, register_toolchains):

fail("Unsupported make version: " + str(version))

def _ninja_toolchain(version, register_toolchains):
def ninja_toolchain(version, register_toolchains):
if register_toolchains:
native.register_toolchains(
"@rules_foreign_cc//toolchains:built_ninja_toolchain",
Expand Down

0 comments on commit 289b9c6

Please sign in to comment.