Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: declare and register regctl toolchains only for compatible platforms #692

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions oci/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ regctl_toolchain(
"""
REGCTL_VERSION = "v0.7.0"

REGCTL_PLATFORMS = {
name: platform
for name, platform in PLATFORMS.items()
if name.replace("_", "-") in REGCTL_VERSIONS[REGCTL_VERSION].keys()
}

def _regctl_repo_impl(rctx):
platform = rctx.attr.platform.replace("_", "-")
ext = ".exe" if platform.startswith("windows") else ""
Expand All @@ -83,7 +89,7 @@ regctl_repositories = repository_rule(
_regctl_repo_impl,
doc = "Fetch external tools needed for regctl toolchain",
attrs = {
"platform": attr.string(mandatory = True, values = PLATFORMS.keys()),
"platform": attr.string(mandatory = True, values = REGCTL_PLATFORMS.keys()),
},
)

Expand All @@ -107,9 +113,11 @@ def oci_register_toolchains(name, register = True):
register_coreutils_toolchains(register = register)
register_copy_to_directory_toolchains(register = register)
register_zstd_toolchains(register = register)
register_crane_toolchains(name, register = register)
register_regctl_toolchains(name, register = register)

def register_crane_toolchains(name, register = True):
crane_toolchain_name = "{name}_crane_toolchains".format(name = name)
regctl_toolchain_name = "{name}_regctl_toolchains".format(name = name)

for platform in PLATFORMS.keys():
crane_repositories(
Expand All @@ -118,14 +126,8 @@ def oci_register_toolchains(name, register = True):
crane_version = CRANE_VERSIONS.keys()[0],
)

regctl_repositories(
name = "{name}_regctl_{platform}".format(name = name, platform = platform),
platform = platform,
)

if register:
native.register_toolchains("@{}//:{}_toolchain".format(crane_toolchain_name, platform))
native.register_toolchains("@{}//:{}_toolchain".format(regctl_toolchain_name, platform))

toolchains_repo(
name = crane_toolchain_name,
Expand All @@ -134,6 +136,18 @@ def oci_register_toolchains(name, register = True):
toolchain = "@%s_crane_{platform}//:crane_toolchain" % name,
)

def register_regctl_toolchains(name, register = True):
regctl_toolchain_name = "{name}_regctl_toolchains".format(name = name)

for platform in REGCTL_PLATFORMS.keys():
regctl_repositories(
name = "{name}_regctl_{platform}".format(name = name, platform = platform),
platform = platform,
)

if register:
native.register_toolchains("@{}//:{}_toolchain".format(regctl_toolchain_name, platform))

toolchains_repo(
name = regctl_toolchain_name,
toolchain_type = "@rules_oci//oci:regctl_toolchain_type",
Expand Down
Loading