diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index c1a26f6..9839fae 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -851,7 +851,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_toolchain": { "general": { - "bzlTransitiveDigest": "5uCK07Csa3uEOK6aGuYNpT97C+qTU4KuIVR/EzZ3vXk=", + "bzlTransitiveDigest": "vVLbMp7KKsm27vV6ej3jinCYCZ198Kc5G5a1T5A0zac=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -864,8 +864,7 @@ "name": "_main~arm_toolchain~arm_none_eabi_windows_x86_64", "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-win32-x64.zip", "sha256": "56b18ccb0a50f536332ec5de57799342ff0cd005ca2c54288c74759b51929e4f", - "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1", - "bin_extension": ".exe" + "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1" } }, "arm_none_linux_gnueabihf_linux_x86_64": { @@ -892,8 +891,7 @@ "name": "_main~arm_toolchain~arm_none_eabi_darwin_arm64", "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-darwin-arm64.tar.gz", "sha256": "d4ce0de062420daab140161086ba017642365977e148d20f55a8807b1eacd703", - "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1", - "bin_extension": "" + "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1" } }, "arm_none_linux_gnueabihf_linux_aarch64": { @@ -923,8 +921,7 @@ "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-mingw-w64-i686-arm-none-linux-gnueabihf.zip?rev=14b6dd20622a4beabb60a6ee41a4c141&hash=C1F9FA6DE8259B5ACA0211139F4304F2B942E489", "patches": [ "@@//toolchain:patches/0001-Resolve-libc-relative-to-sysroot.patch" - ], - "bin_extension": ".exe" + ] } }, "arm_none_eabi": { @@ -946,8 +943,7 @@ "name": "_main~arm_toolchain~arm_none_eabi_linux_x86_64", "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-linux-x64.tar.gz", "sha256": "1252a8cafe9237de27a765376697230368eec21db44dc3f1edeb8d838dabd530", - "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1", - "bin_extension": "" + "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1" } }, "arm_none_eabi_darwin_x86_64": { @@ -959,8 +955,7 @@ "name": "_main~arm_toolchain~arm_none_eabi_darwin_x86_64", "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-darwin-x64.tar.gz", "sha256": "1ecc0fd6c31020aff702204f51459b4b00ff0d12b9cd95e832399881d819aa57", - "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1", - "bin_extension": "" + "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1" } }, "arm_none_linux_gnueabihf": { @@ -982,8 +977,7 @@ "name": "_main~arm_toolchain~arm_none_eabi_linux_aarch64", "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-linux-arm64.tar.gz", "sha256": "ab7f75d95ead0b1efb7432e7f034f9575cc3d23dc1b03d41af1ec253486d19de", - "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1", - "bin_extension": "" + "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1" } } }, diff --git a/deps.bzl b/deps.bzl index 113a7b5..49f9163 100644 --- a/deps.bzl +++ b/deps.bzl @@ -16,7 +16,7 @@ def _arm_gnu_cross_hosted_platform_specific_repo_impl(repository_ctx): substitutions = { "%toolchain_prefix%": repository_ctx.attr.toolchain_prefix, "%version%": repository_ctx.attr.version.split("-")[0], - "%bin_extension%": repository_ctx.attr.bin_extension, + "%bin_extension%": ".exe" if "windows" in repository_ctx.name else "", }, ) for patch in repository_ctx.attr.patches: @@ -31,7 +31,6 @@ arm_gnu_cross_hosted_platform_specific_repo = repository_rule( "version": attr.string(mandatory = True), "strip_prefix": attr.string(), "patches": attr.label_list(), - "bin_extension": attr.string(default = ""), }, ) diff --git a/toolchain/archives/README.md b/toolchain/archives/README.md index 12f9a0e..f8a7bce 100644 --- a/toolchain/archives/README.md +++ b/toolchain/archives/README.md @@ -9,3 +9,9 @@ The toolchains can be autogenerated from github for convenience ```bash bazel run //toolchain/archives:generate --toolchain ``` + +For example to generate `arm-none-eabi` releases + +```bash +bazel run //toolchain/archives:generate -- --toolchain=arm-none-eabi --releases=3 >> toolchain/archives/arm_none_eabi.bzl +``` diff --git a/toolchain/archives/arm_none_eabi.bzl b/toolchain/archives/arm_none_eabi.bzl index 9469a99..65974e8 100644 --- a/toolchain/archives/arm_none_eabi.bzl +++ b/toolchain/archives/arm_none_eabi.bzl @@ -30,7 +30,6 @@ ARM_NONE_EABI = { "name": "arm_none_eabi_windows_x86_64", "sha256": "e4c964add8d0fdcc6b14f323e277a0946456082a84a1cc560da265b357762b62", "url": "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-win32.zip?revision=20c5df9c-9870-47e2-b994-2a652fb99075&la=en&hash=347C07EEEB848CC8944F943D8E1EAAB55A6CA0BC", - "bin_extension": ".exe", }, ], "13.2.1": [ @@ -63,44 +62,103 @@ ARM_NONE_EABI = { "sha256": "51d933f00578aa28016c5e3c84f94403274ea7915539f8e56c13e2196437d18f", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-mingw-w64-i686-arm-none-eabi.zip?rev=93fda279901c4c0299e03e5c4899b51f&hash=A3C5FF788BE90810E121091C873E3532336C8D46", - "bin_extension": ".exe", }, ], +} | { + "12.3.1-1.1": [ + { + "name": "arm_none_eabi_darwin_arm64", + "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v12.3.1-1.1/xpack-arm-none-eabi-gcc-12.3.1-1.1-darwin-arm64.tar.gz", + "sha256": "fc943971a9c52fe67992b9bcde618df96f08c2cf7ab75b1c487dcfa5e0ef34d1", + "strip_prefix": "xpack-arm-none-eabi-gcc-12.3.1-1.1" + }, + { + "name": "arm_none_eabi_darwin_x86_64", + "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v12.3.1-1.1/xpack-arm-none-eabi-gcc-12.3.1-1.1-darwin-x64.tar.gz", + "sha256": "62e6146ec1bbd86ee92df97f74075c895ebf4ad36b0a05e3d38ae662c9e7a2ab", + "strip_prefix": "xpack-arm-none-eabi-gcc-12.3.1-1.1" + }, + { + "name": "arm_none_eabi_linux_aarch64", + "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v12.3.1-1.1/xpack-arm-none-eabi-gcc-12.3.1-1.1-linux-arm64.tar.gz", + "sha256": "f833298bda3545e9303198463839bc156b6aef3d340ca55c109666e3f6a1f3a0", + "strip_prefix": "xpack-arm-none-eabi-gcc-12.3.1-1.1" + }, + { + "name": "arm_none_eabi_linux_x86_64", + "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v12.3.1-1.1/xpack-arm-none-eabi-gcc-12.3.1-1.1-linux-x64.tar.gz", + "sha256": "83b869765862bcf029966c82a258d9b330878e2570a277d82fc90af5e88077a4", + "strip_prefix": "xpack-arm-none-eabi-gcc-12.3.1-1.1" + }, + { + "name": "arm_none_eabi_windows_x86_64", + "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v12.3.1-1.1/xpack-arm-none-eabi-gcc-12.3.1-1.1-win32-x64.zip", + "sha256": "dcd941678c49b780869db94d5ad3f036b1f18003b968b8ab62af04648b265e92", + "strip_prefix": "xpack-arm-none-eabi-gcc-12.3.1-1.1" + } + ], + "12.3.1-1.2": [ + { + "name": "arm_none_eabi_darwin_arm64", + "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v12.3.1-1.2/xpack-arm-none-eabi-gcc-12.3.1-1.2-darwin-arm64.tar.gz", + "sha256": "507926ba1e37e6fcae2a7499559cffd6da015b93145ff7657aafca9ef097d683", + "strip_prefix": "xpack-arm-none-eabi-gcc-12.3.1-1.2" + }, + { + "name": "arm_none_eabi_darwin_x86_64", + "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v12.3.1-1.2/xpack-arm-none-eabi-gcc-12.3.1-1.2-darwin-x64.tar.gz", + "sha256": "a90e6d0cb74c61e8d06e586f32bcd1983789da15808a8aa64658c1f5e892d2dc", + "strip_prefix": "xpack-arm-none-eabi-gcc-12.3.1-1.2" + }, + { + "name": "arm_none_eabi_linux_aarch64", + "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v12.3.1-1.2/xpack-arm-none-eabi-gcc-12.3.1-1.2-linux-arm64.tar.gz", + "sha256": "35fadc858f3551f789d87760eb40ad04f893a23936f5090a138e7de6cd04d939", + "strip_prefix": "xpack-arm-none-eabi-gcc-12.3.1-1.2" + }, + { + "name": "arm_none_eabi_linux_x86_64", + "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v12.3.1-1.2/xpack-arm-none-eabi-gcc-12.3.1-1.2-linux-x64.tar.gz", + "sha256": "771dfb9d10e7339ac40f3a32be9cd287405c537ca0bf16e1dbf6fa6f1fc1dd2a", + "strip_prefix": "xpack-arm-none-eabi-gcc-12.3.1-1.2" + }, + { + "name": "arm_none_eabi_windows_x86_64", + "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v12.3.1-1.2/xpack-arm-none-eabi-gcc-12.3.1-1.2-win32-x64.zip", + "sha256": "cb5e2be31fcfc7c78390041efc5602f22266f21ed968443827898fa4c47c6f20", + "strip_prefix": "xpack-arm-none-eabi-gcc-12.3.1-1.2" + } + ], "13.2.1-1.1": [ { "name": "arm_none_eabi_darwin_arm64", "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-darwin-arm64.tar.gz", "sha256": "d4ce0de062420daab140161086ba017642365977e148d20f55a8807b1eacd703", - "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1", - "bin_extension": "", + "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1" }, { "name": "arm_none_eabi_darwin_x86_64", "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-darwin-x64.tar.gz", "sha256": "1ecc0fd6c31020aff702204f51459b4b00ff0d12b9cd95e832399881d819aa57", - "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1", - "bin_extension": "", + "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1" }, { "name": "arm_none_eabi_linux_aarch64", "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-linux-arm64.tar.gz", "sha256": "ab7f75d95ead0b1efb7432e7f034f9575cc3d23dc1b03d41af1ec253486d19de", - "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1", - "bin_extension": "", + "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1" }, { "name": "arm_none_eabi_linux_x86_64", "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-linux-x64.tar.gz", "sha256": "1252a8cafe9237de27a765376697230368eec21db44dc3f1edeb8d838dabd530", - "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1", - "bin_extension": "", + "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1" }, { "name": "arm_none_eabi_windows_x86_64", "url": "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v13.2.1-1.1/xpack-arm-none-eabi-gcc-13.2.1-1.1-win32-x64.zip", "sha256": "56b18ccb0a50f536332ec5de57799342ff0cd005ca2c54288c74759b51929e4f", - "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1", - "bin_extension": ".exe", - }, - ], + "strip_prefix": "xpack-arm-none-eabi-gcc-13.2.1-1.1" + } + ] } diff --git a/toolchain/archives/arm_none_linux_gnueabihf.bzl b/toolchain/archives/arm_none_linux_gnueabihf.bzl index 46d8650..c99dd05 100644 --- a/toolchain/archives/arm_none_linux_gnueabihf.bzl +++ b/toolchain/archives/arm_none_linux_gnueabihf.bzl @@ -22,7 +22,6 @@ ARM_NONE_LINUX_GNUEABIHF = { "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-linux-gnueabihf", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-mingw-w64-i686-arm-none-linux-gnueabihf.zip?rev=14b6dd20622a4beabb60a6ee41a4c141&hash=C1F9FA6DE8259B5ACA0211139F4304F2B942E489", "patches": ["@toolchains_arm_gnu//toolchain:patches/0001-Resolve-libc-relative-to-sysroot.patch"], - "bin_extension": ".exe", }, ], } diff --git a/toolchain/archives/generate.py b/toolchain/archives/generate.py index 22e7f7e..73be847 100644 --- a/toolchain/archives/generate.py +++ b/toolchain/archives/generate.py @@ -3,13 +3,13 @@ import argparse import urllib.request import json - +import os XPACK = { "owner": "xpack-dev-tools", "repo": "{prefix}-gcc-xpack", - "url": "https://github.com/xpack-dev-tools/{prefix}-gcc-xpack/releases/download/v{version}/xpack-{prefix}-gcc-{version}-{os}.{ext}", - "sha_url": "https://github.com/xpack-dev-tools/{prefix}-gcc-xpack/releases/download/v{version}/xpack-{prefix}-gcc-{version}-{os}.{ext}.sha", + "url": "https://github.com/xpack-dev-tools/{prefix}-gcc-xpack/releases/download/v{version}/xpack-{prefix}-gcc-{version}-{system}.{ext}", + "sha_url": "https://github.com/xpack-dev-tools/{prefix}-gcc-xpack/releases/download/v{version}/xpack-{prefix}-gcc-{version}-{system}.{ext}.sha", "strip": "xpack-{prefix}-gcc-{version}", } @@ -28,6 +28,7 @@ def download_sha(url): + """Download the SHA256 checksum of a file from a given URL""" try: with urllib.request.urlopen(url) as response: if response.getcode() == 200: @@ -37,18 +38,21 @@ def download_sha(url): def github_release_tags(owner, repo, count=1): + """Get the latest release tags from a GitHub repository""" releases_url = f"https://api.github.com/repos/{owner}/{repo}/releases" response = urllib.request.urlopen(releases_url) releases = json.loads(response.read().decode()) - return [release["tag_name"][1:] for release in releases[:count]] + return [release["tag_name"][1:] for release in reversed(releases[:count])] + -def generate_archive(name, prefix, version, os, template): +def generate_archive(name, prefix, version, system, template): + """Generate an archive dictionary for a given toolchain""" info = { "prefix": prefix, "version": version, - "os": os, - "ext": "zip" if "win32" in os else "tar.gz", + "system": system, + "ext": "zip" if "win32" in system else "tar.gz", } url = template["url"].format(**info) sha256 = download_sha(template["sha_url"].format(**info)) @@ -57,21 +61,21 @@ def generate_archive(name, prefix, version, os, template): "url": url, "sha256": sha256, "strip_prefix": template["strip"].format(**info), - "bin_extension": ".exe" if "win32" in os else "", } def generate_release(name, prefix, hosts, template, releases): + """Generate a release dictionary for a given toolchain""" return { version: [ generate_archive( name=f"{name}_{host}", prefix=prefix, version=version, - os=os, + system=system, template=template, ) - for host, os in hosts.items() + for host, system in hosts.items() ] for version in github_release_tags( owner=template["owner"], @@ -82,14 +86,20 @@ def generate_release(name, prefix, hosts, template, releases): def main(): + """Main function to generate and print release information""" parser = argparse.ArgumentParser() parser.add_argument("--toolchain", choices=["arm-none-eabi"]) - parser.add_argument("--releases", default=1) + parser.add_argument("--releases", default=1, type=int) args = parser.parse_args() + # Make the script well behaved when running under bazel + if os.environ.get("BUILD_WORKING_DIRECTORY"): + os.chdir(os.environ["BUILD_WORKING_DIRECTORY"]) + if args.toolchain == "arm-none-eabi": release = generate_release(**ARM_NONE_EABI, releases=args.releases) print(json.dumps(release, indent=4)) + if __name__ == "__main__": main()