2021-12-09 00:47:45 +00:00
|
|
|
"Macros for loading dependencies and registering toolchains"
|
|
|
|
|
2022-04-23 19:06:40 +00:00
|
|
|
load("//lib/private:jq_toolchain.bzl", "JQ_PLATFORMS", "jq_host_alias_repo", "jq_platform_repo", "jq_toolchains_repo", _DEFAULT_JQ_VERSION = "DEFAULT_JQ_VERSION")
|
|
|
|
load("//lib/private:yq_toolchain.bzl", "YQ_PLATFORMS", "yq_host_alias_repo", "yq_platform_repo", "yq_toolchains_repo", _DEFAULT_YQ_VERSION = "DEFAULT_YQ_VERSION")
|
2023-01-07 19:26:27 +00:00
|
|
|
load("//lib/private:copy_to_directory_toolchain.bzl", "COPY_TO_DIRECTORY_PLATFORMS", "copy_to_directory_platform_repo", "copy_to_directory_toolchains_repo")
|
2023-01-16 18:02:17 +00:00
|
|
|
load("//lib/private:coreutils_toolchain.bzl", "COREUTILS_PLATFORMS", "coreutils_platform_repo", "coreutils_toolchains_repo", _DEFAULT_COREUTILS_VERSION = "DEFAULT_COREUTILS_VERSION")
|
2023-01-17 01:19:13 +00:00
|
|
|
load("//lib/private:copy_directory_toolchain.bzl", "COPY_DIRECTORY_PLATFORMS", "copy_directory_platform_repo", "copy_directory_toolchains_repo")
|
2023-05-16 23:14:50 +00:00
|
|
|
load("//lib/private:expand_template_toolchain.bzl", "EXPAND_TEMPLATE_PLATFORMS", "expand_template_platform_repo", "expand_template_toolchains_repo")
|
2022-09-14 03:37:24 +00:00
|
|
|
load("//lib/private:local_config_platform.bzl", "local_config_platform")
|
2023-01-01 23:17:41 +00:00
|
|
|
load("//lib:utils.bzl", "is_bazel_6_or_greater", http_archive = "maybe_http_archive")
|
2022-06-10 20:58:40 +00:00
|
|
|
|
2023-01-07 19:26:27 +00:00
|
|
|
# buildifier: disable=unnamed-macro
|
2022-09-14 04:58:08 +00:00
|
|
|
def aspect_bazel_lib_dependencies(override_local_config_platform = False):
|
|
|
|
"""Load dependencies required by aspect rules
|
|
|
|
|
|
|
|
Args:
|
|
|
|
override_local_config_platform: override the @local_config_platform repository with one that adds stardoc
|
|
|
|
support for loading constraints.bzl.
|
|
|
|
|
|
|
|
Should be set in repositories that load @aspect_bazel_lib copy actions and also generate stardoc.
|
|
|
|
"""
|
2022-06-10 20:58:40 +00:00
|
|
|
http_archive(
|
|
|
|
name = "bazel_skylib",
|
2022-10-12 15:07:11 +00:00
|
|
|
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
|
2022-06-10 20:58:40 +00:00
|
|
|
urls = [
|
2022-10-12 15:07:11 +00:00
|
|
|
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
|
|
|
|
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
|
2022-06-10 20:58:40 +00:00
|
|
|
],
|
|
|
|
)
|
2021-12-09 00:47:45 +00:00
|
|
|
|
2023-01-01 23:17:41 +00:00
|
|
|
# Bazel 6 now has the exports that our custom local_config_platform rule made
|
|
|
|
# so it should never be needed when running Bazel 6 or newer
|
|
|
|
# TODO(2.0): remove the override_local_config_platform attribute entirely
|
|
|
|
if not is_bazel_6_or_greater() and override_local_config_platform:
|
2022-09-14 04:58:08 +00:00
|
|
|
local_config_platform(
|
|
|
|
name = "local_config_platform",
|
|
|
|
)
|
2022-09-14 03:37:24 +00:00
|
|
|
|
2023-01-07 19:26:27 +00:00
|
|
|
# Always register the copy_to_directory toolchain
|
2023-01-17 01:19:13 +00:00
|
|
|
register_copy_directory_toolchains()
|
2023-01-07 19:26:27 +00:00
|
|
|
register_copy_to_directory_toolchains()
|
|
|
|
|
2023-05-16 23:14:50 +00:00
|
|
|
# Always register the expand_template toolchain
|
|
|
|
register_expand_template_toolchains()
|
|
|
|
|
2023-03-10 17:37:57 +00:00
|
|
|
# Always register the coreutils toolchain
|
|
|
|
register_coreutils_toolchains()
|
|
|
|
|
2022-04-23 19:06:40 +00:00
|
|
|
# Re-export the default versions
|
|
|
|
DEFAULT_JQ_VERSION = _DEFAULT_JQ_VERSION
|
|
|
|
DEFAULT_YQ_VERSION = _DEFAULT_YQ_VERSION
|
2023-01-16 18:02:17 +00:00
|
|
|
DEFAULT_COREUTILS_VERSION = _DEFAULT_COREUTILS_VERSION
|
2022-04-23 19:06:40 +00:00
|
|
|
|
2022-04-27 04:07:17 +00:00
|
|
|
def register_jq_toolchains(name = "jq", version = DEFAULT_JQ_VERSION, register = True):
|
2021-12-09 00:47:45 +00:00
|
|
|
"""Registers jq toolchain and repositories
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: override the prefix for the generated toolchain repositories
|
2022-04-23 19:06:40 +00:00
|
|
|
version: the version of jq to execute (see https://github.com/stedolan/jq/releases)
|
2022-04-27 04:07:17 +00:00
|
|
|
register: whether to call through to native.register_toolchains.
|
|
|
|
Should be True for WORKSPACE users, but false when used under bzlmod extension
|
2021-12-09 00:47:45 +00:00
|
|
|
"""
|
2022-04-22 00:45:33 +00:00
|
|
|
for [platform, meta] in JQ_PLATFORMS.items():
|
2021-12-09 00:47:45 +00:00
|
|
|
jq_platform_repo(
|
2022-04-22 01:35:10 +00:00
|
|
|
name = "%s_%s" % (name, platform),
|
2021-12-09 00:47:45 +00:00
|
|
|
platform = platform,
|
2022-04-22 00:45:33 +00:00
|
|
|
version = version,
|
2021-12-09 00:47:45 +00:00
|
|
|
)
|
2022-04-27 04:07:17 +00:00
|
|
|
if register:
|
|
|
|
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
|
2021-12-09 00:47:45 +00:00
|
|
|
|
2022-04-27 15:08:28 +00:00
|
|
|
jq_host_alias_repo(name = name)
|
2022-04-22 01:35:10 +00:00
|
|
|
|
2021-12-09 00:47:45 +00:00
|
|
|
jq_toolchains_repo(
|
|
|
|
name = "%s_toolchains" % name,
|
2022-04-22 01:35:10 +00:00
|
|
|
user_repository_name = name,
|
2021-12-09 00:47:45 +00:00
|
|
|
)
|
2022-04-20 04:45:06 +00:00
|
|
|
|
2022-04-27 04:07:17 +00:00
|
|
|
def register_yq_toolchains(name = "yq", version = DEFAULT_YQ_VERSION, register = True):
|
2022-04-20 04:45:06 +00:00
|
|
|
"""Registers yq toolchain and repositories
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: override the prefix for the generated toolchain repositories
|
2022-04-23 19:06:40 +00:00
|
|
|
version: the version of yq to execute (see https://github.com/mikefarah/yq/releases)
|
2022-04-27 04:07:17 +00:00
|
|
|
register: whether to call through to native.register_toolchains.
|
|
|
|
Should be True for WORKSPACE users, but false when used under bzlmod extension
|
2022-04-20 04:45:06 +00:00
|
|
|
"""
|
2022-04-22 00:45:33 +00:00
|
|
|
for [platform, meta] in YQ_PLATFORMS.items():
|
2022-04-20 04:45:06 +00:00
|
|
|
yq_platform_repo(
|
2022-04-22 01:35:10 +00:00
|
|
|
name = "%s_%s" % (name, platform),
|
2022-04-20 04:45:06 +00:00
|
|
|
platform = platform,
|
2022-04-22 00:45:33 +00:00
|
|
|
version = version,
|
2022-04-20 04:45:06 +00:00
|
|
|
)
|
2022-04-27 04:07:17 +00:00
|
|
|
if register:
|
|
|
|
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
|
2022-04-20 04:45:06 +00:00
|
|
|
|
2022-04-27 15:08:28 +00:00
|
|
|
yq_host_alias_repo(name = name)
|
2022-04-22 01:35:10 +00:00
|
|
|
|
2022-04-20 04:45:06 +00:00
|
|
|
yq_toolchains_repo(
|
|
|
|
name = "%s_toolchains" % name,
|
2022-04-22 01:35:10 +00:00
|
|
|
user_repository_name = name,
|
2022-04-20 04:45:06 +00:00
|
|
|
)
|
2023-01-07 19:26:27 +00:00
|
|
|
|
2023-01-16 18:02:17 +00:00
|
|
|
def register_coreutils_toolchains(name = "coreutils", version = DEFAULT_COREUTILS_VERSION, register = True):
|
|
|
|
"""Registers coreutils toolchain and repositories
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: override the prefix for the generated toolchain repositories
|
|
|
|
version: the version of coreutils to execute (see https://github.com/uutils/coreutils/releases)
|
|
|
|
register: whether to call through to native.register_toolchains.
|
|
|
|
Should be True for WORKSPACE users, but false when used under bzlmod extension
|
|
|
|
"""
|
|
|
|
for [platform, meta] in COREUTILS_PLATFORMS.items():
|
|
|
|
coreutils_platform_repo(
|
|
|
|
name = "%s_%s" % (name, platform),
|
|
|
|
platform = platform,
|
2023-01-17 01:19:13 +00:00
|
|
|
version = version,
|
2023-01-16 18:02:17 +00:00
|
|
|
)
|
|
|
|
if register:
|
|
|
|
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
|
|
|
|
|
|
|
|
coreutils_toolchains_repo(
|
|
|
|
name = "%s_toolchains" % name,
|
|
|
|
user_repository_name = name,
|
|
|
|
)
|
|
|
|
|
2023-01-17 01:19:13 +00:00
|
|
|
def register_copy_directory_toolchains(name = "copy_directory", register = True):
|
|
|
|
"""Registers copy_directory toolchain and repositories
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: override the prefix for the generated toolchain repositories
|
|
|
|
register: whether to call through to native.register_toolchains.
|
|
|
|
Should be True for WORKSPACE users, but false when used under bzlmod extension
|
|
|
|
"""
|
|
|
|
for [platform, meta] in COPY_DIRECTORY_PLATFORMS.items():
|
|
|
|
copy_directory_platform_repo(
|
|
|
|
name = "%s_%s" % (name, platform),
|
|
|
|
platform = platform,
|
|
|
|
)
|
|
|
|
if register:
|
|
|
|
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
|
|
|
|
|
|
|
|
copy_directory_toolchains_repo(
|
|
|
|
name = "%s_toolchains" % name,
|
|
|
|
user_repository_name = name,
|
|
|
|
)
|
|
|
|
|
2023-01-07 19:26:27 +00:00
|
|
|
def register_copy_to_directory_toolchains(name = "copy_to_directory", register = True):
|
|
|
|
"""Registers copy_to_directory toolchain and repositories
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: override the prefix for the generated toolchain repositories
|
|
|
|
register: whether to call through to native.register_toolchains.
|
|
|
|
Should be True for WORKSPACE users, but false when used under bzlmod extension
|
|
|
|
"""
|
|
|
|
for [platform, meta] in COPY_TO_DIRECTORY_PLATFORMS.items():
|
|
|
|
copy_to_directory_platform_repo(
|
|
|
|
name = "%s_%s" % (name, platform),
|
|
|
|
platform = platform,
|
|
|
|
)
|
|
|
|
if register:
|
|
|
|
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
|
|
|
|
|
|
|
|
copy_to_directory_toolchains_repo(
|
|
|
|
name = "%s_toolchains" % name,
|
|
|
|
user_repository_name = name,
|
|
|
|
)
|
2023-05-16 23:14:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
def register_expand_template_toolchains(name = "expand_template", register = True):
|
|
|
|
"""Registers expand_template toolchain and repositories
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: override the prefix for the generated toolchain repositories
|
|
|
|
register: whether to call through to native.register_toolchains.
|
|
|
|
Should be True for WORKSPACE users, but false when used under bzlmod extension
|
|
|
|
"""
|
|
|
|
for [platform, meta] in EXPAND_TEMPLATE_PLATFORMS.items():
|
|
|
|
expand_template_platform_repo(
|
|
|
|
name = "%s_%s" % (name, platform),
|
|
|
|
platform = platform,
|
|
|
|
)
|
|
|
|
if register:
|
|
|
|
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
|
|
|
|
|
|
|
|
expand_template_toolchains_repo(
|
|
|
|
name = "%s_toolchains" % name,
|
|
|
|
user_repository_name = name,
|
|
|
|
)
|