Skip to content

Commit ab96e59

Browse files
committed
feat: extend the extension to support more version pins
1 parent 4c0c58f commit ab96e59

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

foreign_cc/extensions.bzl

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,41 @@
22

33
load("@bazel_features//:features.bzl", "bazel_features")
44
load("//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
5+
load("//foreign_cc/private:default_versions.bzl", _DEFAULT_VERSIONS = "DEFAULT_VERSIONS")
56
load("//toolchains:prebuilt_toolchains.bzl", "prebuilt_toolchains")
67

7-
_DEFAULT_CMAKE_VERSION = "3.31.7"
8-
_DEFAULT_NINJA_VERSION = "1.12.1"
9-
108
cmake_toolchain_version = tag_class(attrs = {
11-
"version": attr.string(doc = "The cmake version", default = _DEFAULT_CMAKE_VERSION),
9+
"version": attr.string(doc = "The cmake version", default = _DEFAULT_VERSIONS["cmake"]),
10+
})
11+
12+
make_toolchain_version = tag_class(attrs = {
13+
"version": attr.string(doc = "The make version", default = _DEFAULT_VERSIONS["make"]),
14+
})
15+
16+
meson_toolchain_version = tag_class(attrs = {
17+
"version": attr.string(doc = "The meson version", default = _DEFAULT_VERSIONS["meson"]),
1218
})
1319

1420
ninja_toolchain_version = tag_class(attrs = {
15-
"version": attr.string(doc = "The ninja version", default = _DEFAULT_NINJA_VERSION),
21+
"version": attr.string(doc = "The ninja version", default = _DEFAULT_VERSIONS["ninja"]),
22+
})
23+
24+
pkgconfig_toolchain_version = tag_class(attrs = {
25+
"version": attr.string(doc = "The pkgconfig version", default = _DEFAULT_VERSIONS["pkgconfig"]),
1626
})
1727

1828
def _init(module_ctx):
29+
versions = dict(_DEFAULT_VERSIONS)
30+
31+
pinned_kw = {}
32+
33+
for mod in module_ctx.modules:
34+
if not mod.is_root:
35+
for toolchain_type in versions.keys():
36+
for toolchain in getattr(mod.tags, toolchain_type):
37+
versions[toolchain_type] = toolchain.version
38+
pinned_kw[toolchain_type + "_version"] = toolchain.version
39+
1940
rules_foreign_cc_dependencies(
2041
register_toolchains = False,
2142
register_built_tools = True,
@@ -24,21 +45,9 @@ def _init(module_ctx):
2445
register_built_pkgconfig_toolchain = True,
2546
# These should be registered via bzlmod entries instead
2647
register_repos = False,
48+
**pinned_kw
2749
)
2850

29-
versions = {
30-
"cmake": _DEFAULT_CMAKE_VERSION,
31-
"ninja": _DEFAULT_NINJA_VERSION,
32-
}
33-
34-
for mod in module_ctx.modules:
35-
if not mod.is_root:
36-
for toolchain in mod.tags.cmake:
37-
versions["cmake"] = toolchain.version
38-
39-
for toolchain in mod.tags.ninja:
40-
versions["ninja"] = toolchain.version
41-
4251
prebuilt_toolchains(
4352
cmake_version = versions["cmake"],
4453
ninja_version = versions["ninja"],
@@ -54,6 +63,9 @@ tools = module_extension(
5463
implementation = _init,
5564
tag_classes = {
5665
"cmake": cmake_toolchain_version,
66+
"make": make_toolchain_version,
67+
"meson": meson_toolchain_version,
5768
"ninja": ninja_toolchain_version,
69+
"pkgconfig": pkgconfig_toolchain_version,
5870
},
5971
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
""" contains the default versions of the prebuilt and built toolchains"""
2+
DEFAULT_VERSIONS = {
3+
"cmake": "3.31.7",
4+
"make": "4.4.1",
5+
"meson": "1.5.1",
6+
"ninja": "1.12.1",
7+
"pkgconfig": "0.29.2",
8+
}

foreign_cc/repositories.bzl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
5+
load("//foreign_cc/private:default_versions.bzl", _DEFAULT_VERSIONS = "DEFAULT_VERSIONS")
56
load("//foreign_cc/private/framework:toolchain.bzl", "register_framework_toolchains")
67
load("//toolchains:toolchains.bzl", "built_toolchains", "prebuilt_toolchains", "preinstalled_toolchains")
78

89
# buildifier: disable=unnamed-macro
910
def rules_foreign_cc_dependencies(
1011
native_tools_toolchains = [],
1112
register_default_tools = True,
12-
cmake_version = "3.31.7",
13-
make_version = "4.4.1",
14-
ninja_version = "1.12.1",
15-
meson_version = "1.5.1",
16-
pkgconfig_version = "0.29.2",
13+
cmake_version = _DEFAULT_VERSIONS["cmake"],
14+
make_version = _DEFAULT_VERSIONS["make"],
15+
ninja_version = _DEFAULT_VERSIONS["ninja"],
16+
meson_version = _DEFAULT_VERSIONS["meson"],
17+
pkgconfig_version = _DEFAULT_VERSIONS["pkgconfig"],
1718
register_preinstalled_tools = True,
1819
register_built_tools = True,
1920
register_toolchains = True,

0 commit comments

Comments
 (0)