mirror of
https://github.com/bazel-contrib/bazel-lib
synced 2024-11-26 13:30:30 +00:00
104 lines
4.2 KiB
Python
104 lines
4.2 KiB
Python
"Macros for loading dependencies and registering toolchains"
|
|
|
|
load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive")
|
|
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
|
|
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")
|
|
load("//lib/private:local_config_platform.bzl", "local_config_platform")
|
|
|
|
# Don't wrap later calls with maybe() as that prevents renovate from parsing our deps
|
|
def http_archive(name, **kwargs):
|
|
maybe(_http_archive, name = name, **kwargs)
|
|
|
|
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.
|
|
"""
|
|
http_archive(
|
|
name = "bazel_skylib",
|
|
sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728",
|
|
urls = [
|
|
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
|
|
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
|
|
],
|
|
)
|
|
|
|
http_archive(
|
|
name = "socat",
|
|
build_file = "socat.BUILD",
|
|
sha256 = "d697245144731423ddbbceacabbd29447089ea223e9a439b28f9ff90d0dd216e",
|
|
strip_prefix = "socat-1.7.4.3",
|
|
urls = ["http://www.dest-unreach.org/socat/download/socat-1.7.4.3.tar.gz"],
|
|
)
|
|
|
|
http_archive(
|
|
name = "rules_foreign_cc",
|
|
sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
|
|
strip_prefix = "rules_foreign_cc-0.9.0",
|
|
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
|
|
)
|
|
|
|
if override_local_config_platform:
|
|
local_config_platform(
|
|
name = "local_config_platform",
|
|
)
|
|
|
|
# Re-export the default versions
|
|
DEFAULT_JQ_VERSION = _DEFAULT_JQ_VERSION
|
|
DEFAULT_YQ_VERSION = _DEFAULT_YQ_VERSION
|
|
|
|
def register_jq_toolchains(name = "jq", version = DEFAULT_JQ_VERSION, register = True):
|
|
"""Registers jq toolchain and repositories
|
|
|
|
Args:
|
|
name: override the prefix for the generated toolchain repositories
|
|
version: the version of jq to execute (see https://github.com/stedolan/jq/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 JQ_PLATFORMS.items():
|
|
jq_platform_repo(
|
|
name = "%s_%s" % (name, platform),
|
|
platform = platform,
|
|
version = version,
|
|
)
|
|
if register:
|
|
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
|
|
|
|
jq_host_alias_repo(name = name)
|
|
|
|
jq_toolchains_repo(
|
|
name = "%s_toolchains" % name,
|
|
user_repository_name = name,
|
|
)
|
|
|
|
def register_yq_toolchains(name = "yq", version = DEFAULT_YQ_VERSION, register = True):
|
|
"""Registers yq toolchain and repositories
|
|
|
|
Args:
|
|
name: override the prefix for the generated toolchain repositories
|
|
version: the version of yq to execute (see https://github.com/mikefarah/yq/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 YQ_PLATFORMS.items():
|
|
yq_platform_repo(
|
|
name = "%s_%s" % (name, platform),
|
|
platform = platform,
|
|
version = version,
|
|
)
|
|
if register:
|
|
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
|
|
|
|
yq_host_alias_repo(name = name)
|
|
|
|
yq_toolchains_repo(
|
|
name = "%s_toolchains" % name,
|
|
user_repository_name = name,
|
|
)
|