2021-12-09 00:47:45 +00:00
|
|
|
"Macros for loading dependencies and registering toolchains"
|
|
|
|
|
2023-10-05 21:22:38 +00:00
|
|
|
load("//lib:utils.bzl", http_archive = "maybe_http_archive")
|
2023-09-29 21:42:33 +00:00
|
|
|
load("//lib/private:copy_directory_toolchain.bzl", "COPY_DIRECTORY_PLATFORMS", "copy_directory_platform_repo", "copy_directory_toolchains_repo")
|
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-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")
|
2023-09-29 21:42:33 +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")
|
2023-09-24 22:06:10 +00:00
|
|
|
load("//lib/private:source_toolchains_repo.bzl", "source_toolchains_repo")
|
2023-10-03 20:00:58 +00:00
|
|
|
load("//lib/private:tar_toolchain.bzl", "BSDTAR_PLATFORMS", "bsdtar_binary_repo", "tar_toolchains_repo")
|
2023-09-29 21:42:33 +00:00
|
|
|
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-09-24 22:06:10 +00:00
|
|
|
load("//tools:version.bzl", "VERSION")
|
2022-06-10 20:58:40 +00:00
|
|
|
|
2023-01-07 19:26:27 +00:00
|
|
|
# buildifier: disable=unnamed-macro
|
2023-10-05 21:22:38 +00:00
|
|
|
def aspect_bazel_lib_dependencies():
|
|
|
|
"Load dependencies required by aspect rules"
|
2022-06-10 20:58:40 +00:00
|
|
|
http_archive(
|
|
|
|
name = "bazel_skylib",
|
2023-06-13 05:16:56 +00:00
|
|
|
sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa",
|
2022-06-10 20:58:40 +00:00
|
|
|
urls = [
|
2023-06-13 05:16:56 +00:00
|
|
|
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
|
|
|
|
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
|
2022-06-10 20:58:40 +00:00
|
|
|
],
|
|
|
|
)
|
2021-12-09 00:47:45 +00:00
|
|
|
|
2023-10-10 19:16:13 +00:00
|
|
|
DEFAULT_JQ_REPOSITORY = "jq"
|
2022-04-23 19:06:40 +00:00
|
|
|
DEFAULT_JQ_VERSION = _DEFAULT_JQ_VERSION
|
|
|
|
|
2023-10-10 19:16:13 +00:00
|
|
|
def register_jq_toolchains(name = DEFAULT_JQ_REPOSITORY, 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
|
|
|
|
2023-10-10 19:16:13 +00:00
|
|
|
DEFAULT_YQ_REPOSITORY = "yq"
|
|
|
|
DEFAULT_YQ_VERSION = _DEFAULT_YQ_VERSION
|
|
|
|
|
|
|
|
def register_yq_toolchains(name = DEFAULT_YQ_REPOSITORY, 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,
|
2023-10-03 20:00:58 +00:00
|
|
|
user_repository_name = name,
|
|
|
|
)
|
|
|
|
|
2023-10-10 19:16:13 +00:00
|
|
|
DEFAULT_TAR_REPOSITORY = "bsd_tar"
|
|
|
|
|
|
|
|
def register_tar_toolchains(name = DEFAULT_TAR_REPOSITORY, register = True):
|
2023-10-03 20:00:58 +00:00
|
|
|
"""Registers bsdtar 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 BSDTAR_PLATFORMS.items():
|
|
|
|
bsdtar_binary_repo(
|
|
|
|
name = "%s_%s" % (name, platform),
|
|
|
|
platform = platform,
|
|
|
|
)
|
|
|
|
if register:
|
|
|
|
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
|
|
|
|
|
|
|
|
tar_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-10-10 19:16:13 +00:00
|
|
|
DEFAULT_COREUTILS_REPOSITORY = "coreutils"
|
|
|
|
DEFAULT_COREUTILS_VERSION = _DEFAULT_COREUTILS_VERSION
|
|
|
|
|
|
|
|
def register_coreutils_toolchains(name = DEFAULT_COREUTILS_REPOSITORY, version = DEFAULT_COREUTILS_VERSION, register = True):
|
2023-01-16 18:02:17 +00:00
|
|
|
"""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-10-10 19:16:13 +00:00
|
|
|
DEFAULT_COPY_DIRECTORY_REPOSITORY = "copy_directory"
|
|
|
|
|
|
|
|
def register_copy_directory_toolchains(name = DEFAULT_COPY_DIRECTORY_REPOSITORY, register = True):
|
2023-01-17 01:19:13 +00:00
|
|
|
"""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
|
|
|
|
"""
|
2023-09-24 22:06:10 +00:00
|
|
|
if VERSION == "0.0.0":
|
|
|
|
source_toolchains_repo(
|
|
|
|
name = "%s_toolchains" % name,
|
|
|
|
toolchain_type = "@aspect_bazel_lib//lib:copy_directory_toolchain_type",
|
|
|
|
toolchain_rule_load_from = "@aspect_bazel_lib//lib/private:copy_directory_toolchain.bzl",
|
|
|
|
toolchain_rule = "copy_directory_toolchain",
|
|
|
|
binary = "@aspect_bazel_lib//tools/copy_directory",
|
|
|
|
)
|
|
|
|
if register:
|
|
|
|
native.register_toolchains("@%s_toolchains//:toolchain" % name)
|
|
|
|
return
|
|
|
|
|
2023-01-17 01:19:13 +00:00
|
|
|
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-10-10 19:16:13 +00:00
|
|
|
DEFAULT_COPY_TO_DIRECTORY_REPOSITORY = "copy_to_directory"
|
|
|
|
|
|
|
|
def register_copy_to_directory_toolchains(name = DEFAULT_COPY_TO_DIRECTORY_REPOSITORY, register = True):
|
2023-01-07 19:26:27 +00:00
|
|
|
"""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
|
|
|
|
"""
|
2023-09-24 22:06:10 +00:00
|
|
|
if VERSION == "0.0.0":
|
|
|
|
source_toolchains_repo(
|
|
|
|
name = "%s_toolchains" % name,
|
|
|
|
toolchain_type = "@aspect_bazel_lib//lib:copy_to_directory_toolchain_type",
|
|
|
|
toolchain_rule_load_from = "@aspect_bazel_lib//lib/private:copy_to_directory_toolchain.bzl",
|
|
|
|
toolchain_rule = "copy_to_directory_toolchain",
|
|
|
|
binary = "@aspect_bazel_lib//tools/copy_to_directory",
|
|
|
|
)
|
|
|
|
if register:
|
|
|
|
native.register_toolchains("@%s_toolchains//:toolchain" % name)
|
|
|
|
return
|
|
|
|
|
2023-01-07 19:26:27 +00:00
|
|
|
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
|
|
|
|
2023-10-10 19:16:13 +00:00
|
|
|
DEFAULT_EXPAND_TEMPLATE_REPOSITORY = "expand_template"
|
|
|
|
|
|
|
|
def register_expand_template_toolchains(name = DEFAULT_EXPAND_TEMPLATE_REPOSITORY, register = True):
|
2023-05-16 23:14:50 +00:00
|
|
|
"""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
|
|
|
|
"""
|
2023-09-24 22:06:10 +00:00
|
|
|
if VERSION == "0.0.0":
|
|
|
|
source_toolchains_repo(
|
|
|
|
name = "%s_toolchains" % name,
|
|
|
|
toolchain_type = "@aspect_bazel_lib//lib:expand_template_toolchain_type",
|
|
|
|
toolchain_rule_load_from = "@aspect_bazel_lib//lib/private:expand_template_toolchain.bzl",
|
|
|
|
toolchain_rule = "expand_template_toolchain",
|
|
|
|
binary = "@aspect_bazel_lib//tools/expand_template",
|
|
|
|
)
|
|
|
|
if register:
|
|
|
|
native.register_toolchains("@%s_toolchains//:toolchain" % name)
|
|
|
|
return
|
|
|
|
|
2023-05-16 23:14:50 +00:00
|
|
|
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,
|
|
|
|
)
|
2023-10-10 19:16:13 +00:00
|
|
|
|
|
|
|
# buildifier: disable=unnamed-macro
|
|
|
|
def aspect_bazel_lib_register_toolchains():
|
|
|
|
"""Register all bazel-lib toolchains at their default versions.
|
|
|
|
|
|
|
|
To be more selective about which toolchains and versions to register,
|
|
|
|
call the individual toolchain registration macros.
|
|
|
|
"""
|
|
|
|
register_copy_directory_toolchains()
|
|
|
|
register_copy_to_directory_toolchains()
|
|
|
|
register_expand_template_toolchains()
|
|
|
|
register_coreutils_toolchains()
|
|
|
|
register_jq_toolchains()
|
|
|
|
register_yq_toolchains()
|
|
|
|
register_tar_toolchains()
|