Skip to content

Commit

Permalink
[EXT] more explicit toolchain mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
hexdae committed Apr 4, 2024
1 parent 6bee9b7 commit ba33f39
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 22 additions & 7 deletions extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def _semver(version):
patch = parts[2],
)

def _module_toolchain(tag, deps):
"""Return a module toolchain."""
return struct(
tag = tag,
deps = deps,
)

def _compare_versions(left, right):
"""Compare two semantic versions."""
left = _semver(left)
Expand All @@ -37,16 +44,24 @@ def _minimal_supported_version(versions):
return minimum

def _arm_toolchain_impl(ctx):
tag_deps = {
lambda mod: mod.tags.arm_none_eabi: arm_none_eabi_deps,
lambda mod: mod.tags.arm_none_linux_gnueabihf: arm_none_linux_gnueabihf_deps,
}
"""Implement the module extension."""

available_toolchains = [
_module_toolchain(
tag = lambda mod: mod.tags.arm_none_eabi,
deps = arm_none_eabi_deps,
),
_module_toolchain(
tag = lambda mod: mod.tags.arm_none_linux_gnueabihf,
deps = arm_none_linux_gnueabihf_deps,
),
]

for tag, deps in tag_deps.items():
versions = [attr.version for mod in ctx.modules for attr in tag(mod)]
for toolchain in available_toolchains:
versions = [attr.version for mod in ctx.modules for attr in toolchain.tag(mod)]
selected = _minimal_supported_version(versions)
if selected:
deps(version = selected)
toolchain.deps(version = selected)

_toolchain = tag_class(attrs = {
"version": attr.string(),
Expand Down

0 comments on commit ba33f39

Please sign in to comment.