Allow configuring meson, make and pkgconfig versions via bzlmod extension

This commit is contained in:
James Sharpe 2024-01-12 22:28:37 +00:00
parent a8421af4cc
commit b6938f84a2
14 changed files with 502 additions and 1309 deletions

View File

@ -7,8 +7,8 @@ module(
)
bazel_dep(name = "bazel_features", version = "1.15.0")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "platforms", version = "0.0.9")
bazel_dep(name = "rules_python", version = "0.23.1")
# Dev dependencies
@ -28,23 +28,16 @@ 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.1_toolchains",
"ninja_build_src",
"pkgconfig_src",
"prebuilt_cmake_toolchains",
"prebuilt_ninja_toolchains",
"rules_foreign_cc_framework_toolchains",
"toolchain_hub",
)
register_toolchains(
"@toolchain_hub//:all",
"@prebuilt_cmake_toolchains//:all",
"@prebuilt_ninja_toolchains//:all",
"@rules_foreign_cc_framework_toolchains//:all",
"@cmake_3.23.2_toolchains//:all",
"@ninja_1.12.1_toolchains//:all",
"@python_3_9//:all",
"@rules_foreign_cc//toolchains:all",
)

View File

@ -7,16 +7,15 @@ local_path_override(
tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools")
tools.cmake(version = "3.23.1")
tools.ninja(version = "1.11.1")
use_repo(
tools,
"meson_src",
)
tools.meson(version = "1.5.1")
bazel_dep(name = "platforms", version = "0.0.6")
bazel_dep(name = "rules_swift", version = "1.6.0", repo_name = "build_bazel_rules_swift")
use_repo(tools, "meson_1.5.1_src")
bazel_dep(name = "platforms", version = "0.0.9")
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")
bazel_dep(name = "rules_cc", version = "0.0.9")
python = use_extension("@rules_python//python/extensions:python.bzl", "python")

View File

@ -17,6 +17,7 @@ def zlib_repositories():
],
urls = [
"https://zlib.net/zlib-1.2.13.tar.gz",
"https://zlib.net/archive/zlib-1.2.13.tar.gz",
"https://storage.googleapis.com/mirror.tensorflow.org/zlib.net/zlib-1.2.13.tar.gz",
],
)

View File

@ -1,51 +1,123 @@
"""Entry point for extensions used by bzlmod."""
load("//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
load("//toolchains:prebuilt_toolchains.bzl", "prebuilt_toolchains")
_DEFAULT_CMAKE_VERSION = "3.23.2"
_DEFAULT_NINJA_VERSION = "1.12.1"
load("//foreign_cc:repositories.bzl", "DEFAULT_CMAKE_VERSION", "DEFAULT_MAKE_VERSION", "DEFAULT_MESON_VERSION", "DEFAULT_NINJA_VERSION", "DEFAULT_PKGCONFIG_VERSION")
load("//foreign_cc/private/bzlmod:toolchain_hub.bzl", "hub_repo")
load("//foreign_cc/private/framework:toolchain.bzl", "register_framework_toolchains")
load("//toolchains:built_toolchains.bzl", "make_toolchain", "meson_toolchain", "pkgconfig_toolchain", cmake_toolchains_src = "cmake_toolchain", ninja_toolchains_src = "ninja_toolchain")
load("//toolchains:prebuilt_toolchains.bzl", "cmake_toolchains", "ninja_toolchains")
cmake_toolchain_version = tag_class(attrs = {
"version": attr.string(doc = "The cmake version", default = _DEFAULT_CMAKE_VERSION),
"version": attr.string(doc = "The cmake version", default = DEFAULT_CMAKE_VERSION),
})
make_toolchain_version = tag_class(attrs = {
"version": attr.string(doc = "The GNU Make version", default = DEFAULT_MAKE_VERSION),
})
meson_toolchain_version = tag_class(attrs = {
"version": attr.string(doc = "The meson version", default = DEFAULT_MESON_VERSION),
})
ninja_toolchain_version = tag_class(attrs = {
"version": attr.string(doc = "The ninja version", default = _DEFAULT_NINJA_VERSION),
"version": attr.string(doc = "The ninja version", default = DEFAULT_NINJA_VERSION),
})
pkgconfig_toolchain_version = tag_class(attrs = {
"version": attr.string(doc = "The pkgconfig version", default = DEFAULT_PKGCONFIG_VERSION),
})
def _init(module_ctx):
rules_foreign_cc_dependencies(
register_toolchains = False,
register_built_tools = True,
register_default_tools = False,
register_preinstalled_tools = False,
register_built_pkgconfig_toolchain = True,
)
versions = {
"cmake": _DEFAULT_CMAKE_VERSION,
"ninja": _DEFAULT_NINJA_VERSION,
}
cmake_registered = False
make_registered = False
meson_registered = False
ninja_registered = False
pkgconfig_registered = False
toolchain_names = []
toolchain_target = []
toolchain_types = []
for mod in module_ctx.modules:
if not mod.is_root:
if mod.is_root:
for toolchain in mod.tags.cmake:
versions["cmake"] = toolchain.version
cmake_toolchains(toolchain.version)
cmake_toolchains_src(toolchain.version)
toolchain_names.append("cmake_{}_from_src".format(toolchain.version))
toolchain_types.append("@rules_foreign_cc//toolchains:cmake_toolchain")
toolchain_target.append("@cmake_{}_src//:built_cmake".format(toolchain.version))
cmake_registered = True
for toolchain in mod.tags.make:
make_toolchain(toolchain.version)
toolchain_names.append("make_{}_from_src".format(toolchain.version))
toolchain_types.append("@rules_foreign_cc//toolchains:make_toolchain")
toolchain_target.append("@gnumake_{}_src//:built_make".format(toolchain.version))
make_registered = True
for toolchain in mod.tags.meson:
meson_toolchain(toolchain.version)
toolchain_names.append("meson_{}_from_src".format(toolchain.version))
toolchain_types.append("@rules_foreign_cc//toolchains:meson_toolchain")
toolchain_target.append("@meson_{}_src//:built_meson".format(toolchain.version))
meson_registered = True
for toolchain in mod.tags.ninja:
versions["ninja"] = toolchain.version
ninja_toolchains(toolchain.version)
ninja_toolchains_src(toolchain.version)
prebuilt_toolchains(
cmake_version = versions["cmake"],
ninja_version = versions["ninja"],
register_toolchains = False,
)
toolchain_names.append("ninja_{}_from_src".format(toolchain.version))
toolchain_types.append("@rules_foreign_cc//toolchains:ninja_toolchain")
toolchain_target.append("@ninja_{}_src//:built_ninja".format(toolchain.version))
ninja_registered = True
for toolchain in mod.tags.pkgconfig:
pkgconfig_toolchain(toolchain.version)
toolchain_names.append("pkgconfig_{}_from_src".format(toolchain.version))
toolchain_types.append("@rules_foreign_cc//toolchains:pkgconfig_toolchain")
toolchain_target.append("@pkgconfig_{}_src//:built_pkgconfig".format(toolchain.version))
pkgconfig_registered = True
if not cmake_registered:
cmake_toolchains(DEFAULT_CMAKE_VERSION)
cmake_toolchains_src(DEFAULT_CMAKE_VERSION)
toolchain_names.append("cmake_{}_from_src".format(DEFAULT_CMAKE_VERSION))
toolchain_types.append("@rules_foreign_cc//toolchains:cmake_toolchain")
toolchain_target.append("@cmake_{}_src//:built_cmake".format(DEFAULT_CMAKE_VERSION))
if not make_registered:
make_toolchain(DEFAULT_MAKE_VERSION)
toolchain_names.append("make_{}_from_src".format(DEFAULT_MAKE_VERSION))
toolchain_types.append("@rules_foreign_cc//toolchains:make_toolchain")
toolchain_target.append("@gnumake_{}_src//:built_make".format(DEFAULT_MAKE_VERSION))
if not meson_registered:
meson_toolchain(DEFAULT_MESON_VERSION)
toolchain_names.append("meson_{}_from_src".format(DEFAULT_MESON_VERSION))
toolchain_types.append("@rules_foreign_cc//toolchains:meson_toolchain")
toolchain_target.append("@meson_{}_src//:built_meson".format(DEFAULT_MESON_VERSION))
if not ninja_registered:
ninja_toolchains(DEFAULT_NINJA_VERSION)
ninja_toolchains_src(DEFAULT_NINJA_VERSION)
toolchain_names.append("ninja_{}_from_src".format(DEFAULT_NINJA_VERSION))
toolchain_types.append("@rules_foreign_cc//toolchains:ninja_toolchain")
toolchain_target.append("@ninja_{}_src//:built_ninja".format(DEFAULT_NINJA_VERSION))
if not pkgconfig_registered:
pkgconfig_toolchain(DEFAULT_PKGCONFIG_VERSION)
toolchain_names.append("pkgconfig_{}_from_src".format(DEFAULT_PKGCONFIG_VERSION))
toolchain_types.append("@rules_foreign_cc//toolchains:pkgconfig_toolchain")
toolchain_target.append("@pkgconfig_{}_src//:built_pkgconfig".format(DEFAULT_PKGCONFIG_VERSION))
register_framework_toolchains(register_toolchains = False)
hub_repo(name = "toolchain_hub", toolchain_names = toolchain_names, toolchain_target = toolchain_target, toolchain_types = toolchain_types)
tools = module_extension(
implementation = _init,
tag_classes = {
"cmake": cmake_toolchain_version,
"make": make_toolchain_version,
"meson": meson_toolchain_version,
"ninja": ninja_toolchain_version,
"pkgconfig": pkgconfig_toolchain_version,
},
)

View File

@ -212,8 +212,8 @@ def meson_with_requirements(name, requirements, **kwargs):
meson_tool(
name = "meson_tool_for_{}".format(name),
main = "@meson_src//:meson.py",
data = ["@meson_src//:runtime"],
main = "@meson_1.5.1_src//:meson.py",
data = ["@meson_1.5.1_src//:runtime"],
requirements = requirements,
tags = tags + ["manual"],
)

View File

View File

@ -0,0 +1,33 @@
def _hub_repo_impl(rctx):
if len(rctx.attr.toolchain_names) != len(rctx.attr.toolchain_target):
fail("toolchain_names and toolchain_target must have the same length.")
if len(rctx.attr.toolchain_names) != len(rctx.attr.toolchain_types):
fail("toolchain_names and toolchain_types must have the same length.")
toolchains = ["toolchain(name = '{}', toolchain = '{}', toolchain_type = '{}')".format(name, target, type) for (name, target, type) in zip(rctx.attr.toolchain_names, rctx.attr.toolchain_target, rctx.attr.toolchain_types)]
rctx.file("BUILD", "\n".join(toolchains), executable = False)
hub_repo = repository_rule(
doc = """\
This private rule creates a repo with a BUILD file that containers all the toolchain
rules that have been requested by the user so that the MODULE.bazel file can simply
register `:all` and get all the toolchains registered in a single call.
""",
implementation = _hub_repo_impl,
attrs = {
"toolchain_names": attr.string_list(
doc = "The list of toolchains to include in the hub repo.",
default = [],
),
"toolchain_target": attr.string_list(
doc = "The list of toolchain targets to include in the hub repo.",
default = [],
),
"toolchain_types": attr.string_list(
doc = "The list of toolchain targets to include in the hub repo.",
default = [],
),
# "_rules_foreign_cc_workspace: attr.label(default = Label("//:does_not_matter_what_this_name_is")),
},
)

View File

@ -5,18 +5,23 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//foreign_cc/private/framework:toolchain.bzl", "register_framework_toolchains")
load("//toolchains:toolchains.bzl", "built_toolchains", "prebuilt_toolchains", "preinstalled_toolchains")
DEFAULT_CMAKE_VERSION = "3.29.1"
DEFAULT_MAKE_VERSION = "4.4.1"
DEFAULT_MESON_VERSION = "1.5.1"
DEFAULT_NINJA_VERSION = "1.12.1"
DEFAULT_PKGCONFIG_VERSION = "0.29.2"
# buildifier: disable=unnamed-macro
def rules_foreign_cc_dependencies(
native_tools_toolchains = [],
register_default_tools = True,
cmake_version = "3.23.2",
make_version = "4.4.1",
ninja_version = "1.12.1",
meson_version = "1.5.1",
pkgconfig_version = "0.29.2",
cmake_version = DEFAULT_CMAKE_VERSION,
make_version = DEFAULT_MAKE_VERSION,
ninja_version = DEFAULT_NINJA_VERSION,
meson_version = DEFAULT_MESON_VERSION,
pkgconfig_version = DEFAULT_PKGCONFIG_VERSION,
register_preinstalled_tools = True,
register_built_tools = True,
register_toolchains = True,
register_built_pkgconfig_toolchain = True):
"""Call this function from the WORKSPACE file to initialize rules_foreign_cc \
dependencies and let neccesary code generation happen \
@ -50,8 +55,6 @@ def rules_foreign_cc_dependencies(
register_built_tools: If true, toolchains that build the tools from source are registered
register_toolchains: If true, registers the toolchains via native.register_toolchains. Used by bzlmod
register_built_pkgconfig_toolchain: If true, the built pkgconfig toolchain will be registered. On Windows it may be preferrable to set this to False, as
this requires the --enable_runfiles bazel option. Also note that building pkgconfig from source under bazel results in paths that are more
than 256 characters long, which will not work on Windows unless the following options are added to the .bazelrc and symlinks are enabled in Windows.
@ -61,13 +64,13 @@ def rules_foreign_cc_dependencies(
startup --output_user_root=C:/b -> This is required to keep paths as short as possible
"""
register_framework_toolchains(register_toolchains = register_toolchains)
register_framework_toolchains(register_toolchains = True)
if register_toolchains:
native.register_toolchains(*native_tools_toolchains)
native.register_toolchains(*native_tools_toolchains)
if register_default_tools:
prebuilt_toolchains(cmake_version, ninja_version, register_toolchains)
prebuilt_toolchains(cmake_version, ninja_version)
native.register_toolchains("@prebuilt_cmake_toolchains//:all", "@prebuilt_ninja_toolchains//:all")
if register_built_tools:
built_toolchains(
@ -76,7 +79,6 @@ def rules_foreign_cc_dependencies(
ninja_version = ninja_version,
meson_version = meson_version,
pkgconfig_version = pkgconfig_version,
register_toolchains = register_toolchains,
register_built_pkgconfig_toolchain = register_built_pkgconfig_toolchain,
)

View File

@ -67,36 +67,6 @@ current_autoconf_toolchain(
name = "current_autoconf_toolchain",
)
toolchain(
name = "built_cmake_toolchain",
toolchain = "//toolchains/private:built_cmake",
toolchain_type = ":cmake_toolchain",
)
toolchain(
name = "built_ninja_toolchain",
toolchain = "//toolchains/private:built_ninja",
toolchain_type = ":ninja_toolchain",
)
toolchain(
name = "built_make_toolchain",
toolchain = "//toolchains/private:built_make",
toolchain_type = ":make_toolchain",
)
toolchain(
name = "built_meson_toolchain",
toolchain = "//toolchains/private:built_meson",
toolchain_type = ":meson_toolchain",
)
toolchain(
name = "built_pkgconfig_toolchain",
toolchain = "//toolchains/private:built_pkgconfig",
toolchain_type = ":pkgconfig_toolchain",
)
# Preinstalled cmake will always be the default, if toolchain with more exact constraints
# is not defined before; registered from workspace_definitions.bzl#rules_foreign_cc_dependencies
toolchain(

View File

@ -7,15 +7,106 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@rules_foreign_cc//toolchains:cmake_versions.bzl", _CMAKE_SRCS = "CMAKE_SRCS")
_ALL_CONTENT = """\
_CMAKE_ALL_CONTENT = """\
load("@rules_foreign_cc//foreign_cc/built_tools:cmake_build.bzl", "cmake_tool")
load("@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl", "native_tool_toolchain")
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)
config_setting(
name = "msvc_compiler",
flag_values = {
"@bazel_tools//tools/cpp:compiler": "msvc-cl",
},
)
cmake_tool(
name = "cmake_tool",
srcs = ":all_srcs",
tags = ["manual"],
)
native_tool_toolchain(
name = "built_cmake",
env = select({
"@platforms//os:windows": {"CMAKE": "$(execpath :cmake_tool)/bin/cmake.exe"},
"//conditions:default": {"CMAKE": "$(execpath :cmake_tool)/bin/cmake"},
}),
path = select({
"@platforms//os:windows": "$(execpath :cmake_tool)/bin/cmake.exe",
"//conditions:default": "$(execpath :cmake_tool)/bin/cmake",
}),
target = ":cmake_tool",
visibility = ["//visibility:public"],
)
"""
_MAKE_BUILD_FILE_CONTENT = """\
load("@rules_foreign_cc//foreign_cc/built_tools:make_build.bzl", "make_tool")
load("@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl", "native_tool_toolchain")
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)
make_tool(
name = "make_tool",
srcs = ":all_srcs",
tags = ["manual"],
)
native_tool_toolchain(
name = "built_make",
env = select({
"@platforms//os:windows": {"MAKE": "$(execpath :make_tool)/bin/make.exe"},
"//conditions:default": {"MAKE": "$(execpath :make_tool)/bin/make"},
}),
path = select({
"@platforms//os:windows": "$(execpath :make_tool)/bin/make.exe",
"//conditions:default": "$(execpath :make_tool)/bin/make",
}),
target = ":make_tool",
visibility = ["//visibility:public"],
)
"""
_NINJA_BUILD_FILE_CONTENT = """\
load("@rules_foreign_cc//foreign_cc/built_tools:ninja_build.bzl", "ninja_tool")
load("@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl", "native_tool_toolchain")
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)
ninja_tool(
name = "ninja_tool",
srcs = ":all_srcs",
tags = ["manual"],
)
native_tool_toolchain(
name = "built_ninja",
env = select({
"@platforms//os:windows": {"NINJA": "$(execpath :ninja_tool)/bin/ninja.exe"},
"//conditions:default": {"NINJA": "$(execpath :ninja_tool)/bin/ninja"},
}),
path = select({
"@platforms//os:windows": "$(execpath :ninja_tool)/bin/ninja.exe",
"//conditions:default": "$(execpath :ninja_tool)/bin/ninja",
}),
target = ":ninja_tool",
visibility = ["//visibility:public"],
)
"""
_MESON_BUILD_FILE_CONTENT = """\
load("@rules_foreign_cc//foreign_cc/built_tools:meson_build.bzl", "meson_tool")
load("@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl", "native_tool_toolchain")
exports_files(["meson.py"])
filegroup(
@ -23,10 +114,54 @@ filegroup(
srcs = glob(["mesonbuild/**"]),
visibility = ["//visibility:public"],
)
meson_tool(
name = "meson_tool",
data = [":runtime"],
main = ":meson.py",
tags = ["manual"],
)
native_tool_toolchain(
name = "built_meson",
env = {"MESON": "$(execpath :meson_tool)"},
path = "$(execpath :meson_tool)",
target = ":meson_tool",
)
"""
_PKGCONFIG_BUILD_FILE_CONTENT = """\
load("@rules_foreign_cc//foreign_cc/built_tools:pkgconfig_build.bzl", "pkgconfig_tool")
load("@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl", "native_tool_toolchain")
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)
pkgconfig_tool(
name = "pkgconfig_tool",
srcs = ":all_srcs",
tags = ["manual"],
)
native_tool_toolchain(
name = "built_pkgconfig",
env = select({
"@platforms//os:windows": {"PKG_CONFIG": "$(execpath :pkgconfig_tool)"},
"//conditions:default": {"PKG_CONFIG": "$(execpath :pkgconfig_tool)/bin/pkg-config"},
}),
path = select({
"@platforms//os:windows": "$(execpath :pkgconfig_tool)",
"//conditions:default": "$(execpath :pkgconfig_tool)/bin/pkg-config",
}),
target = ":pkgconfig_tool",
visibility = ["//visibility:public"],
)
"""
# buildifier: disable=unnamed-macro
def built_toolchains(cmake_version, make_version, ninja_version, meson_version, pkgconfig_version, register_toolchains, register_built_pkgconfig_toolchain):
def built_toolchains(cmake_version, make_version, ninja_version, meson_version, pkgconfig_version, register_built_pkgconfig_toolchain):
"""
Register toolchains for built tools that will be built from source
@ -42,24 +177,18 @@ def built_toolchains(cmake_version, make_version, ninja_version, meson_version,
pkgconfig_version: The pkg-config version to build
register_toolchains: If true, registers the toolchains via native.register_toolchains. Used by bzlmod
register_built_pkgconfig_toolchain: If true, the built pkgconfig toolchain will be registered.
"""
_cmake_toolchain(cmake_version, register_toolchains)
_make_toolchain(make_version, register_toolchains)
_ninja_toolchain(ninja_version, register_toolchains)
_meson_toolchain(meson_version, register_toolchains)
cmake_toolchain(cmake_version)
make_toolchain(make_version)
ninja_toolchain(ninja_version)
meson_toolchain(meson_version)
if register_built_pkgconfig_toolchain:
_pkgconfig_toolchain(pkgconfig_version, register_toolchains)
def _cmake_toolchain(version, register_toolchains):
if register_toolchains:
native.register_toolchains(
"@rules_foreign_cc//toolchains:built_cmake_toolchain",
)
pkgconfig_toolchain(pkgconfig_version)
# buildifier: disable=unnamed-macro
def cmake_toolchain(version):
if _CMAKE_SRCS.get(version):
cmake_meta = _CMAKE_SRCS[version]
urls = cmake_meta[0]
@ -67,8 +196,8 @@ def _cmake_toolchain(version, register_toolchains):
sha256 = cmake_meta[2]
maybe(
http_archive,
name = "cmake_src",
build_file_content = _ALL_CONTENT,
name = "cmake_{}_src".format(version),
build_file_content = _CMAKE_ALL_CONTENT,
sha256 = sha256,
strip_prefix = prefix,
urls = urls,
@ -80,17 +209,13 @@ def _cmake_toolchain(version, register_toolchains):
fail("Unsupported cmake version: " + str(version))
def _make_toolchain(version, register_toolchains):
if register_toolchains:
native.register_toolchains(
"@rules_foreign_cc//toolchains:built_make_toolchain",
)
# buildifier: disable=unnamed-macro
def make_toolchain(version):
if version == "4.4.1":
maybe(
http_archive,
name = "gnumake_src",
build_file_content = _ALL_CONTENT,
name = "gnumake_4.4.1_src",
build_file_content = _MAKE_BUILD_FILE_CONTENT,
sha256 = "dd16fb1d67bfab79a72f5e8390735c49e3e8e70b4945a15ab1f81ddb78658fb3",
strip_prefix = "make-4.4.1",
urls = [
@ -103,8 +228,8 @@ def _make_toolchain(version, register_toolchains):
if version == "4.4":
maybe(
http_archive,
name = "gnumake_src",
build_file_content = _ALL_CONTENT,
name = "gnumake_4.4_src",
build_file_content = _MAKE_BUILD_FILE_CONTENT,
sha256 = "581f4d4e872da74b3941c874215898a7d35802f03732bdccee1d4a7979105d18",
strip_prefix = "make-4.4",
urls = [
@ -116,8 +241,8 @@ def _make_toolchain(version, register_toolchains):
if version == "4.3":
maybe(
http_archive,
name = "gnumake_src",
build_file_content = _ALL_CONTENT,
name = "gnumake_4.3_src",
build_file_content = _MAKE_BUILD_FILE_CONTENT,
patches = [Label("//toolchains:make-reproducible-bootstrap.patch")],
sha256 = "e05fdde47c5f7ca45cb697e973894ff4f5d79e13b750ed57d7b66d8defc78e19",
strip_prefix = "make-4.3",
@ -130,16 +255,12 @@ def _make_toolchain(version, register_toolchains):
fail("Unsupported make version: " + str(version))
def _ninja_toolchain(version, register_toolchains):
if register_toolchains:
native.register_toolchains(
"@rules_foreign_cc//toolchains:built_ninja_toolchain",
)
def ninja_toolchain(version):
if version == "1.12.1":
maybe(
http_archive,
name = "ninja_build_src",
build_file_content = _ALL_CONTENT,
name = "ninja_1.12.1_src",
build_file_content = _NINJA_BUILD_FILE_CONTENT,
integrity = "sha256-ghvf9Io/aDvEuztvC1/nstZHz2XVKutjMoyRpsbfKFo=",
strip_prefix = "ninja-1.12.1",
urls = [
@ -151,8 +272,8 @@ def _ninja_toolchain(version, register_toolchains):
if version == "1.12.0":
maybe(
http_archive,
name = "ninja_build_src",
build_file_content = _ALL_CONTENT,
name = "ninja_1.12.0_src",
build_file_content = _NINJA_BUILD_FILE_CONTENT,
integrity = "sha256-iyyGzUg9x/y3l1xexzKRNdIQCZqJvH2wWQoHsLv+SaU=",
strip_prefix = "ninja-1.12.0",
urls = [
@ -164,8 +285,8 @@ def _ninja_toolchain(version, register_toolchains):
if version == "1.11.1":
maybe(
http_archive,
name = "ninja_build_src",
build_file_content = _ALL_CONTENT,
name = "ninja_1.11.1_src",
build_file_content = _NINJA_BUILD_FILE_CONTENT,
sha256 = "31747ae633213f1eda3842686f83c2aa1412e0f5691d1c14dbbcc67fe7400cea",
strip_prefix = "ninja-1.11.1",
urls = [
@ -177,8 +298,8 @@ def _ninja_toolchain(version, register_toolchains):
if version == "1.11.0":
maybe(
http_archive,
name = "ninja_build_src",
build_file_content = _ALL_CONTENT,
name = "ninja_1.11.0_src",
build_file_content = _NINJA_BUILD_FILE_CONTENT,
sha256 = "3c6ba2e66400fe3f1ae83deb4b235faf3137ec20bd5b08c29bfc368db143e4c6",
strip_prefix = "ninja-1.11.0",
urls = [
@ -190,8 +311,8 @@ def _ninja_toolchain(version, register_toolchains):
if version == "1.10.2":
maybe(
http_archive,
name = "ninja_build_src",
build_file_content = _ALL_CONTENT,
name = "ninja_1.10.2_src",
build_file_content = _NINJA_BUILD_FILE_CONTENT,
sha256 = "ce35865411f0490368a8fc383f29071de6690cbadc27704734978221f25e2bed",
strip_prefix = "ninja-1.10.2",
urls = [
@ -203,15 +324,12 @@ def _ninja_toolchain(version, register_toolchains):
fail("Unsupported ninja version: " + str(version))
def _meson_toolchain(version, register_toolchains):
if register_toolchains:
native.register_toolchains(
"@rules_foreign_cc//toolchains:built_meson_toolchain",
)
# buildifier: disable=unnamed-macro
def meson_toolchain(version):
if version == "1.5.1":
maybe(
http_archive,
name = "meson_src",
name = "meson_1.5.1_src",
build_file_content = _MESON_BUILD_FILE_CONTENT,
sha256 = "567e533adf255de73a2de35049b99923caf872a455af9ce03e01077e0d384bed",
strip_prefix = "meson-1.5.1",
@ -224,7 +342,7 @@ def _meson_toolchain(version, register_toolchains):
if version == "1.1.1":
maybe(
http_archive,
name = "meson_src",
name = "meson_1.1.1_src",
build_file_content = _MESON_BUILD_FILE_CONTENT,
sha256 = "d04b541f97ca439fb82fab7d0d480988be4bd4e62563a5ca35fadb5400727b1c",
strip_prefix = "meson-1.1.1",
@ -237,7 +355,7 @@ def _meson_toolchain(version, register_toolchains):
if version == "0.63.0":
maybe(
http_archive,
name = "meson_src",
name = "meson_0.63.0_src",
build_file_content = _MESON_BUILD_FILE_CONTENT,
sha256 = "3b51d451744c2bc71838524ec8d96cd4f8c4793d5b8d5d0d0a9c8a4f7c94cd6f",
strip_prefix = "meson-0.63.0",
@ -250,12 +368,8 @@ def _meson_toolchain(version, register_toolchains):
fail("Unsupported meson version: " + str(version))
def _pkgconfig_toolchain(version, register_toolchains):
if register_toolchains:
native.register_toolchains(
"@rules_foreign_cc//toolchains:built_pkgconfig_toolchain",
)
# buildifier: disable=unnamed-macro
def pkgconfig_toolchain(version):
maybe(
http_archive,
name = "glib_dev",
@ -333,8 +447,8 @@ cc_import(
if version == "0.29.2":
maybe(
http_archive,
name = "pkgconfig_src",
build_file_content = _ALL_CONTENT,
name = "pkgconfig_0.29.2_src",
build_file_content = _PKGCONFIG_BUILD_FILE_CONTENT,
sha256 = "6fc69c01688c9458a57eb9a1664c9aba372ccda420a02bf4429fe610e7e7d591",
strip_prefix = "pkg-config-0.29.2",
# The patch is required as bazel does not provide the VCINSTALLDIR or WINDOWSSDKDIR vars

View File

@ -533,17 +533,17 @@ CMAKE_SRCS = {
],
"3.28.5": [
[
"https://github.com/Kitware/CMake/releases/download/v3.28.5/cmake-3.28.5.tar.gz",
"https://github.com/Kitware/CMake/releases/download/v3.28.5/cmake-3.28.5.tar.gz"
],
"cmake-3.28.5",
"a75d3487ffe817e116a2bf668bf1434af7fe5864cbd4c7e3dcf33dd1a470d659",
"a75d3487ffe817e116a2bf668bf1434af7fe5864cbd4c7e3dcf33dd1a470d659"
],
"3.28.6": [
[
"https://github.com/Kitware/CMake/releases/download/v3.28.6/cmake-3.28.6.tar.gz",
"https://github.com/Kitware/CMake/releases/download/v3.28.6/cmake-3.28.6.tar.gz"
],
"cmake-3.28.6",
"c39c733900affc4eb0e9688b4d1a45435a732105d9bf9cc1e75dd2b9b81a36bb",
"c39c733900affc4eb0e9688b4d1a45435a732105d9bf9cc1e75dd2b9b81a36bb"
],
"3.29.0": [
[
@ -568,24 +568,24 @@ CMAKE_SRCS = {
],
"3.29.3": [
[
"https://github.com/Kitware/CMake/releases/download/v3.29.3/cmake-3.29.3.tar.gz",
"https://github.com/Kitware/CMake/releases/download/v3.29.3/cmake-3.29.3.tar.gz"
],
"cmake-3.29.3",
"252aee1448d49caa04954fd5e27d189dd51570557313e7b281636716a238bccb",
"252aee1448d49caa04954fd5e27d189dd51570557313e7b281636716a238bccb"
],
"3.29.4": [
[
"https://github.com/Kitware/CMake/releases/download/v3.29.4/cmake-3.29.4.tar.gz",
"https://github.com/Kitware/CMake/releases/download/v3.29.4/cmake-3.29.4.tar.gz"
],
"cmake-3.29.4",
"b1b48d7100bdff0b46e8c8f6a3c86476dbe872c8df39c42b8d104298b3d56a2c",
"b1b48d7100bdff0b46e8c8f6a3c86476dbe872c8df39c42b8d104298b3d56a2c"
],
"3.29.5": [
[
"https://github.com/Kitware/CMake/releases/download/v3.29.5/cmake-3.29.5.tar.gz",
"https://github.com/Kitware/CMake/releases/download/v3.29.5/cmake-3.29.5.tar.gz"
],
"cmake-3.29.5",
"dd63da7d763c0db455ca232f2c443f5234fe0b11f8bd6958a81d29cc987dfd6e",
"dd63da7d763c0db455ca232f2c443f5234fe0b11f8bd6958a81d29cc987dfd6e"
],
"3.3.2": [
[

File diff suppressed because it is too large Load Diff

View File

@ -209,13 +209,6 @@ maybe(
)
"""
REGISTER_TOOLCHAINS = """\
if register_toolchains:
native.register_toolchains(
{toolchains}
)
"""
BZL_FILE_TEMPLATE = """\
\"\"\" A U T O G E N E R A T E D -- D O N O T M O D I F Y
@generated
@ -281,21 +274,20 @@ native_tool_toolchain(
\"\"\"
# buildifier: disable=unnamed-macro
def prebuilt_toolchains(cmake_version, ninja_version, register_toolchains):
def prebuilt_toolchains(cmake_version, ninja_version):
\"\"\"Register toolchains for pre-built cmake and ninja binaries
Args:
cmake_version (string): The target cmake version
ninja_version (string): The target ninja-build version
register_toolchains (boolean): Whether to call native.register_toolchains or not
\"\"\"
_cmake_toolchains(cmake_version, register_toolchains)
_ninja_toolchains(ninja_version, register_toolchains)
cmake_toolchains(cmake_version)
ninja_toolchains(ninja_version)
def _cmake_toolchains(version, register_toolchains):
def cmake_toolchains(version):
{cmake_definitions}
def _ninja_toolchains(version, register_toolchains):
def ninja_toolchains(version):
{ninja_definitions}
"""
@ -314,7 +306,7 @@ def get_cmake_definitions() -> str:
"""Define a set of repositories and calls for registering `cmake` toolchains
Returns:
str: The Implementation of `_cmake_toolchains`
str: The Implementation of `cmake_toolchains`
"""
archives = []
@ -388,7 +380,7 @@ def get_cmake_definitions() -> str:
archives.append(
indent(
TOOLCHAIN_REPO_DEFINITION.format(
name="cmake_{}_toolchains".format(version),
name="prebuilt_cmake_toolchains",
repos=indent(
json.dumps(toolchains_repos, indent=4), " " * 4
).lstrip(),
@ -398,25 +390,6 @@ def get_cmake_definitions() -> str:
)
)
archives.append(
indent(
REGISTER_TOOLCHAINS.format(
toolchains="\n".join(
[
indent(
'"@cmake_{}_toolchains//:{}_toolchain",'.format(
version, repo
),
" " * 8,
)
for repo in toolchains_repos
]
)
),
" " * 8,
)
)
archives.extend(
[
indent("return", " " * 8),
@ -433,7 +406,7 @@ def get_ninja_definitions() -> str:
"""Define a set of repositories and calls for registering `ninja` toolchains
Returns:
str: The Implementation of `_ninja_toolchains`
str: The Implementation of `ninja_toolchains`
"""
archives = []
@ -506,7 +479,7 @@ def get_ninja_definitions() -> str:
archives.append(
indent(
TOOLCHAIN_REPO_DEFINITION.format(
name="ninja_{}_toolchains".format(version),
name="prebuilt_ninja_toolchains",
repos=indent(
json.dumps(toolchains_repos, indent=4), " " * 4
).lstrip(),
@ -516,25 +489,6 @@ def get_ninja_definitions() -> str:
)
)
archives.append(
indent(
REGISTER_TOOLCHAINS.format(
toolchains="\n".join(
[
indent(
'"@ninja_{}_toolchains//:{}_toolchain",'.format(
version, repo
),
" " * 8,
)
for repo in toolchains_repos
]
)
),
" " * 8,
)
)
archives.extend(
[
indent("return", " " * 8),

View File

@ -1,14 +1,13 @@
load("//foreign_cc/built_tools:cmake_build.bzl", "cmake_tool")
load("//foreign_cc/built_tools:make_build.bzl", "make_tool")
load("//foreign_cc/built_tools:meson_build.bzl", "meson_tool")
load("//foreign_cc/built_tools:ninja_build.bzl", "ninja_tool")
load("//foreign_cc/built_tools:pkgconfig_build.bzl", "pkgconfig_tool")
load("//toolchains/native_tools:native_tools_toolchain.bzl", "native_tool_toolchain")
package(default_visibility = ["//visibility:public"])
native_tool_toolchain(
name = "preinstalled_make",
env = select({
"@platforms//os:windows": {"MAKE": "make.exe"},
"//conditions:default": {"MAKE": "make"},
}),
path = select({
"@platforms//os:windows": "make.exe",
"//conditions:default": "make",
@ -20,25 +19,6 @@ native_tool_toolchain(
path = "nmake.exe",
)
make_tool(
name = "make_tool",
srcs = "@gnumake_src//:all_srcs",
tags = ["manual"],
)
native_tool_toolchain(
name = "built_make",
env = select({
"@platforms//os:windows": {"MAKE": "$(execpath :make_tool)/bin/make.exe"},
"//conditions:default": {"MAKE": "$(execpath :make_tool)/bin/make"},
}),
path = select({
"@platforms//os:windows": "$(execpath :make_tool)/bin/make.exe",
"//conditions:default": "$(execpath :make_tool)/bin/make",
}),
target = ":make_tool",
)
native_tool_toolchain(
name = "preinstalled_cmake",
env = select({
@ -51,25 +31,6 @@ native_tool_toolchain(
}),
)
cmake_tool(
name = "cmake_tool",
srcs = "@cmake_src//:all_srcs",
tags = ["manual"],
)
native_tool_toolchain(
name = "built_cmake",
env = select({
"@platforms//os:windows": {"CMAKE": "$(execpath :cmake_tool)/bin/cmake.exe"},
"//conditions:default": {"CMAKE": "$(execpath :cmake_tool)/bin/cmake"},
}),
path = select({
"@platforms//os:windows": "$(execpath :cmake_tool)/bin/cmake.exe",
"//conditions:default": "$(execpath :cmake_tool)/bin/cmake",
}),
target = ":cmake_tool",
)
native_tool_toolchain(
name = "preinstalled_ninja",
env = select({
@ -82,25 +43,6 @@ native_tool_toolchain(
}),
)
ninja_tool(
name = "ninja_tool",
srcs = "@ninja_build_src//:all_srcs",
tags = ["manual"],
)
native_tool_toolchain(
name = "built_ninja",
env = select({
"@platforms//os:windows": {"NINJA": "$(execpath :ninja_tool)/bin/ninja.exe"},
"//conditions:default": {"NINJA": "$(execpath :ninja_tool)/bin/ninja"},
}),
path = select({
"@platforms//os:windows": "$(execpath :ninja_tool)/bin/ninja.exe",
"//conditions:default": "$(execpath :ninja_tool)/bin/ninja",
}),
target = ":ninja_tool",
)
native_tool_toolchain(
name = "preinstalled_meson",
path = select({
@ -109,20 +51,6 @@ native_tool_toolchain(
}),
)
meson_tool(
name = "meson_tool",
data = ["@meson_src//:runtime"],
main = "@meson_src//:meson.py",
tags = ["manual"],
)
native_tool_toolchain(
name = "built_meson",
env = {"MESON": "$(execpath :meson_tool)"},
path = "$(execpath :meson_tool)",
target = ":meson_tool",
)
native_tool_toolchain(
name = "preinstalled_autoconf",
path = select({
@ -154,22 +82,3 @@ native_tool_toolchain(
"//conditions:default": "pkg-config",
}),
)
pkgconfig_tool(
name = "pkgconfig_tool",
srcs = "@pkgconfig_src//:all_srcs",
tags = ["manual"],
)
native_tool_toolchain(
name = "built_pkgconfig",
env = select({
"@platforms//os:windows": {"PKG_CONFIG": "$(execpath :pkgconfig_tool)"},
"//conditions:default": {"PKG_CONFIG": "$(execpath :pkgconfig_tool)/bin/pkg-config"},
}),
path = select({
"@platforms//os:windows": "$(execpath :pkgconfig_tool)",
"//conditions:default": "$(execpath :pkgconfig_tool)/bin/pkg-config",
}),
target = ":pkgconfig_tool",
)