Skip to content

Commit

Permalink
[TOOLCHAIN] use aliased repos
Browse files Browse the repository at this point in the history
  • Loading branch information
hexdae committed Apr 5, 2024
1 parent e79b3b3 commit 5c75da5
Show file tree
Hide file tree
Showing 17 changed files with 1,890 additions and 81 deletions.
21 changes: 4 additions & 17 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module(
name = "toolchains_arm_gnu",
version = "0.0.1",
version = "1.0.0",
compatibility_level = 1,
)

Expand All @@ -16,29 +16,16 @@ arm_toolchain = use_extension("@toolchains_arm_gnu//:extensions.bzl", "arm_toolc
# module extension will select the version here if a consumer attempts to use
# the newer toolchain.
arm_toolchain.arm_none_eabi(version = "13.2.1-1.1")
use_repo(
arm_toolchain,
"arm_none_eabi",
"arm_none_eabi_darwin_arm64",
"arm_none_eabi_darwin_x86_64",
"arm_none_eabi_linux_aarch64",
"arm_none_eabi_linux_x86_64",
"arm_none_eabi_windows_x86_64",
)
use_repo(arm_toolchain, "arm_none_eabi")
arm_toolchain.arm_none_linux_gnueabihf(version = "13.2.1")
use_repo(
arm_toolchain,
"arm_none_linux_gnueabihf",
"arm_none_linux_gnueabihf_linux_aarch64",
"arm_none_linux_gnueabihf_linux_x86_64",
"arm_none_linux_gnueabihf_windows_x86_64",
)
use_repo(arm_toolchain, "arm_none_linux_gnueabihf")

# DEV ONLY (not needed for release)
bazel_dep(name = "aspect_bazel_lib", version = "2.0.0", dev_dependency = True)
bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True)

register_toolchains(
"//test/toolchains:all",
"@arm_none_eabi//toolchain:all",
"@arm_none_linux_gnueabihf//toolchain:all",
dev_dependency = True,
Expand Down
102 changes: 83 additions & 19 deletions MODULE.bazel.lock

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

40 changes: 39 additions & 1 deletion deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

load("@toolchains_arm_gnu//toolchain/archives:arm_none_eabi.bzl", "ARM_NONE_EABI")
load("@toolchains_arm_gnu//toolchain/archives:arm_none_linux_gnueabihf.bzl", "ARM_NONE_LINUX_GNUEABIHF")
load("@toolchains_arm_gnu//toolchain:toolchain.bzl", "tools")

def _arm_gnu_cross_hosted_platform_specific_repo_impl(repository_ctx):
"""Defines a host-specific repository for the ARM GNU toolchain."""
Expand All @@ -10,15 +11,18 @@ def _arm_gnu_cross_hosted_platform_specific_repo_impl(repository_ctx):
url = repository_ctx.attr.url,
stripPrefix = repository_ctx.attr.strip_prefix,
)

repository_ctx.template(
"BUILD.bazel",
Label("@toolchains_arm_gnu//toolchain:templates/compiler.BUILD"),
substitutions = {
"%toolchain_prefix%": repository_ctx.attr.toolchain_prefix,
"%version%": repository_ctx.attr.version.split("-")[0],
"%bin_extension%": ".exe" if "windows" in repository_ctx.name else "",
"%tools%": "{}".format(repository_ctx.attr.tools),
},
)

for patch in repository_ctx.attr.patches:
repository_ctx.patch(patch, strip = 1)

Expand All @@ -31,6 +35,8 @@ arm_gnu_cross_hosted_platform_specific_repo = repository_rule(
"version": attr.string(mandatory = True),
"strip_prefix": attr.string(),
"patches": attr.label_list(),
"tools": attr.string_list(default = tools),
"exec_compatible_with": attr.string_list(),
},
)

Expand All @@ -56,24 +62,56 @@ def _arm_gnu_toolchain_repo_impl(repository_ctx):
},
)

repository_ctx.template(
"toolchain/toolchain.bzl",
Label("@toolchains_arm_gnu//toolchain:templates/toolchain.bazel"),
substitutions = {
"%toolchain_name%": repository_ctx.attr.toolchain_name,
"%version%": repository_ctx.attr.version,
"%toolchain_prefix%": repository_ctx.attr.toolchain_prefix,
"%hosts%": "{}".format(repository_ctx.attr.hosts),
},
)

for repo in repository_ctx.attr.hosts.keys():
repository_ctx.template(
"toolchain/{}/BUILD".format(repo),
Label("@toolchains_arm_gnu//toolchain:templates/alias.BUILD"),
substitutions = {
"%repo%": repo,
"%tools%": "{}".format(repository_ctx.attr.tools),
},
)

toolchains_arm_gnu_repo = repository_rule(
implementation = _arm_gnu_toolchain_repo_impl,
attrs = {
"toolchain_name": attr.string(mandatory = True),
"toolchain_prefix": attr.string(mandatory = True),
"version": attr.string(mandatory = True),
"hosts": attr.string_list_dict(mandatory = True),
"tools": attr.string_list(default = tools),
},
)

def toolchains_arm_gnu_deps(toolchain, toolchain_prefix, version, archives):
archive = archives.get(version)

if not archive:
fail("Version {} not available in {}".format(version, archives.keys()))

toolchains_arm_gnu_repo(
name = toolchain,
toolchain_name = toolchain,
toolchain_prefix = toolchain_prefix,
version = version,
hosts = {
repo["name"]: repo["exec_compatible_with"]
for repo in archive
},
)

for attrs in archives[version]:
for attrs in archive:
arm_gnu_cross_hosted_platform_specific_repo(
toolchain_prefix = toolchain_prefix,
version = version,
Expand Down
20 changes: 3 additions & 17 deletions examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,12 @@ local_path_override(

arm_toolchain = use_extension("@toolchains_arm_gnu//:extensions.bzl", "arm_toolchain")
arm_toolchain.arm_none_eabi(version = "13.2.1")
use_repo(
arm_toolchain,
"arm_none_eabi",
"arm_none_eabi_darwin_arm64",
"arm_none_eabi_darwin_x86_64",
"arm_none_eabi_linux_aarch64",
"arm_none_eabi_linux_x86_64",
"arm_none_eabi_windows_x86_64",
)
use_repo(arm_toolchain, "arm_none_eabi")
arm_toolchain.arm_none_linux_gnueabihf(version = "13.2.1")
use_repo(
arm_toolchain,
"arm_none_linux_gnueabihf",
"arm_none_linux_gnueabihf_linux_aarch64",
"arm_none_linux_gnueabihf_linux_x86_64",
"arm_none_linux_gnueabihf_windows_x86_64",
)
use_repo(arm_toolchain, "arm_none_linux_gnueabihf")

register_toolchains(
"//custom/toolchain:all",
"@arm_none_eabi//toolchain:all",
"@arm_none_linux_gnueabihf//toolchain:all",
"//custom/toolchain:all",
)
Loading

0 comments on commit 5c75da5

Please sign in to comment.