From 345bf59c0fd5524df21018d15b869fb50e6e968f Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sat, 2 Mar 2024 15:06:33 -0600 Subject: [PATCH 01/23] Manage 'target constraints' instead of just compatible cpus Previously, there was a list of compatible CPUs that were used to form the target constraints for the toolchain. Now, however, we need to distinguish toolchains on more than just @platforms//cpu, so manage these as a collection of constraint values instead. --- MODULE.bazel.lock | 2 +- deps.bzl | 8 ++++++-- toolchain/BUILD | 9 +++------ toolchain/toolchain.bzl | 16 +++++++++------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 440c8d0..334984d 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -832,7 +832,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_none_eabi": { "general": { - "bzlTransitiveDigest": "TBXaznRVLACieywI746foE9heDPOJCL7pDKibX+RJEc=", + "bzlTransitiveDigest": "fYpi3tKiM0IlfOvA6pDvDlh/SMJHrGgcqub2jKC3ry4=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { diff --git a/deps.bzl b/deps.bzl index c72155b..39b8a8a 100644 --- a/deps.bzl +++ b/deps.bzl @@ -1,7 +1,11 @@ """deps.bzl""" load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@arm_none_eabi//toolchain:toolchain.bzl", "compatible_cpus", "register_arm_none_eabi_toolchain") +load( + "@arm_none_eabi//toolchain:toolchain.bzl", + "target_constraints", + "register_arm_none_eabi_toolchain" +) GCC = { "9.2.1": [ @@ -75,5 +79,5 @@ def arm_none_eabi_deps(version = "9.2.1", archives = GCC): http_archive(**attrs) def register_default_arm_none_eabi_toolchains(): - for cpu in compatible_cpus: + for cpu in target_constraints['arm-none-eabi']: register_arm_none_eabi_toolchain("//toolchain:{}".format(cpu)) diff --git a/toolchain/BUILD b/toolchain/BUILD index 12de4b3..2ea9d15 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -1,14 +1,11 @@ # toolchain/BUILD -load("@arm_none_eabi//toolchain:toolchain.bzl", "arm_none_eabi_toolchain", "compatible_cpus") +load("@arm_none_eabi//toolchain:toolchain.bzl", "arm_none_eabi_toolchain", "target_constraints") [ arm_none_eabi_toolchain( name = name, - target_compatible_with = [ - "@platforms//os:none", - platform, - ], + target_compatible_with = constraints, ) - for name, platform in compatible_cpus.items() + for name, constraints in target_constraints['arm-none-eabi'].items() ] diff --git a/toolchain/toolchain.bzl b/toolchain/toolchain.bzl index 96d1a56..f2582bc 100644 --- a/toolchain/toolchain.bzl +++ b/toolchain/toolchain.bzl @@ -21,13 +21,15 @@ tools = [ "size", ] -compatible_cpus = { - "arm": "@platforms//cpu:arm", - "armv6-m": "@platforms//cpu:armv6-m", - "armv7-m": "@platforms//cpu:armv7-m", - "armv7e-m": "@platforms//cpu:armv7e-m", - "armv7e-mf": "@platforms//cpu:armv7e-mf", - "armv8-m": "@platforms//cpu:armv8-m", +target_constraints = { + "arm-none-eabi": { + "arm": ["@platforms//os:none", "@platforms//cpu:arm"], + "armv6-m": ["@platforms//os:none", "@platforms//cpu:armv6-m"], + "armv7-m": ["@platforms//os:none", "@platforms//cpu:armv7-m"], + "armv7e-m": ["@platforms//os:none", "@platforms//cpu:armv7e-m"], + "armv7e-mf": ["@platforms//os:none", "@platforms//cpu:armv7e-mf"], + "armv8-m": ["@platforms//os:none", "@platforms//cpu:armv8-m"], + }, } hosts = { From d50437c0c199ff3b927c8f0505d412cdb91b2f4a Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sat, 2 Mar 2024 16:03:30 -0600 Subject: [PATCH 02/23] Rename module to arm_gnu_toolchain This commit renames the module to arm_gnu_toolchain from arm_none_eabi. API-compatibility is _mostly_ retained through the new top-level repository generation mechanism. Using this module to configure an arm-none-eabi toolchain results in the generation of an external repository called @arm_none_eabi. In this way, clients can still rely on tools and targets that were previously defined by the old module. Consumers must now import module extensions and repository rules from the new module, however. See the updated README.md for more information. --- BUILD | 26 ---------------------- MODULE.bazel | 11 +++++----- MODULE.bazel.lock | 38 ++++++++++++++++++++------------- README.md | 8 +++---- deps.bzl | 35 ++++++++++++++++++++++-------- examples/custom/toolchain/BUILD | 2 +- extensions.bzl | 10 ++++----- toolchain/BUILD | 11 ---------- toolchain/compiler/nix.BUILD | 2 +- toolchain/compiler/win.BUILD | 2 +- toolchain/toolchain.BUILD | 13 +++++++++++ toolchain/toolchain.bzl | 2 +- toolchain/top.BUILD | 30 ++++++++++++++++++++++++++ 13 files changed, 111 insertions(+), 79 deletions(-) create mode 100644 toolchain/toolchain.BUILD create mode 100644 toolchain/top.BUILD diff --git a/BUILD b/BUILD index c32ddfc..e69de29 100644 --- a/BUILD +++ b/BUILD @@ -1,26 +0,0 @@ -# BUILD - -load("//toolchain:toolchain.bzl", "hosts", "tools") - -package(default_visibility = ["//visibility:public"]) - -TOOLS = tools + ["bin"] - -[ - config_setting( - name = host, - constraint_values = constraint_values, - ) - for host, constraint_values in hosts.items() -] - -[ - filegroup( - name = tool, - srcs = select({ - host: ["@arm_none_eabi_{}//:{}".format(host, tool)] - for host in hosts.keys() - }), - ) - for tool in TOOLS -] diff --git a/MODULE.bazel b/MODULE.bazel index 6a06198..d37c1d6 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,15 +1,16 @@ module( - name = "arm_none_eabi", + name = "arm_gnu_toolchain", version = "1.0.0", compatibility_level = 1, ) bazel_dep(name = "platforms", version = "0.0.8") -arm_none_eabi_gcc = use_extension("@arm_none_eabi//:extensions.bzl", "arm_none_eabi") -arm_none_eabi_gcc.toolchain(version = "9.2.1") +arm_gnu_gcc = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_gnu") +arm_gnu_gcc.toolchain(version = "9.2.1") use_repo( - arm_none_eabi_gcc, + arm_gnu_gcc, + "arm_none_eabi", "arm_none_eabi_darwin_x86_64", "arm_none_eabi_linux_aarch64", "arm_none_eabi_linux_x86_64", @@ -26,6 +27,6 @@ register_toolchains( ) register_toolchains( - "@arm_none_eabi//examples/custom/toolchain:all", + "@arm_gnu_toolchain//examples/custom/toolchain:all", dev_dependency = True, ) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 334984d..7d7f9b5 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 3, - "moduleFileHash": "34ee30e2562d5f7543514f26a6e41c227768a67f47808745f814f6724de2b8cc", + "moduleFileHash": "1547720628aef14e9ed8ccfeb1ca0165a62e223dc3c5acd6b727ba4cab5e7c5c", "flags": { "cmdRegistries": [ "https://bcr.bazel.build/" @@ -17,26 +17,27 @@ }, "moduleDepGraph": { "": { - "name": "arm_none_eabi", + "name": "arm_gnu_toolchain", "version": "1.0.0", "key": "", - "repoName": "arm_none_eabi", + "repoName": "arm_gnu_toolchain", "executionPlatformsToRegister": [], "toolchainsToRegister": [ "@arm_none_eabi//toolchain:all", - "@arm_none_eabi//examples/custom/toolchain:all" + "@arm_gnu_toolchain//examples/custom/toolchain:all" ], "extensionUsages": [ { - "extensionBzlFile": "@arm_none_eabi//:extensions.bzl", - "extensionName": "arm_none_eabi", + "extensionBzlFile": "@arm_gnu_toolchain//:extensions.bzl", + "extensionName": "arm_gnu", "usingModule": "", "location": { "file": "@@//:MODULE.bazel", "line": 9, - "column": 34 + "column": 28 }, "imports": { + "arm_none_eabi": "arm_none_eabi", "arm_none_eabi_darwin_x86_64": "arm_none_eabi_darwin_x86_64", "arm_none_eabi_linux_aarch64": "arm_none_eabi_linux_aarch64", "arm_none_eabi_linux_x86_64": "arm_none_eabi_linux_x86_64", @@ -53,7 +54,7 @@ "location": { "file": "@@//:MODULE.bazel", "line": 10, - "column": 28 + "column": 22 } } ], @@ -830,9 +831,9 @@ } }, "moduleExtensions": { - "//:extensions.bzl%arm_none_eabi": { + "//:extensions.bzl%arm_gnu": { "general": { - "bzlTransitiveDigest": "fYpi3tKiM0IlfOvA6pDvDlh/SMJHrGgcqub2jKC3ry4=", + "bzlTransitiveDigest": "cQLWJ7ZNJyX372Ti24YE4I3NprTZm7cbvrcCtJ06Uaw=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -840,17 +841,24 @@ "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "_main~arm_none_eabi~arm_none_eabi_windows_x86_64", + "name": "_main~arm_gnu~arm_none_eabi_windows_x86_64", "build_file": "@@//toolchain:compiler/win.BUILD", "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" } }, + "arm_none_eabi": { + "bzlFile": "@@//:deps.bzl", + "ruleClassName": "arm_gnu_toolchain_repo", + "attributes": { + "name": "_main~arm_gnu~arm_none_eabi" + } + }, "arm_none_eabi_linux_x86_64": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "_main~arm_none_eabi~arm_none_eabi_linux_x86_64", + "name": "_main~arm_gnu~arm_none_eabi_linux_x86_64", "sha256": "bcd840f839d5bf49279638e9f67890b2ef3a7c9c7a9b25271e83ec4ff41d177a", "build_file": "@@//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", @@ -861,7 +869,7 @@ "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "_main~arm_none_eabi~arm_none_eabi_darwin_x86_64", + "name": "_main~arm_gnu~arm_none_eabi_darwin_x86_64", "sha256": "1249f860d4155d9c3ba8f30c19e7a88c5047923cea17e0d08e633f12408f01f0", "build_file": "@@//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", @@ -872,7 +880,7 @@ "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_archive", "attributes": { - "name": "_main~arm_none_eabi~arm_none_eabi_linux_aarch64", + "name": "_main~arm_gnu~arm_none_eabi_linux_aarch64", "sha256": "1f5b9309006737950b2218250e6bb392e2d68d4f1a764fe66be96e2a78888d83", "build_file": "@@//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", @@ -883,7 +891,7 @@ "recordedRepoMappingEntries": [ [ "", - "arm_none_eabi", + "arm_gnu_toolchain", "" ], [ diff --git a/README.md b/README.md index 6f30313..595d862 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ And this to your `.bazelrc` # Build using platforms by default build --incompatible_enable_cc_toolchain_resolution -build --platforms=@arm_none_eabi//platforms:arm_none_generic +build --platforms=@arm_gnu_toolchain//platforms:arm_none_generic ``` ## WORKSPACE @@ -76,7 +76,7 @@ git_repository( shallow_since = "", ) -load("@arm_none_eabi//:deps.bzl", "arm_none_eabi_deps", "register_default_arm_none_eabi_toolchains") +load("@arm_gnu_toolchain//:deps.bzl", "arm_none_eabi_deps", "register_default_arm_none_eabi_toolchains") arm_none_eabi_deps() @@ -99,7 +99,7 @@ git_override( bazel_dep(name = "arm_none_eabi", version = "1.0.0") -arm_none_eabi_gcc = use_extension("@arm_none_eabi//:extensions.bzl", "arm_none_eabi") +arm_none_eabi_gcc = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_none_eabi") arm_none_eabi_gcc.toolchain(version = "9.2.1") use_repo( arm_none_eabi_gcc, @@ -124,7 +124,7 @@ In a BUILD file: ```python # path/to/toolchains/BUILD -load("@arm_none_eabi//toolchain:toolchain.bzl", "arm_none_eabi_toolchain") +load("@arm_gnu_toolchain//toolchain:toolchain.bzl", "arm_none_eabi_toolchain") arm_none_eabi_toolchain( name = "custom_toolchain", target_compatible_with = [ diff --git a/deps.bzl b/deps.bzl index 39b8a8a..830d0f5 100644 --- a/deps.bzl +++ b/deps.bzl @@ -2,7 +2,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load( - "@arm_none_eabi//toolchain:toolchain.bzl", + "@arm_gnu_toolchain//toolchain:toolchain.bzl", "target_constraints", "register_arm_none_eabi_toolchain" ) @@ -12,27 +12,27 @@ GCC = { { "name": "arm_none_eabi_darwin_x86_64", "sha256": "1249f860d4155d9c3ba8f30c19e7a88c5047923cea17e0d08e633f12408f01f0", - "build_file": "@arm_none_eabi//toolchain:compiler/nix.BUILD", + "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", "url": "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-mac.tar.bz2?revision=c2c4fe0e-c0b6-4162-97e6-7707e12f2b6e&la=en&hash=EC9D4B5F5B050267B924F876B306D72CDF3BDDC0", }, { "name": "arm_none_eabi_linux_x86_64", "sha256": "bcd840f839d5bf49279638e9f67890b2ef3a7c9c7a9b25271e83ec4ff41d177a", - "build_file": "@arm_none_eabi//toolchain:compiler/nix.BUILD", + "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", "url": "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2?revision=108bd959-44bd-4619-9c19-26187abf5225&la=en&hash=E788CE92E5DFD64B2A8C246BBA91A249CB8E2D2D", }, { "name": "arm_none_eabi_linux_aarch64", "sha256": "1f5b9309006737950b2218250e6bb392e2d68d4f1a764fe66be96e2a78888d83", - "build_file": "@arm_none_eabi//toolchain:compiler/nix.BUILD", + "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", "url": "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-aarch64-linux.tar.bz2?revision=4583ce78-e7e7-459a-ad9f-bff8e94839f1&la=en&hash=550DB9C0184B7C70B6C020A5DCBB9D1E156264B7", }, { "name": "arm_none_eabi_windows_x86_64", - "build_file": "@arm_none_eabi//toolchain:compiler/win.BUILD", + "build_file": "@arm_gnu_toolchain//toolchain:compiler/win.BUILD", "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", }, @@ -41,33 +41,49 @@ GCC = { { "name": "arm_none_eabi_darwin_x86_64", "sha256": "075faa4f3e8eb45e59144858202351a28706f54a6ec17eedd88c9fb9412372cc", - "build_file": "@arm_none_eabi//toolchain:compiler/nix.BUILD", + "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-darwin-x86_64-arm-none-eabi.tar.xz?rev=a3d8c87bb0af4c40b7d7e0e291f6541b&hash=10927356ACA904E1A0122794E036E8DDE7D8435D", }, { "name": "arm_none_eabi_linux_x86_64", "sha256": "6cd1bbc1d9ae57312bcd169ae283153a9572bd6a8e4eeae2fedfbc33b115fdbb", - "build_file": "@arm_none_eabi//toolchain:compiler/nix.BUILD", + "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz?rev=e434b9ea4afc4ed7998329566b764309&hash=688C370BF08399033CA9DE3C1CC8CF8E31D8C441", }, { "name": "arm_none_eabi_linux_aarch64", "sha256": "8fd8b4a0a8d44ab2e195ccfbeef42223dfb3ede29d80f14dcf2183c34b8d199a", - "build_file": "@arm_none_eabi//toolchain:compiler/nix.BUILD", + "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-aarch64-arm-none-eabi.tar.xz?rev=17baf091942042768d55c9a304610954&hash=7F32B9E3ADFAFC4F8F74C30EBBBFECEB1AC96B60", }, { "name": "arm_none_eabi_windows_x86_64", - "build_file": "@arm_none_eabi//toolchain:compiler/win.BUILD", + "build_file": "@arm_gnu_toolchain//toolchain:compiler/win.BUILD", "sha256": "51d933f00578aa28016c5e3c84f94403274ea7915539f8e56c13e2196437d18f", "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", }, ], } +def _arm_gnu_toolchain_repo_impl(repository_ctx): + """Defines the top-level toolchain repository.""" + repository_ctx.template( + "BUILD", + Label("@arm_gnu_toolchain//toolchain:top.BUILD"), + ) + + repository_ctx.template( + "toolchain/BUILD", + Label("@arm_gnu_toolchain//toolchain:toolchain.BUILD"), + ) + +arm_gnu_toolchain_repo = repository_rule( + implementation = _arm_gnu_toolchain_repo_impl, +) + def arm_none_eabi_deps(version = "9.2.1", archives = GCC): """Workspace dependencies for the arm none eabi gcc toolchain @@ -75,6 +91,7 @@ def arm_none_eabi_deps(version = "9.2.1", archives = GCC): version: The version of the toolchain to use. If None, the latest version is used. archives: A dictionary of version to archive attributes. """ + arm_gnu_toolchain_repo(name = "arm_none_eabi") for attrs in archives[version]: http_archive(**attrs) diff --git a/examples/custom/toolchain/BUILD b/examples/custom/toolchain/BUILD index a51c3a1..a4b41d8 100644 --- a/examples/custom/toolchain/BUILD +++ b/examples/custom/toolchain/BUILD @@ -1,4 +1,4 @@ -load("@arm_none_eabi//toolchain:toolchain.bzl", "arm_none_eabi_toolchain") +load("@arm_gnu_toolchain//toolchain:toolchain.bzl", "arm_none_eabi_toolchain") # Cortex-M3 toolchain arm_none_eabi_toolchain( diff --git a/extensions.bzl b/extensions.bzl index e6dc0fe..8500719 100644 --- a/extensions.bzl +++ b/extensions.bzl @@ -1,8 +1,8 @@ -load("@arm_none_eabi//:deps.bzl", "arm_none_eabi_deps") +load("@arm_gnu_toolchain//:deps.bzl", "arm_none_eabi_deps") -def _arm_none_eabi_impl(ctx): +def _arm_gnu_impl(ctx): for mod in ctx.modules: - if mod.name == "arm_none_eabi": + if mod.name == "arm_gnu_toolchain": for attr in mod.tags.toolchain: arm_none_eabi_deps(attr.version) @@ -10,8 +10,8 @@ _toolchain = tag_class(attrs = { "version": attr.string(), }) -arm_none_eabi = module_extension( - implementation = _arm_none_eabi_impl, +arm_gnu = module_extension( + implementation = _arm_gnu_impl, tag_classes = { "toolchain": _toolchain, }, diff --git a/toolchain/BUILD b/toolchain/BUILD index 2ea9d15..e69de29 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -1,11 +0,0 @@ -# toolchain/BUILD - -load("@arm_none_eabi//toolchain:toolchain.bzl", "arm_none_eabi_toolchain", "target_constraints") - -[ - arm_none_eabi_toolchain( - name = name, - target_compatible_with = constraints, - ) - for name, constraints in target_constraints['arm-none-eabi'].items() -] diff --git a/toolchain/compiler/nix.BUILD b/toolchain/compiler/nix.BUILD index 092ae1b..15471bb 100644 --- a/toolchain/compiler/nix.BUILD +++ b/toolchain/compiler/nix.BUILD @@ -1,4 +1,4 @@ -load("@arm_none_eabi//toolchain:toolchain.bzl", "tools") +load("@arm_gnu_toolchain//toolchain:toolchain.bzl", "tools") package(default_visibility = ["//visibility:public"]) diff --git a/toolchain/compiler/win.BUILD b/toolchain/compiler/win.BUILD index a958d65..0322398 100644 --- a/toolchain/compiler/win.BUILD +++ b/toolchain/compiler/win.BUILD @@ -1,4 +1,4 @@ -load("@arm_none_eabi//toolchain:toolchain.bzl", "tools") +load("@arm_gnu_toolchain//toolchain:toolchain.bzl", "tools") package(default_visibility = ["//visibility:public"]) diff --git a/toolchain/toolchain.BUILD b/toolchain/toolchain.BUILD new file mode 100644 index 0000000..fcdad9e --- /dev/null +++ b/toolchain/toolchain.BUILD @@ -0,0 +1,13 @@ +""" +This BUILD file defines the toolchain targets for bzlmod consumers. +""" + +load("@arm_gnu_toolchain//toolchain:toolchain.bzl", "arm_none_eabi_toolchain", "target_constraints") + +[ + arm_none_eabi_toolchain( + name = name, + target_compatible_with = constraints, + ) + for name, constraints in target_constraints['arm-none-eabi'].items() +] diff --git a/toolchain/toolchain.bzl b/toolchain/toolchain.bzl index f2582bc..62e05de 100644 --- a/toolchain/toolchain.bzl +++ b/toolchain/toolchain.bzl @@ -2,7 +2,7 @@ This module provides functions to register an arm-none-eabi toolchain """ -load("@arm_none_eabi//toolchain:config.bzl", "cc_arm_none_eabi_config") +load("@arm_gnu_toolchain//toolchain:config.bzl", "cc_arm_none_eabi_config") tools = [ "as", diff --git a/toolchain/top.BUILD b/toolchain/top.BUILD new file mode 100644 index 0000000..adec838 --- /dev/null +++ b/toolchain/top.BUILD @@ -0,0 +1,30 @@ +""" +This BUILD file marks the top-level package of the generated toolchain +repository, i.e., the targets defined here appear in the workspace as +"@arm_none_eabi//:*" for arm-none-eabi toolchains. +""" + +load("@arm_gnu_toolchain//toolchain:toolchain.bzl", "hosts", "tools") + +package(default_visibility = ["//visibility:public"]) + +TOOLS = tools + ["bin"] + +[ + config_setting( + name = host, + constraint_values = constraint_values, + ) + for host, constraint_values in hosts.items() +] + +[ + filegroup( + name = tool, + srcs = select({ + host: ["@arm_none_eabi_{}//:{}".format(host, tool)] + for host in hosts.keys() + }), + ) + for tool in TOOLS +] From 65bee281cef3569f1ee8f40aba251352d40bd49d Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sun, 3 Mar 2024 17:02:39 -0600 Subject: [PATCH 03/23] Custom repo rule to templatize compiler BUILD Introduce a new custom repository rule to allow us to templatize the "compiler" BUILD.bazel file (toolchain/compilers{nix,win}.BUILD). This allows us an easy path to changing out the toolchain prefix when integrating new toolchain types. --- MODULE.bazel.lock | 22 +++++++++++++--------- deps.bzl | 32 ++++++++++++++++++++++++++++++-- toolchain/compiler/nix.BUILD | 8 +++++--- toolchain/compiler/win.BUILD | 8 +++++--- 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 7d7f9b5..321ad19 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -833,14 +833,15 @@ "moduleExtensions": { "//:extensions.bzl%arm_gnu": { "general": { - "bzlTransitiveDigest": "cQLWJ7ZNJyX372Ti24YE4I3NprTZm7cbvrcCtJ06Uaw=", + "bzlTransitiveDigest": "CmvPnbWE7ZzH8lS0quD4irCoo66D0ZNyU/DNZsxE1v0=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { "arm_none_eabi_windows_x86_64": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_archive", + "bzlFile": "@@//:deps.bzl", + "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { + "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_gnu~arm_none_eabi_windows_x86_64", "build_file": "@@//toolchain:compiler/win.BUILD", "sha256": "e4c964add8d0fdcc6b14f323e277a0946456082a84a1cc560da265b357762b62", @@ -855,9 +856,10 @@ } }, "arm_none_eabi_linux_x86_64": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_archive", + "bzlFile": "@@//:deps.bzl", + "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { + "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_gnu~arm_none_eabi_linux_x86_64", "sha256": "bcd840f839d5bf49279638e9f67890b2ef3a7c9c7a9b25271e83ec4ff41d177a", "build_file": "@@//toolchain:compiler/nix.BUILD", @@ -866,9 +868,10 @@ } }, "arm_none_eabi_darwin_x86_64": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_archive", + "bzlFile": "@@//:deps.bzl", + "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { + "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_gnu~arm_none_eabi_darwin_x86_64", "sha256": "1249f860d4155d9c3ba8f30c19e7a88c5047923cea17e0d08e633f12408f01f0", "build_file": "@@//toolchain:compiler/nix.BUILD", @@ -877,9 +880,10 @@ } }, "arm_none_eabi_linux_aarch64": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_archive", + "bzlFile": "@@//:deps.bzl", + "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { + "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_gnu~arm_none_eabi_linux_aarch64", "sha256": "1f5b9309006737950b2218250e6bb392e2d68d4f1a764fe66be96e2a78888d83", "build_file": "@@//toolchain:compiler/nix.BUILD", diff --git a/deps.bzl b/deps.bzl index 830d0f5..d95f8c6 100644 --- a/deps.bzl +++ b/deps.bzl @@ -1,6 +1,5 @@ """deps.bzl""" -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load( "@arm_gnu_toolchain//toolchain:toolchain.bzl", "target_constraints", @@ -68,6 +67,32 @@ GCC = { ], } +def _arm_gnu_cross_hosted_platform_specific_repo_impl(repository_ctx): + """Defines a host-specific repository for the ARM GNU toolchain.""" + repository_ctx.download_and_extract( + sha256=repository_ctx.attr.sha256, + url=repository_ctx.attr.url, + stripPrefix=repository_ctx.attr.strip_prefix, + ) + repository_ctx.template( + "BUILD.bazel", + Label(repository_ctx.attr.build_file), + substitutions = { + "%prefix%": repository_ctx.attr.toolchain_prefix, + }, + ) + +arm_gnu_cross_hosted_platform_specific_repo = repository_rule( + implementation = _arm_gnu_cross_hosted_platform_specific_repo_impl, + attrs = { + 'sha256': attr.string(mandatory=True), + 'url': attr.string(mandatory=True), + 'build_file': attr.label(mandatory=True), + 'toolchain_prefix': attr.string(mandatory=True), + 'strip_prefix': attr.string(), + }, +) + def _arm_gnu_toolchain_repo_impl(repository_ctx): """Defines the top-level toolchain repository.""" repository_ctx.template( @@ -93,7 +118,10 @@ def arm_none_eabi_deps(version = "9.2.1", archives = GCC): """ arm_gnu_toolchain_repo(name = "arm_none_eabi") for attrs in archives[version]: - http_archive(**attrs) + arm_gnu_cross_hosted_platform_specific_repo( + toolchain_prefix="arm-none-eabi", + **attrs, + ) def register_default_arm_none_eabi_toolchains(): for cpu in target_constraints['arm-none-eabi']: diff --git a/toolchain/compiler/nix.BUILD b/toolchain/compiler/nix.BUILD index 15471bb..6201d80 100644 --- a/toolchain/compiler/nix.BUILD +++ b/toolchain/compiler/nix.BUILD @@ -5,11 +5,13 @@ package(default_visibility = ["//visibility:public"]) # export the executable files to make them available for direct use. exports_files(glob(["**"], exclude_directories=0)) +PREFIX = "%prefix%" + # executables. [ filegroup( name = tool, - srcs = ["bin/arm-none-eabi-{}".format(tool)], + srcs = ["bin/{}-{}".format(PREFIX, tool)], ) for tool in tools ] @@ -20,9 +22,9 @@ filegroup( srcs = glob([ "bin/**", "libexec/**", - "arm-none-eabi/**", + "{}/**".format(PREFIX), "lib/**", - "lib/gcc/arm-none-eabi/**", + "lib/gcc/{}/**".format(PREFIX), ]), ) diff --git a/toolchain/compiler/win.BUILD b/toolchain/compiler/win.BUILD index 0322398..648336c 100644 --- a/toolchain/compiler/win.BUILD +++ b/toolchain/compiler/win.BUILD @@ -5,11 +5,13 @@ package(default_visibility = ["//visibility:public"]) # export the executable files to make them available for direct use. exports_files(glob(["**"], exclude_directories = 0)) +PREFIX = "%prefix%" + # executables. [ filegroup( name = tool, - srcs = ["bin/arm-none-eabi-{}.exe".format(tool)], + srcs = ["bin/{}-{}.exe".format(PREFIX, tool)], ) for tool in tools ] @@ -20,9 +22,9 @@ filegroup( srcs = glob([ "bin/**", "libexec/**", - "arm-none-eabi/**", + "{}/**".format(PREFIX), "lib/**", - "lib/gcc/arm-none-eabi/**", + "lib/gcc/{}/**".format(PREFIX), ]), ) From 502847cab760b7faff3d73cd0ea8843765f16e7e Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Mon, 4 Mar 2024 12:35:40 -0600 Subject: [PATCH 04/23] Make cc_arm_none_eabi_config generic We now encode all toolchain-specific items in the attributes of the generic "cc_arm_gnu_toolchain_config" rule. This allows us to use this rule for other ARM GNU toolchains in the future. --- MODULE.bazel.lock | 2 +- toolchain/config.bzl | 16 +++++++++------- toolchain/toolchain.bzl | 6 ++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 321ad19..0861f3e 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -833,7 +833,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_gnu": { "general": { - "bzlTransitiveDigest": "CmvPnbWE7ZzH8lS0quD4irCoo66D0ZNyU/DNZsxE1v0=", + "bzlTransitiveDigest": "z3aN/IKhgBO0XEAjuNcHnx+yu3CzdYoeDIAb/xp8xFw=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { diff --git a/toolchain/config.bzl b/toolchain/config.bzl index 9edcdee..563af05 100644 --- a/toolchain/config.bzl +++ b/toolchain/config.bzl @@ -1,9 +1,9 @@ load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "action_config", "feature", "flag_group", "flag_set") -def _tool_path(bins, tool_name): +def _tool_path(bins, toolchain_prefix, tool_name): for file in bins: - if file.basename.startswith("arm-none-eabi-{}".format(tool_name)): + if file.basename.startswith("{}-{}".format(toolchain_prefix, tool_name)): return file return None @@ -15,7 +15,7 @@ def _action_configs(ctx, action_names, tool_name, implies = []): tools = [ struct( type_name = "tool", - tool = _tool_path(ctx.files.toolchain_bins, tool_name), + tool = _tool_path(ctx.files.toolchain_bins, ctx.attr.toolchain_prefix, tool_name), ), ], implies = implies, @@ -128,11 +128,11 @@ def _impl(ctx): ctx = ctx, toolchain_identifier = ctx.attr.toolchain_identifier, host_system_name = ctx.attr.host_system_name, - target_system_name = "arm-none-eabi", - target_cpu = "arm-none-eabi", + target_system_name = ctx.attr.toolchain_prefix, + target_cpu = ctx.attr.toolchain_prefix, target_libc = "gcc", compiler = ctx.attr.gcc_repo, - abi_version = "eabi", + abi_version = ctx.attr.abi_version, abi_libc_version = ctx.attr.gcc_version, action_configs = action_configs, features = [ @@ -142,15 +142,17 @@ def _impl(ctx): ], ) -cc_arm_none_eabi_config = rule( +cc_arm_gnu_toolchain_config = rule( implementation = _impl, attrs = { "toolchain_identifier": attr.string(default = ""), + "toolchain_prefix": attr.string(default = ""), "host_system_name": attr.string(default = ""), "toolchain_bins": attr.label(mandatory = True, allow_files = True), "gcc_repo": attr.string(default = ""), "gcc_version": attr.string(default = ""), "gcc_tool": attr.string(default = "gcc"), + "abi_version": attr.string(default = ""), "copts": attr.string_list(default = []), "linkopts": attr.string_list(default = []), "include_path": attr.label_list(default = [], allow_files = True), diff --git a/toolchain/toolchain.bzl b/toolchain/toolchain.bzl index 62e05de..f98fc76 100644 --- a/toolchain/toolchain.bzl +++ b/toolchain/toolchain.bzl @@ -2,7 +2,7 @@ This module provides functions to register an arm-none-eabi toolchain """ -load("@arm_gnu_toolchain//toolchain:config.bzl", "cc_arm_none_eabi_config") +load("@arm_gnu_toolchain//toolchain:config.bzl", "cc_arm_gnu_toolchain_config") tools = [ "as", @@ -54,13 +54,15 @@ def arm_none_eabi_toolchain(name, gcc_tool = "gcc", target_compatible_with = [], """ for host, exec_compatible_with in hosts.items(): - cc_arm_none_eabi_config( + cc_arm_gnu_toolchain_config( name = "config_{}_{}".format(host, name), gcc_repo = "arm_none_eabi_{}".format(host), gcc_version = version, gcc_tool = gcc_tool, + abi_version = "eabi", host_system_name = host, toolchain_identifier = "arm_none_eabi_{}_{}".format(host, name), + toolchain_prefix = "arm-none-eabi", toolchain_bins = "@arm_none_eabi_{}//:compiler_components".format(host), include_path = [ "@arm_none_eabi_{}//:arm-none-eabi/include".format(host), From cd02104e71c29707e5b4cb9638b67a4fe3e5d481 Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Mon, 4 Mar 2024 12:56:17 -0600 Subject: [PATCH 05/23] Abstract generic logic from arm_none_eabi_toolchain All the interesting stuff now lives in a "private" _arm_gnu_toolchain function that specific toolchains can delegate to. This provide a common toolchain mechanism that can be used for creating and registering arm linux toolchains, for example. --- MODULE.bazel.lock | 2 +- deps.bzl | 4 +- toolchain/toolchain.bzl | 88 +++++++++++++++++++++++------------------ 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 0861f3e..0d928f7 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -833,7 +833,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_gnu": { "general": { - "bzlTransitiveDigest": "z3aN/IKhgBO0XEAjuNcHnx+yu3CzdYoeDIAb/xp8xFw=", + "bzlTransitiveDigest": "55dtwtm1aiXtPnZLcXPKGvRSFxlumnD+fMcrNcOrxRI=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { diff --git a/deps.bzl b/deps.bzl index d95f8c6..9c0091a 100644 --- a/deps.bzl +++ b/deps.bzl @@ -3,7 +3,7 @@ load( "@arm_gnu_toolchain//toolchain:toolchain.bzl", "target_constraints", - "register_arm_none_eabi_toolchain" + "register_arm_gnu_toolchain", ) GCC = { @@ -125,4 +125,4 @@ def arm_none_eabi_deps(version = "9.2.1", archives = GCC): def register_default_arm_none_eabi_toolchains(): for cpu in target_constraints['arm-none-eabi']: - register_arm_none_eabi_toolchain("//toolchain:{}".format(cpu)) + register_arm_gnu_toolchain("//toolchain:{}".format(cpu)) diff --git a/toolchain/toolchain.bzl b/toolchain/toolchain.bzl index f98fc76..44ce3ec 100644 --- a/toolchain/toolchain.bzl +++ b/toolchain/toolchain.bzl @@ -33,47 +33,40 @@ target_constraints = { } hosts = { - "darwin_x86_64": ["@platforms//os:macos"], # Also runs on apple silicon - "linux_x86_64": ["@platforms//os:linux", "@platforms//cpu:x86_64"], - "linux_aarch64": ["@platforms//os:linux", "@platforms//cpu:arm64"], - "windows_x86_64": ["@platforms//os:windows", "@platforms//cpu:x86_64"], + "arm-none-eabi": { + "darwin_x86_64": ["@platforms//os:macos"], # Also runs on apple silicon + "linux_x86_64": ["@platforms//os:linux", "@platforms//cpu:x86_64"], + "linux_aarch64": ["@platforms//os:linux", "@platforms//cpu:arm64"], + "windows_x86_64": ["@platforms//os:windows", "@platforms//cpu:x86_64"], + }, } -def arm_none_eabi_toolchain(name, gcc_tool = "gcc", target_compatible_with = [], copts = [], linkopts = [], version = "9.2.1", include_std = False): - """ - Create an arm-none-eabi toolchain with the given configuration. - - Args: - name: The name of the toolchain. - gcc_tool: The gcc tool to use. Defaults to "gcc". [gcc, c++, cpp] - target_compatible_with: A list of constraint values to apply to the toolchain. - copts: A list of compiler options to apply to the toolchain. - linkopts: A list of linker options to apply to the toolchain. - version: The version of the gcc toolchain. - include_std: Whether to include the standard library in the include path. - """ - - for host, exec_compatible_with in hosts.items(): +def _arm_gnu_toolchain(name, toolchain = "", toolchain_prefix = "", + gcc_tool = "gcc", abi_version = "", + target_compatible_with = [], copts = [], + linkopts = [], version = "", include_std = False): + for host, exec_compatible_with in hosts[toolchain_prefix].items(): cc_arm_gnu_toolchain_config( name = "config_{}_{}".format(host, name), - gcc_repo = "arm_none_eabi_{}".format(host), + gcc_repo = "{}_{}".format(toolchain, host), gcc_version = version, gcc_tool = gcc_tool, - abi_version = "eabi", + abi_version = abi_version, host_system_name = host, - toolchain_identifier = "arm_none_eabi_{}_{}".format(host, name), - toolchain_prefix = "arm-none-eabi", - toolchain_bins = "@arm_none_eabi_{}//:compiler_components".format(host), + toolchain_prefix = toolchain_prefix, + toolchain_identifier = "{}_{}_{}".format(toolchain, host, name), + toolchain_bins = "@{}_{}//:compiler_components".format(toolchain, host), include_path = [ - "@arm_none_eabi_{}//:arm-none-eabi/include".format(host), - "@arm_none_eabi_{}//:lib/gcc/arm-none-eabi/{}/include".format(host, version), - "@arm_none_eabi_{}//:lib/gcc/arm-none-eabi/{}/include-fixed".format(host, version), - "@arm_none_eabi_{}//:arm-none-eabi/include/c++/{}".format(host, version), - "@arm_none_eabi_{}//:arm-none-eabi/include/c++/{}/arm-none-eabi".format(host, version), + "@{}_{}//:{}/include".format(toolchain, host, toolchain_prefix), + "@{}_{}//:lib/gcc/{}/{}/include".format(toolchain, host, toolchain_prefix, version), + "@{}_{}//:lib/gcc/{}/{}/include-fixed".format(toolchain, host, toolchain_prefix, version), + "@{}_{}//:{}/include/c++/{}".format(toolchain, host, toolchain_prefix, version), + "@{}_{}//:{}/include/c++/{}/{}".format(toolchain, host, toolchain_prefix, version, toolchain_prefix), ], library_path = [ - "@arm_none_eabi_{}//:arm-none-eabi/lib".format(host), - "@arm_none_eabi_{}//:lib/gcc/arm-none-eabi/{}".format(host, version), + "@{}_{}//:{}".format(toolchain, host, toolchain_prefix), + "@{}_{}//:{}/lib".format(toolchain, host, toolchain_prefix), + "@{}_{}//:lib/gcc/{}/{}".format(toolchain, host, toolchain_prefix, version), ], copts = copts, linkopts = linkopts, @@ -82,16 +75,16 @@ def arm_none_eabi_toolchain(name, gcc_tool = "gcc", target_compatible_with = [], native.cc_toolchain( name = "cc_toolchain_{}_{}".format(host, name), - all_files = "@arm_none_eabi_{}//:compiler_pieces".format(host), - ar_files = "@arm_none_eabi_{}//:ar_files".format(host), - compiler_files = "@arm_none_eabi_{}//:compiler_files".format(host), + all_files = "@{}_{}//:compiler_pieces".format(toolchain, host), + ar_files = "@{}_{}//:ar_files".format(toolchain, host), + compiler_files = "@{}_{}//:compiler_files".format(toolchain, host), dwp_files = ":empty", - linker_files = "@arm_none_eabi_{}//:linker_files".format(host), - objcopy_files = "@arm_none_eabi_{}//:objcopy".format(host), - strip_files = "@arm_none_eabi_{}//:strip".format(host), + linker_files = "@{}_{}//:linker_files".format(toolchain, host), + objcopy_files = "@{}_{}//:objcopy".format(toolchain, host), + strip_files = "@{}_{}//:strip".format(toolchain, host), supports_param_files = 0, toolchain_config = ":config_{}_{}".format(host, name), - toolchain_identifier = "arm_none_eabi_{}_{}".format(host, name), + toolchain_identifier = "{}_{}_{}".format(toolchain, host, name), ) native.toolchain( @@ -102,6 +95,23 @@ def arm_none_eabi_toolchain(name, gcc_tool = "gcc", target_compatible_with = [], toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", ) -def register_arm_none_eabi_toolchain(name): +def arm_none_eabi_toolchain(name, version = "9.2.1", **kwargs): + """ + Create an arm-none-eabi toolchain with the given configuration. + + Args: + name: The name of the toolchain. + gcc_tool: The gcc tool to use. Defaults to "gcc". [gcc, c++, cpp] + target_compatible_with: A list of constraint values to apply to the toolchain. + copts: A list of compiler options to apply to the toolchain. + linkopts: A list of linker options to apply to the toolchain. + version: The version of the gcc toolchain. + include_std: Whether to include the standard library in the include path. + """ + _arm_gnu_toolchain(name, toolchain = "arm_none_eabi", + toolchain_prefix = "arm-none-eabi", version = version, + abi_version = "eabi", **kwargs) + +def register_arm_gnu_toolchain(name): for host in hosts: native.register_toolchains("{}_{}".format(name, host)) From cbd28b681d91bad7924c0e55b8627fb995bddc65 Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Mon, 4 Mar 2024 13:07:45 -0600 Subject: [PATCH 06/23] Genericize arm_none_eabi_deps and repo BUILD templates Continuing with the trend of "genericization," this commit abstracts everything specific to the arm-none-eabi platform out of the arm_none_eabi_deps function into a new function that can be leveraged by additional toolchains. The arm_none_eabi_deps function is kept to maintain API stability. --- MODULE.bazel.lock | 6 +++-- deps.bzl | 49 +++++++++++++++++++++++++++++++-------- toolchain/toolchain.BUILD | 14 +++++++---- toolchain/top.BUILD | 2 +- 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 0d928f7..dd34fed 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -833,7 +833,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_gnu": { "general": { - "bzlTransitiveDigest": "55dtwtm1aiXtPnZLcXPKGvRSFxlumnD+fMcrNcOrxRI=", + "bzlTransitiveDigest": "owkHZtCdsCQ2JdfDibLd2OtYWhm916XudZANlMpzRHc=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -852,7 +852,9 @@ "bzlFile": "@@//:deps.bzl", "ruleClassName": "arm_gnu_toolchain_repo", "attributes": { - "name": "_main~arm_gnu~arm_none_eabi" + "name": "_main~arm_gnu~arm_none_eabi", + "toolchain_name": "arm_none_eabi", + "toolchain_prefix": "arm-none-eabi" } }, "arm_none_eabi_linux_x86_64": { diff --git a/deps.bzl b/deps.bzl index 9c0091a..d204893 100644 --- a/deps.bzl +++ b/deps.bzl @@ -6,7 +6,7 @@ load( "register_arm_gnu_toolchain", ) -GCC = { +GCC_ARM_NONE_EABI = { "9.2.1": [ { "name": "arm_none_eabi_darwin_x86_64", @@ -98,31 +98,60 @@ def _arm_gnu_toolchain_repo_impl(repository_ctx): repository_ctx.template( "BUILD", Label("@arm_gnu_toolchain//toolchain:top.BUILD"), + substitutions = { + "%toolchain_name%": repository_ctx.attr.toolchain_name, + }, ) repository_ctx.template( "toolchain/BUILD", Label("@arm_gnu_toolchain//toolchain:toolchain.BUILD"), + substitutions = { + "%toolchain_name%": repository_ctx.attr.toolchain_name, + "%toolchain_prefix%": repository_ctx.attr.toolchain_prefix, + }, ) arm_gnu_toolchain_repo = repository_rule( implementation = _arm_gnu_toolchain_repo_impl, + attrs = { + 'toolchain_name': attr.string(mandatory=True), + 'toolchain_prefix': attr.string(mandatory=True), + }, ) -def arm_none_eabi_deps(version = "9.2.1", archives = GCC): +def arm_gnu_toolchain_deps(toolchain, toolchain_prefix, version, archives): + arm_gnu_toolchain_repo( + name = toolchain, + toolchain_name = toolchain, + toolchain_prefix = toolchain_prefix, + ) + + for attrs in archives[version]: + arm_gnu_cross_hosted_platform_specific_repo( + toolchain_prefix=toolchain_prefix, + **attrs, + ) + +def register_default_arm_gnu_toolchains(toolchain_prefix): + for cpu in target_constraints[toolchain_prefix]: + register_arm_gnu_toolchain("//toolchain:{}".format(cpu)) + +# arm-none-eabi + +def arm_none_eabi_deps(version = "9.2.1", archives = GCC_ARM_NONE_EABI): """Workspace dependencies for the arm none eabi gcc toolchain Args: version: The version of the toolchain to use. If None, the latest version is used. archives: A dictionary of version to archive attributes. """ - arm_gnu_toolchain_repo(name = "arm_none_eabi") - for attrs in archives[version]: - arm_gnu_cross_hosted_platform_specific_repo( - toolchain_prefix="arm-none-eabi", - **attrs, - ) + arm_gnu_toolchain_deps( + "arm_none_eabi", + "arm-none-eabi", + version, + archives + ) def register_default_arm_none_eabi_toolchains(): - for cpu in target_constraints['arm-none-eabi']: - register_arm_gnu_toolchain("//toolchain:{}".format(cpu)) + register_default_arm_gnu_toolchains('arm-none-eabi') diff --git a/toolchain/toolchain.BUILD b/toolchain/toolchain.BUILD index fcdad9e..0941aeb 100644 --- a/toolchain/toolchain.BUILD +++ b/toolchain/toolchain.BUILD @@ -1,13 +1,19 @@ """ -This BUILD file defines the toolchain targets for bzlmod consumers. +This BUILD file defines the toolchain targets for bzlmod consumers. It is +rendered into the //toolchain package of the generated toolchain repository. +For example, "@arm_none_eabi//toolchain:*" """ -load("@arm_gnu_toolchain//toolchain:toolchain.bzl", "arm_none_eabi_toolchain", "target_constraints") +load( + "@arm_gnu_toolchain//toolchain:toolchain.bzl", + "%toolchain_name%_toolchain", + "target_constraints", +) [ - arm_none_eabi_toolchain( + %toolchain_name%_toolchain( name = name, target_compatible_with = constraints, ) - for name, constraints in target_constraints['arm-none-eabi'].items() + for name, constraints in target_constraints['%toolchain_prefix%'].items() ] diff --git a/toolchain/top.BUILD b/toolchain/top.BUILD index adec838..2c0dea7 100644 --- a/toolchain/top.BUILD +++ b/toolchain/top.BUILD @@ -22,7 +22,7 @@ TOOLS = tools + ["bin"] filegroup( name = tool, srcs = select({ - host: ["@arm_none_eabi_{}//:{}".format(host, tool)] + host: ["@%toolchain_name%_{}//:{}".format(host, tool)] for host in hosts.keys() }), ) From a6090ea4897e605e36cfe81708551dae7fdfddfc Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Mon, 4 Mar 2024 13:41:58 -0600 Subject: [PATCH 07/23] Rename module extension to arm_toolchain and tag classes Previously, there was a single tag class for the "arm_gnu" module extension which would be used by consumers to pull in arm vendored toolchains. Now, however, the tags map to the particular toolchain through the toolchain's target name. See the updated README for more information. --- MODULE.bazel | 6 +++--- MODULE.bazel.lock | 24 ++++++++++++------------ README.md | 7 ++++--- extensions.bzl | 15 +++++++++------ 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index d37c1d6..f30bb57 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -6,10 +6,10 @@ module( bazel_dep(name = "platforms", version = "0.0.8") -arm_gnu_gcc = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_gnu") -arm_gnu_gcc.toolchain(version = "9.2.1") +arm_toolchain = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_toolchain") +arm_toolchain.arm_none_eabi(version = "9.2.1") use_repo( - arm_gnu_gcc, + arm_toolchain, "arm_none_eabi", "arm_none_eabi_darwin_x86_64", "arm_none_eabi_linux_aarch64", diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index dd34fed..fa82281 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 3, - "moduleFileHash": "1547720628aef14e9ed8ccfeb1ca0165a62e223dc3c5acd6b727ba4cab5e7c5c", + "moduleFileHash": "546696f9bdaf5b0852834ab773cd4ee12190f6dd02bd364f23a200d31020a81d", "flags": { "cmdRegistries": [ "https://bcr.bazel.build/" @@ -29,12 +29,12 @@ "extensionUsages": [ { "extensionBzlFile": "@arm_gnu_toolchain//:extensions.bzl", - "extensionName": "arm_gnu", + "extensionName": "arm_toolchain", "usingModule": "", "location": { "file": "@@//:MODULE.bazel", "line": 9, - "column": 28 + "column": 30 }, "imports": { "arm_none_eabi": "arm_none_eabi", @@ -46,7 +46,7 @@ "devImports": [], "tags": [ { - "tagName": "toolchain", + "tagName": "arm_none_eabi", "attributeValues": { "version": "9.2.1" }, @@ -54,7 +54,7 @@ "location": { "file": "@@//:MODULE.bazel", "line": 10, - "column": 22 + "column": 28 } } ], @@ -831,9 +831,9 @@ } }, "moduleExtensions": { - "//:extensions.bzl%arm_gnu": { + "//:extensions.bzl%arm_toolchain": { "general": { - "bzlTransitiveDigest": "owkHZtCdsCQ2JdfDibLd2OtYWhm916XudZANlMpzRHc=", + "bzlTransitiveDigest": "y3PJMbnU70iP8hb2hqYXDtp8MFHdEMdmRvx1vGgp4i8=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -842,7 +842,7 @@ "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { "toolchain_prefix": "arm-none-eabi", - "name": "_main~arm_gnu~arm_none_eabi_windows_x86_64", + "name": "_main~arm_toolchain~arm_none_eabi_windows_x86_64", "build_file": "@@//toolchain:compiler/win.BUILD", "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" @@ -852,7 +852,7 @@ "bzlFile": "@@//:deps.bzl", "ruleClassName": "arm_gnu_toolchain_repo", "attributes": { - "name": "_main~arm_gnu~arm_none_eabi", + "name": "_main~arm_toolchain~arm_none_eabi", "toolchain_name": "arm_none_eabi", "toolchain_prefix": "arm-none-eabi" } @@ -862,7 +862,7 @@ "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { "toolchain_prefix": "arm-none-eabi", - "name": "_main~arm_gnu~arm_none_eabi_linux_x86_64", + "name": "_main~arm_toolchain~arm_none_eabi_linux_x86_64", "sha256": "bcd840f839d5bf49279638e9f67890b2ef3a7c9c7a9b25271e83ec4ff41d177a", "build_file": "@@//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", @@ -874,7 +874,7 @@ "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { "toolchain_prefix": "arm-none-eabi", - "name": "_main~arm_gnu~arm_none_eabi_darwin_x86_64", + "name": "_main~arm_toolchain~arm_none_eabi_darwin_x86_64", "sha256": "1249f860d4155d9c3ba8f30c19e7a88c5047923cea17e0d08e633f12408f01f0", "build_file": "@@//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", @@ -886,7 +886,7 @@ "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { "toolchain_prefix": "arm-none-eabi", - "name": "_main~arm_gnu~arm_none_eabi_linux_aarch64", + "name": "_main~arm_toolchain~arm_none_eabi_linux_aarch64", "sha256": "1f5b9309006737950b2218250e6bb392e2d68d4f1a764fe66be96e2a78888d83", "build_file": "@@//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", diff --git a/README.md b/README.md index 595d862..01a7e6b 100644 --- a/README.md +++ b/README.md @@ -99,10 +99,11 @@ git_override( bazel_dep(name = "arm_none_eabi", version = "1.0.0") -arm_none_eabi_gcc = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_none_eabi") -arm_none_eabi_gcc.toolchain(version = "9.2.1") +arm_toolchain = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_toolchain") +arm_toolchain.arm_none_eabi(version = "9.2.1") use_repo( - arm_none_eabi_gcc, + arm_toolchain, + "arm_none_eabi", "arm_none_eabi_darwin_x86_64", "arm_none_eabi_linux_aarch64", "arm_none_eabi_linux_x86_64", diff --git a/extensions.bzl b/extensions.bzl index 8500719..051e3a4 100644 --- a/extensions.bzl +++ b/extensions.bzl @@ -1,18 +1,21 @@ -load("@arm_gnu_toolchain//:deps.bzl", "arm_none_eabi_deps") +load( + "@arm_gnu_toolchain//:deps.bzl", + "arm_none_eabi_deps", +) -def _arm_gnu_impl(ctx): +def _arm_toolchain_impl(ctx): for mod in ctx.modules: if mod.name == "arm_gnu_toolchain": - for attr in mod.tags.toolchain: + for attr in mod.tags.arm_none_eabi: arm_none_eabi_deps(attr.version) _toolchain = tag_class(attrs = { "version": attr.string(), }) -arm_gnu = module_extension( - implementation = _arm_gnu_impl, +arm_toolchain = module_extension( + implementation = _arm_toolchain_impl, tag_classes = { - "toolchain": _toolchain, + "arm_none_eabi": _toolchain, }, ) From 2110aee9baa934d54e973fcaf2a96643b6df023d Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Mon, 4 Mar 2024 15:13:50 -0600 Subject: [PATCH 08/23] Introduce the arm-none-linux-gnueabihf toolchain This commit introduces the named toolchain, which functions much in the same way as the existing arm-none-eabi toolchains. A couple of minor changes to existing common code are required to get simple applications to compile. --- MODULE.bazel.lock | 2 +- deps.bzl | 50 +++++++++++++++++++ extensions.bzl | 4 ++ platforms/BUILD | 8 +++ ...001-Resolve-libc-relative-to-sysroot.patch | 16 ++++++ toolchain/toolchain.bzl | 33 +++++++++++- 6 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 toolchain/compiler/0001-Resolve-libc-relative-to-sysroot.patch diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index fa82281..5be4edb 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -833,7 +833,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_toolchain": { "general": { - "bzlTransitiveDigest": "y3PJMbnU70iP8hb2hqYXDtp8MFHdEMdmRvx1vGgp4i8=", + "bzlTransitiveDigest": "KX1j1lleBmumhGSbU9DNMEbRenKDagbmOH0rzUSkAiA=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { diff --git a/deps.bzl b/deps.bzl index d204893..c9a7518 100644 --- a/deps.bzl +++ b/deps.bzl @@ -67,6 +67,34 @@ GCC_ARM_NONE_EABI = { ], } +GCC_ARM_NONE_LINUX_GNUEABIHF = { + "13.2.1": [ + { + "name": "arm_none_linux_gnueabihf_linux_x86_64", + "sha256": "df0f4927a67d1fd366ff81e40bd8c385a9324fbdde60437a512d106215f257b3", + "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", + "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-linux-gnueabihf", + "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz?rev=adb0c0238c934aeeaa12c09609c5e6fc&hash=68DA67DE12CBAD82A0FA4B75247E866155C93053", + "patches": ["@arm_gnu_toolchain//toolchain:compiler/0001-Resolve-libc-relative-to-sysroot.patch"], + }, + { + "name": "arm_none_linux_gnueabihf_linux_aarch64", + "sha256": "8ad384bb328bccc44396d85c8f8113b7b8c5e11bcfef322e77cda3ebe7baadb5", + "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", + "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-linux-gnueabihf", + "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-aarch64-arm-none-linux-gnueabihf.tar.xz?rev=fbdb67e76c8349e5ad27a7c40fb270c9&hash=8CD3EBFFDC5E211275B705F6F9BCC0F6F5B4A53E", + "patches": ["@arm_gnu_toolchain//toolchain:compiler/0001-Resolve-libc-relative-to-sysroot.patch"], + }, + { + "name": "arm_none_linux_gnueabihf_windows_x86_64", + "sha256": "047e72bcef8f7767691f36929a8c74ef66f717cf6264a31f48dd31bfb067f4c8", + "build_file": "@arm_gnu_toolchain//toolchain:compiler/win.BUILD", + "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": ["@arm_gnu_toolchain//toolchain:compiler/0001-Resolve-libc-relative-to-sysroot.patch"], + }, + ], +} + def _arm_gnu_cross_hosted_platform_specific_repo_impl(repository_ctx): """Defines a host-specific repository for the ARM GNU toolchain.""" repository_ctx.download_and_extract( @@ -81,6 +109,8 @@ def _arm_gnu_cross_hosted_platform_specific_repo_impl(repository_ctx): "%prefix%": repository_ctx.attr.toolchain_prefix, }, ) + for patch in repository_ctx.attr.patches: + repository_ctx.patch(patch, strip=1) arm_gnu_cross_hosted_platform_specific_repo = repository_rule( implementation = _arm_gnu_cross_hosted_platform_specific_repo_impl, @@ -90,6 +120,7 @@ arm_gnu_cross_hosted_platform_specific_repo = repository_rule( 'build_file': attr.label(mandatory=True), 'toolchain_prefix': attr.string(mandatory=True), 'strip_prefix': attr.string(), + 'patches': attr.label_list(), }, ) @@ -155,3 +186,22 @@ def arm_none_eabi_deps(version = "9.2.1", archives = GCC_ARM_NONE_EABI): def register_default_arm_none_eabi_toolchains(): register_default_arm_gnu_toolchains('arm-none-eabi') + +# arm-none-linux-gnueabihf + +def arm_none_linux_gnueabihf_deps(version = "13.2.1", archives = GCC_ARM_NONE_LINUX_GNUEABIHF): + """Workspace dependencies for the arm linux gcc toolchain + + Args: + version: The version of the toolchain to use. If None, the latest version is used. + archives: A dictionary of the version to archive attributes. + """ + arm_gnu_toolchain_deps( + "arm_none_linux_gnueabihf", + "arm-none-linux-gnueabihf", + version, + archives, + ) + +def register_default_arm_none_linux_gnueabihf_toolchains(): + register_default_arm_gnu_toolchains('arm-none-linux-gnueabihf') diff --git a/extensions.bzl b/extensions.bzl index 051e3a4..9f06a41 100644 --- a/extensions.bzl +++ b/extensions.bzl @@ -1,6 +1,7 @@ load( "@arm_gnu_toolchain//:deps.bzl", "arm_none_eabi_deps", + "arm_none_linux_gnueabihf_deps", ) def _arm_toolchain_impl(ctx): @@ -8,6 +9,8 @@ def _arm_toolchain_impl(ctx): if mod.name == "arm_gnu_toolchain": for attr in mod.tags.arm_none_eabi: arm_none_eabi_deps(attr.version) + for attr in mod.tags.arm_none_linux_gnueabihf: + arm_none_linux_gnueabihf_deps(attr.version) _toolchain = tag_class(attrs = { "version": attr.string(), @@ -17,5 +20,6 @@ arm_toolchain = module_extension( implementation = _arm_toolchain_impl, tag_classes = { "arm_none_eabi": _toolchain, + "arm_none_linux_gnueabihf": _toolchain, }, ) diff --git a/platforms/BUILD b/platforms/BUILD index a895c00..c35e4a7 100644 --- a/platforms/BUILD +++ b/platforms/BUILD @@ -9,3 +9,11 @@ platform( "@platforms//os:none", ], ) + +platform( + name = "arm_linux", + constraint_values = [ + "@platforms//cpu:arm", + "@platforms//os:linux", + ], +) diff --git a/toolchain/compiler/0001-Resolve-libc-relative-to-sysroot.patch b/toolchain/compiler/0001-Resolve-libc-relative-to-sysroot.patch new file mode 100644 index 0000000..5d33633 --- /dev/null +++ b/toolchain/compiler/0001-Resolve-libc-relative-to-sysroot.patch @@ -0,0 +1,16 @@ +Resolve libc relative to sysroot + +In the arm linux toolchain, libc.so is simply a link script that +points to the real libc.so shared library. However, the path of the +actual shared object is specified as an absolute path, which means +it is not resolved relative to the toolchain prefix or sysroot +directories. Adding '=' here causes ld to search for these files +relative to the library search directories. +--- a/arm-none-linux-gnueabihf/libc/usr/lib/libc.so ++++ b/arm-none-linux-gnueabihf/libc/usr/lib/libc.so +@@ -2,4 +2,4 @@ + Use the shared library, but some functions are only in + the static library, so try that secondarily. */ + OUTPUT_FORMAT(elf32-littlearm) +-GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux-armhf.so.3 ) ) ++GROUP ( =/lib/libc.so.6 =/usr/lib/libc_nonshared.a AS_NEEDED ( =/lib/ld-linux-armhf.so.3 ) ) diff --git a/toolchain/toolchain.bzl b/toolchain/toolchain.bzl index 44ce3ec..08748b3 100644 --- a/toolchain/toolchain.bzl +++ b/toolchain/toolchain.bzl @@ -30,6 +30,11 @@ target_constraints = { "armv7e-mf": ["@platforms//os:none", "@platforms//cpu:armv7e-mf"], "armv8-m": ["@platforms//os:none", "@platforms//cpu:armv8-m"], }, + + "arm-none-linux-gnueabihf": { + "arm": ["@platforms//os:linux", "@platforms//cpu:arm"], + "armv7": ["@platforms//os:linux", "@platforms//cpu:armv7"], + }, } hosts = { @@ -39,6 +44,13 @@ hosts = { "linux_aarch64": ["@platforms//os:linux", "@platforms//cpu:arm64"], "windows_x86_64": ["@platforms//os:windows", "@platforms//cpu:x86_64"], }, + + "arm-none-linux-gnueabihf": { + # ARM has not provided an arm linux toolchain for darwin. + "linux_x86_64": ["@platforms//os:linux", "@platforms//cpu:x86_64"], + "linux_aarch64": ["@platforms//os:linux", "@platforms//cpu:arm64"], + "windows_x86_64": ["@platforms//os:windows", "@platforms//cpu:x86_64"], + }, } def _arm_gnu_toolchain(name, toolchain = "", toolchain_prefix = "", @@ -95,7 +107,7 @@ def _arm_gnu_toolchain(name, toolchain = "", toolchain_prefix = "", toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", ) -def arm_none_eabi_toolchain(name, version = "9.2.1", **kwargs): +def arm_none_eabi_toolchain(name, version = "9.2.1", copts = [], **kwargs): """ Create an arm-none-eabi toolchain with the given configuration. @@ -110,7 +122,24 @@ def arm_none_eabi_toolchain(name, version = "9.2.1", **kwargs): """ _arm_gnu_toolchain(name, toolchain = "arm_none_eabi", toolchain_prefix = "arm-none-eabi", version = version, - abi_version = "eabi", **kwargs) + abi_version = "eabi", copts = ["-nostdinc"] + copts, + **kwargs) + +def arm_none_linux_gnueabihf_toolchain(name, version = "13.2.1", **kwargs): + """ + Create an arm-none-linux-gnueabihf toolchain with the given configuration. + + Args: + name: The name of the toolchain. + gcc_tool: The gcc tool to use. Defaults to "gcc". [gcc, c++, cpp] + target_compatible_with: A list of constraint values to apply to the toolchain. + copts: A list of compiler options to apply to the toolchain. + linkopts: A list of linker options to apply to the toolchain. + version: The version of the gcc toolchain. + """ + _arm_gnu_toolchain(name, toolchain = "arm_none_linux_gnueabihf", + toolchain_prefix = "arm-none-linux-gnueabihf", + version = version, abi_version = "gnueabihf", **kwargs) def register_arm_gnu_toolchain(name): for host in hosts: From fa2cec38e8ac8b9037b3fe171d838d2e67b265e8 Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Mon, 4 Mar 2024 15:21:10 -0600 Subject: [PATCH 09/23] Create an example using arm-none-linux-gnueabihf toolchain --- MODULE.bazel | 10 ++++ MODULE.bazel.lock | 74 +++++++++++++++++++++++- examples/simple-linux/BUILD | 51 ++++++++++++++++ examples/simple-linux/includes/library.h | 4 ++ examples/simple-linux/source/library.cpp | 20 +++++++ examples/simple-linux/source/main.cpp | 5 ++ 6 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 examples/simple-linux/BUILD create mode 100644 examples/simple-linux/includes/library.h create mode 100644 examples/simple-linux/source/library.cpp create mode 100644 examples/simple-linux/source/main.cpp diff --git a/MODULE.bazel b/MODULE.bazel index f30bb57..1df0882 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -17,12 +17,22 @@ use_repo( "arm_none_eabi_windows_x86_64", ) +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", +) + # 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( "@arm_none_eabi//toolchain:all", + "@arm_none_linux_gnueabihf//toolchain:all", dev_dependency = True, ) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 5be4edb..5db3479 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 3, - "moduleFileHash": "546696f9bdaf5b0852834ab773cd4ee12190f6dd02bd364f23a200d31020a81d", + "moduleFileHash": "83a3bf69a53475bc86fe8eb51a0e3b024ad186d35aad4d1d4b5d5b54a44c66e9", "flags": { "cmdRegistries": [ "https://bcr.bazel.build/" @@ -24,6 +24,7 @@ "executionPlatformsToRegister": [], "toolchainsToRegister": [ "@arm_none_eabi//toolchain:all", + "@arm_none_linux_gnueabihf//toolchain:all", "@arm_gnu_toolchain//examples/custom/toolchain:all" ], "extensionUsages": [ @@ -41,7 +42,11 @@ "arm_none_eabi_darwin_x86_64": "arm_none_eabi_darwin_x86_64", "arm_none_eabi_linux_aarch64": "arm_none_eabi_linux_aarch64", "arm_none_eabi_linux_x86_64": "arm_none_eabi_linux_x86_64", - "arm_none_eabi_windows_x86_64": "arm_none_eabi_windows_x86_64" + "arm_none_eabi_windows_x86_64": "arm_none_eabi_windows_x86_64", + "arm_none_linux_gnueabihf": "arm_none_linux_gnueabihf", + "arm_none_linux_gnueabihf_linux_aarch64": "arm_none_linux_gnueabihf_linux_aarch64", + "arm_none_linux_gnueabihf_linux_x86_64": "arm_none_linux_gnueabihf_linux_x86_64", + "arm_none_linux_gnueabihf_windows_x86_64": "arm_none_linux_gnueabihf_windows_x86_64" }, "devImports": [], "tags": [ @@ -56,6 +61,18 @@ "line": 10, "column": 28 } + }, + { + "tagName": "arm_none_linux_gnueabihf", + "attributeValues": { + "version": "13.2.1" + }, + "devDependency": false, + "location": { + "file": "@@//:MODULE.bazel", + "line": 20, + "column": 39 + } } ], "hasDevUseExtension": false, @@ -848,6 +865,50 @@ "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" } }, + "arm_none_linux_gnueabihf_linux_x86_64": { + "bzlFile": "@@//:deps.bzl", + "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", + "attributes": { + "toolchain_prefix": "arm-none-linux-gnueabihf", + "name": "_main~arm_toolchain~arm_none_linux_gnueabihf_linux_x86_64", + "sha256": "df0f4927a67d1fd366ff81e40bd8c385a9324fbdde60437a512d106215f257b3", + "build_file": "@@//toolchain:compiler/nix.BUILD", + "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-linux-gnueabihf", + "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz?rev=adb0c0238c934aeeaa12c09609c5e6fc&hash=68DA67DE12CBAD82A0FA4B75247E866155C93053", + "patches": [ + "@@//toolchain:compiler/0001-Resolve-libc-relative-to-sysroot.patch" + ] + } + }, + "arm_none_linux_gnueabihf_linux_aarch64": { + "bzlFile": "@@//:deps.bzl", + "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", + "attributes": { + "toolchain_prefix": "arm-none-linux-gnueabihf", + "name": "_main~arm_toolchain~arm_none_linux_gnueabihf_linux_aarch64", + "sha256": "8ad384bb328bccc44396d85c8f8113b7b8c5e11bcfef322e77cda3ebe7baadb5", + "build_file": "@@//toolchain:compiler/nix.BUILD", + "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-linux-gnueabihf", + "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-aarch64-arm-none-linux-gnueabihf.tar.xz?rev=fbdb67e76c8349e5ad27a7c40fb270c9&hash=8CD3EBFFDC5E211275B705F6F9BCC0F6F5B4A53E", + "patches": [ + "@@//toolchain:compiler/0001-Resolve-libc-relative-to-sysroot.patch" + ] + } + }, + "arm_none_linux_gnueabihf_windows_x86_64": { + "bzlFile": "@@//:deps.bzl", + "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", + "attributes": { + "toolchain_prefix": "arm-none-linux-gnueabihf", + "name": "_main~arm_toolchain~arm_none_linux_gnueabihf_windows_x86_64", + "sha256": "047e72bcef8f7767691f36929a8c74ef66f717cf6264a31f48dd31bfb067f4c8", + "build_file": "@@//toolchain:compiler/win.BUILD", + "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:compiler/0001-Resolve-libc-relative-to-sysroot.patch" + ] + } + }, "arm_none_eabi": { "bzlFile": "@@//:deps.bzl", "ruleClassName": "arm_gnu_toolchain_repo", @@ -881,6 +942,15 @@ "url": "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-mac.tar.bz2?revision=c2c4fe0e-c0b6-4162-97e6-7707e12f2b6e&la=en&hash=EC9D4B5F5B050267B924F876B306D72CDF3BDDC0" } }, + "arm_none_linux_gnueabihf": { + "bzlFile": "@@//:deps.bzl", + "ruleClassName": "arm_gnu_toolchain_repo", + "attributes": { + "name": "_main~arm_toolchain~arm_none_linux_gnueabihf", + "toolchain_name": "arm_none_linux_gnueabihf", + "toolchain_prefix": "arm-none-linux-gnueabihf" + } + }, "arm_none_eabi_linux_aarch64": { "bzlFile": "@@//:deps.bzl", "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", diff --git a/examples/simple-linux/BUILD b/examples/simple-linux/BUILD new file mode 100644 index 0000000..3a4317a --- /dev/null +++ b/examples/simple-linux/BUILD @@ -0,0 +1,51 @@ +# project/BUILD.bazel + +load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + +cc_library( + name = "arm_library", + srcs = ["source/library.cpp"], + hdrs = ["includes/library.h"], + copts = [ + "-mcpu=cortex-a5", + "-mthumb", + ], + includes = ["includes"], + target_compatible_with = [ + "@platforms//cpu:arm", + "@platforms//os:linux", + ], +) + +cc_binary( + name = "arm_elf", + srcs = ["source/main.cpp"], + copts = [ + "-mcpu=cortex-a5", + "-mthumb", + ], + deps = [":arm_library"], +) + +platform_transition_filegroup( + name = "elf", + srcs = [":arm_elf"], + target_platform = "//platforms:arm_linux", +) + +genrule( + name = "bin", + srcs = [":elf"], + outs = ["mock.bin"], + cmd = "$(execpath @arm_none_linux_gnueabihf//:objcopy) -O binary $< $@", + tools = ["@arm_none_linux_gnueabihf//:objcopy"], +) + +genrule( + name = "hex", + srcs = [":elf"], + outs = ["mock.hex"], + cmd = "$(execpath @arm_none_linux_gnueabihf//:objcopy) -O ihex $< $@", + tools = ["@arm_none_linux_gnueabihf//:objcopy"], +) diff --git a/examples/simple-linux/includes/library.h b/examples/simple-linux/includes/library.h new file mode 100644 index 0000000..8d8469b --- /dev/null +++ b/examples/simple-linux/includes/library.h @@ -0,0 +1,4 @@ +#include + +uint16_t baz(uint8_t var); +uint32_t foo(void); \ No newline at end of file diff --git a/examples/simple-linux/source/library.cpp b/examples/simple-linux/source/library.cpp new file mode 100644 index 0000000..eef1ad8 --- /dev/null +++ b/examples/simple-linux/source/library.cpp @@ -0,0 +1,20 @@ +#include "library.h" +#include + +uint16_t baz(int a) +{ + return a * 2; +} + +uint32_t foo() +{ + static constexpr int k = 5; + return baz(k); +} + +uint16_t foobaz() +{ + std::vector vec(10); + vec.push_back(1); + return vec[0]; +} diff --git a/examples/simple-linux/source/main.cpp b/examples/simple-linux/source/main.cpp new file mode 100644 index 0000000..b61259d --- /dev/null +++ b/examples/simple-linux/source/main.cpp @@ -0,0 +1,5 @@ +// The simplest possible main function + +int main(){ + return 0; +} \ No newline at end of file From c49bf36f71febdfbced6c1418c526c08cdb0b07e Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Mon, 4 Mar 2024 15:39:25 -0600 Subject: [PATCH 10/23] Fix issue that caused tools to be resolved incorrectly Previously, the BUILD template for the cross-hosted toolchain external repository (host-specific) had a defect that caused the paths of tools to be resolved incorrectly. --- deps.bzl | 1 + toolchain/top.BUILD | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/deps.bzl b/deps.bzl index c9a7518..2fedc64 100644 --- a/deps.bzl +++ b/deps.bzl @@ -131,6 +131,7 @@ def _arm_gnu_toolchain_repo_impl(repository_ctx): Label("@arm_gnu_toolchain//toolchain:top.BUILD"), substitutions = { "%toolchain_name%": repository_ctx.attr.toolchain_name, + "%toolchain_prefix%": repository_ctx.attr.toolchain_prefix, }, ) diff --git a/toolchain/top.BUILD b/toolchain/top.BUILD index 2c0dea7..6884b02 100644 --- a/toolchain/top.BUILD +++ b/toolchain/top.BUILD @@ -15,7 +15,7 @@ TOOLS = tools + ["bin"] name = host, constraint_values = constraint_values, ) - for host, constraint_values in hosts.items() + for host, constraint_values in hosts['%toolchain_prefix%'].items() ] [ @@ -23,7 +23,7 @@ TOOLS = tools + ["bin"] name = tool, srcs = select({ host: ["@%toolchain_name%_{}//:{}".format(host, tool)] - for host in hosts.keys() + for host in hosts['%toolchain_prefix%'].keys() }), ) for tool in TOOLS From 853daf1b75763484e917791799e8729207365236 Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Mon, 4 Mar 2024 20:59:51 -0600 Subject: [PATCH 11/23] Make toolchain rules public --- MODULE.bazel.lock | 2 +- toolchain/toolchain.BUILD | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 5db3479..6ef1e0c 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -850,7 +850,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_toolchain": { "general": { - "bzlTransitiveDigest": "KX1j1lleBmumhGSbU9DNMEbRenKDagbmOH0rzUSkAiA=", + "bzlTransitiveDigest": "GgKuN4WAh5Tik/jTT4oagJlZyWxr4aeL592sQqzLUKM=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { diff --git a/toolchain/toolchain.BUILD b/toolchain/toolchain.BUILD index 0941aeb..48c7073 100644 --- a/toolchain/toolchain.BUILD +++ b/toolchain/toolchain.BUILD @@ -4,6 +4,8 @@ rendered into the //toolchain package of the generated toolchain repository. For example, "@arm_none_eabi//toolchain:*" """ +package(default_visibility = ["//visibility:public"]) + load( "@arm_gnu_toolchain//toolchain:toolchain.bzl", "%toolchain_name%_toolchain", From 7e3652c45f6f14a38133461ae90e23e41b1f7fa3 Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Fri, 8 Mar 2024 18:30:10 -0600 Subject: [PATCH 12/23] Hotfix for toolchain selection issue. Currently, there is an issue where the consuming MODULE.bazel is not capable of overriding the version of the toolchain specified in our MODULE.bazel. Create a FIXME comment in extensions.bzl. Previously, there was also an issue where selecting any toolchain version besides 9.x.x caused a failure when setting up the external repository, because the generated BUILD.bazel wasn't provided the version of the toolchain it was generating. --- MODULE.bazel | 2 +- deps.bzl | 3 +++ extensions.bzl | 8 ++++++-- toolchain/toolchain.BUILD | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 1df0882..1a55f32 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,7 +7,7 @@ module( bazel_dep(name = "platforms", version = "0.0.8") arm_toolchain = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_toolchain") -arm_toolchain.arm_none_eabi(version = "9.2.1") +arm_toolchain.arm_none_eabi(version = "13.2.1") use_repo( arm_toolchain, "arm_none_eabi", diff --git a/deps.bzl b/deps.bzl index 2fedc64..417f8b1 100644 --- a/deps.bzl +++ b/deps.bzl @@ -140,6 +140,7 @@ def _arm_gnu_toolchain_repo_impl(repository_ctx): Label("@arm_gnu_toolchain//toolchain:toolchain.BUILD"), substitutions = { "%toolchain_name%": repository_ctx.attr.toolchain_name, + "%version%": repository_ctx.attr.version, "%toolchain_prefix%": repository_ctx.attr.toolchain_prefix, }, ) @@ -149,6 +150,7 @@ arm_gnu_toolchain_repo = repository_rule( attrs = { 'toolchain_name': attr.string(mandatory=True), 'toolchain_prefix': attr.string(mandatory=True), + 'version': attr.string(mandatory=True), }, ) @@ -157,6 +159,7 @@ def arm_gnu_toolchain_deps(toolchain, toolchain_prefix, version, archives): name = toolchain, toolchain_name = toolchain, toolchain_prefix = toolchain_prefix, + version = version, ) for attrs in archives[version]: diff --git a/extensions.bzl b/extensions.bzl index 9f06a41..32b4dcd 100644 --- a/extensions.bzl +++ b/extensions.bzl @@ -6,11 +6,15 @@ load( def _arm_toolchain_impl(ctx): for mod in ctx.modules: + # FIXME: The module extension fails if this is removed, but it + # prevents the ability to override the toolchain version in the + # consuming MODULE.bazel. We should implement some form of MSV + # selection here. if mod.name == "arm_gnu_toolchain": for attr in mod.tags.arm_none_eabi: - arm_none_eabi_deps(attr.version) + arm_none_eabi_deps(version = attr.version) for attr in mod.tags.arm_none_linux_gnueabihf: - arm_none_linux_gnueabihf_deps(attr.version) + arm_none_linux_gnueabihf_deps(version = attr.version) _toolchain = tag_class(attrs = { "version": attr.string(), diff --git a/toolchain/toolchain.BUILD b/toolchain/toolchain.BUILD index 48c7073..b43bbc6 100644 --- a/toolchain/toolchain.BUILD +++ b/toolchain/toolchain.BUILD @@ -15,6 +15,7 @@ load( [ %toolchain_name%_toolchain( name = name, + version = "%version%", target_compatible_with = constraints, ) for name, constraints in target_constraints['%toolchain_prefix%'].items() From 543b3c5d737bef8185a04eab10113df5374d0eca Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Thu, 14 Mar 2024 18:10:42 -0500 Subject: [PATCH 13/23] Use MSV to select the version of the toolchain This commit fixes an issue with the bzlmod extension that prevents consuming MODULE.bazel files from being able to select the version of the toolchain. Now, the bzlmod extension selects the minimum version from the modules that have requested the toolchain and uses that for the system. This allows consumers to upgrade the version of arm_gnu_toolchain without needing to ugprade their compiler version, as well. --- MODULE.bazel | 4 +++ MODULE.bazel.lock | 38 +++++++++++++------------ extensions.bzl | 72 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 86 insertions(+), 28 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 1a55f32..aa72dae 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,6 +7,10 @@ module( bazel_dep(name = "platforms", version = "0.0.8") arm_toolchain = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_toolchain") +# NOTE: It's important that we update these versions whenever a new toolchain +# version is added--otherwise the Minimum Selected Version algorithm in the +# 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") use_repo( arm_toolchain, diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 6ef1e0c..21c80b2 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 3, - "moduleFileHash": "83a3bf69a53475bc86fe8eb51a0e3b024ad186d35aad4d1d4b5d5b54a44c66e9", + "moduleFileHash": "cc7772f488e471a657eb70ac10d6e02215a54e58fa654a90b9fdfbf5e0cfb2e3", "flags": { "cmdRegistries": [ "https://bcr.bazel.build/" @@ -53,12 +53,12 @@ { "tagName": "arm_none_eabi", "attributeValues": { - "version": "9.2.1" + "version": "13.2.1" }, "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 10, + "line": 14, "column": 28 } }, @@ -70,7 +70,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 20, + "line": 24, "column": 39 } } @@ -850,7 +850,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_toolchain": { "general": { - "bzlTransitiveDigest": "GgKuN4WAh5Tik/jTT4oagJlZyWxr4aeL592sQqzLUKM=", + "bzlTransitiveDigest": "nABIo5MPqdeY9ulas4PTAWCcl835IUiTJpM/wuIMWnw=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -861,8 +861,8 @@ "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_toolchain~arm_none_eabi_windows_x86_64", "build_file": "@@//toolchain:compiler/win.BUILD", - "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" + "sha256": "51d933f00578aa28016c5e3c84f94403274ea7915539f8e56c13e2196437d18f", + "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" } }, "arm_none_linux_gnueabihf_linux_x86_64": { @@ -915,7 +915,8 @@ "attributes": { "name": "_main~arm_toolchain~arm_none_eabi", "toolchain_name": "arm_none_eabi", - "toolchain_prefix": "arm-none-eabi" + "toolchain_prefix": "arm-none-eabi", + "version": "13.2.1" } }, "arm_none_eabi_linux_x86_64": { @@ -924,10 +925,10 @@ "attributes": { "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_toolchain~arm_none_eabi_linux_x86_64", - "sha256": "bcd840f839d5bf49279638e9f67890b2ef3a7c9c7a9b25271e83ec4ff41d177a", + "sha256": "6cd1bbc1d9ae57312bcd169ae283153a9572bd6a8e4eeae2fedfbc33b115fdbb", "build_file": "@@//toolchain:compiler/nix.BUILD", - "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", - "url": "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2?revision=108bd959-44bd-4619-9c19-26187abf5225&la=en&hash=E788CE92E5DFD64B2A8C246BBA91A249CB8E2D2D" + "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", + "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz?rev=e434b9ea4afc4ed7998329566b764309&hash=688C370BF08399033CA9DE3C1CC8CF8E31D8C441" } }, "arm_none_eabi_darwin_x86_64": { @@ -936,10 +937,10 @@ "attributes": { "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_toolchain~arm_none_eabi_darwin_x86_64", - "sha256": "1249f860d4155d9c3ba8f30c19e7a88c5047923cea17e0d08e633f12408f01f0", + "sha256": "075faa4f3e8eb45e59144858202351a28706f54a6ec17eedd88c9fb9412372cc", "build_file": "@@//toolchain:compiler/nix.BUILD", - "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", - "url": "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-mac.tar.bz2?revision=c2c4fe0e-c0b6-4162-97e6-7707e12f2b6e&la=en&hash=EC9D4B5F5B050267B924F876B306D72CDF3BDDC0" + "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", + "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-darwin-x86_64-arm-none-eabi.tar.xz?rev=a3d8c87bb0af4c40b7d7e0e291f6541b&hash=10927356ACA904E1A0122794E036E8DDE7D8435D" } }, "arm_none_linux_gnueabihf": { @@ -948,7 +949,8 @@ "attributes": { "name": "_main~arm_toolchain~arm_none_linux_gnueabihf", "toolchain_name": "arm_none_linux_gnueabihf", - "toolchain_prefix": "arm-none-linux-gnueabihf" + "toolchain_prefix": "arm-none-linux-gnueabihf", + "version": "13.2.1" } }, "arm_none_eabi_linux_aarch64": { @@ -957,10 +959,10 @@ "attributes": { "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_toolchain~arm_none_eabi_linux_aarch64", - "sha256": "1f5b9309006737950b2218250e6bb392e2d68d4f1a764fe66be96e2a78888d83", + "sha256": "8fd8b4a0a8d44ab2e195ccfbeef42223dfb3ede29d80f14dcf2183c34b8d199a", "build_file": "@@//toolchain:compiler/nix.BUILD", - "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", - "url": "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-aarch64-linux.tar.bz2?revision=4583ce78-e7e7-459a-ad9f-bff8e94839f1&la=en&hash=550DB9C0184B7C70B6C020A5DCBB9D1E156264B7" + "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi", + "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-aarch64-arm-none-eabi.tar.xz?rev=17baf091942042768d55c9a304610954&hash=7F32B9E3ADFAFC4F8F74C30EBBBFECEB1AC96B60" } } }, diff --git a/extensions.bzl b/extensions.bzl index 32b4dcd..f55f5cd 100644 --- a/extensions.bzl +++ b/extensions.bzl @@ -4,17 +4,69 @@ load( "arm_none_linux_gnueabihf_deps", ) +def compare_versions(left, right): + """ + Compare two version strings, assuming that they're both of the form + major.minor.patch. + + Returns: + -1 if left < right + 0 if left == right + 1 if left > right + """ + left_parts = [int(i) for i in left.split('.')] + right_parts = [int(i) for i in right.split('.')] + for i in range(3): + if left_parts[0] < right_parts[0]: + return -1 + + if left_parts[0] > right_parts[0]: + return 1 + + return 0 + +def minimum_supported_version(versions): + """Obtains the minimum version from the list of version strings.""" + if not len(versions): + return None + + if 1 == len(versions): + return versions[0] + + minimum = versions[0] + for version in versions[1:]: + if compare_versions(minimum, version) > 0: + minimum = version + + return minimum + +def get_toolchain_versions(module_ctx, tag_class): + """Extract toolchain versions from tag classes obtained by evaluating + the lambda on each module.""" + versions = [] + for mod in module_ctx.modules: + for attr in tag_class(mod): + versions.append(attr.version) + return versions + def _arm_toolchain_impl(ctx): - for mod in ctx.modules: - # FIXME: The module extension fails if this is removed, but it - # prevents the ability to override the toolchain version in the - # consuming MODULE.bazel. We should implement some form of MSV - # selection here. - if mod.name == "arm_gnu_toolchain": - for attr in mod.tags.arm_none_eabi: - arm_none_eabi_deps(version = attr.version) - for attr in mod.tags.arm_none_linux_gnueabihf: - arm_none_linux_gnueabihf_deps(version = attr.version) + selected_baremetal_version = minimum_supported_version( + get_toolchain_versions( + ctx, + lambda mod: mod.tags.arm_none_eabi, + ) + ) + if selected_baremetal_version: + arm_none_eabi_deps(version = selected_baremetal_version) + + selected_linux_version = minimum_supported_version( + get_toolchain_versions( + ctx, + lambda mod: mod.tags.arm_none_linux_gnueabihf, + ) + ) + if selected_linux_version: + arm_none_linux_gnueabihf_deps(version = selected_linux_version) _toolchain = tag_class(attrs = { "version": attr.string(), From 2d9a10107db5c9bff6ac738bbceadc6608e48d39 Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sat, 16 Mar 2024 12:05:42 -0500 Subject: [PATCH 14/23] Consolidate templates for generated repos This commit combines the two previous BUILD templates for the generated repos, nix.BUILD and win.BUILD, into one templatized compiler.BUILD template, and it also moves the other existing templates into the toolchain/templates folder. --- MODULE.bazel.lock | 48 ++++++----------- deps.bzl | 29 ++++------- toolchain/compiler/nix.BUILD | 51 ------------------- ...001-Resolve-libc-relative-to-sysroot.patch | 0 .../win.BUILD => templates/compiler.BUILD} | 7 ++- toolchain/{ => templates}/toolchain.BUILD | 0 toolchain/{ => templates}/top.BUILD | 0 7 files changed, 32 insertions(+), 103 deletions(-) delete mode 100644 toolchain/compiler/nix.BUILD rename toolchain/{compiler => patches}/0001-Resolve-libc-relative-to-sysroot.patch (100%) rename toolchain/{compiler/win.BUILD => templates/compiler.BUILD} (78%) rename toolchain/{ => templates}/toolchain.BUILD (100%) rename toolchain/{ => templates}/top.BUILD (100%) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 21c80b2..fee46c5 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -850,7 +850,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_toolchain": { "general": { - "bzlTransitiveDigest": "nABIo5MPqdeY9ulas4PTAWCcl835IUiTJpM/wuIMWnw=", + "bzlTransitiveDigest": "LtrsY8GJj9yBjTo2/9Z5KEDpQjsbDVxhbPOUN4dHknA=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -860,9 +860,9 @@ "attributes": { "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_toolchain~arm_none_eabi_windows_x86_64", - "build_file": "@@//toolchain:compiler/win.BUILD", "sha256": "51d933f00578aa28016c5e3c84f94403274ea7915539f8e56c13e2196437d18f", - "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" + "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" } }, "arm_none_linux_gnueabihf_linux_x86_64": { @@ -872,11 +872,10 @@ "toolchain_prefix": "arm-none-linux-gnueabihf", "name": "_main~arm_toolchain~arm_none_linux_gnueabihf_linux_x86_64", "sha256": "df0f4927a67d1fd366ff81e40bd8c385a9324fbdde60437a512d106215f257b3", - "build_file": "@@//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-linux-gnueabihf", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz?rev=adb0c0238c934aeeaa12c09609c5e6fc&hash=68DA67DE12CBAD82A0FA4B75247E866155C93053", "patches": [ - "@@//toolchain:compiler/0001-Resolve-libc-relative-to-sysroot.patch" + "@@//toolchain:patches/0001-Resolve-libc-relative-to-sysroot.patch" ] } }, @@ -887,11 +886,10 @@ "toolchain_prefix": "arm-none-linux-gnueabihf", "name": "_main~arm_toolchain~arm_none_linux_gnueabihf_linux_aarch64", "sha256": "8ad384bb328bccc44396d85c8f8113b7b8c5e11bcfef322e77cda3ebe7baadb5", - "build_file": "@@//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-linux-gnueabihf", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-aarch64-arm-none-linux-gnueabihf.tar.xz?rev=fbdb67e76c8349e5ad27a7c40fb270c9&hash=8CD3EBFFDC5E211275B705F6F9BCC0F6F5B4A53E", "patches": [ - "@@//toolchain:compiler/0001-Resolve-libc-relative-to-sysroot.patch" + "@@//toolchain:patches/0001-Resolve-libc-relative-to-sysroot.patch" ] } }, @@ -902,11 +900,11 @@ "toolchain_prefix": "arm-none-linux-gnueabihf", "name": "_main~arm_toolchain~arm_none_linux_gnueabihf_windows_x86_64", "sha256": "047e72bcef8f7767691f36929a8c74ef66f717cf6264a31f48dd31bfb067f4c8", - "build_file": "@@//toolchain:compiler/win.BUILD", "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:compiler/0001-Resolve-libc-relative-to-sysroot.patch" - ] + "@@//toolchain:patches/0001-Resolve-libc-relative-to-sysroot.patch" + ], + "bin_extension": ".exe" } }, "arm_none_eabi": { @@ -926,7 +924,6 @@ "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_toolchain~arm_none_eabi_linux_x86_64", "sha256": "6cd1bbc1d9ae57312bcd169ae283153a9572bd6a8e4eeae2fedfbc33b115fdbb", - "build_file": "@@//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz?rev=e434b9ea4afc4ed7998329566b764309&hash=688C370BF08399033CA9DE3C1CC8CF8E31D8C441" } @@ -938,7 +935,6 @@ "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_toolchain~arm_none_eabi_darwin_x86_64", "sha256": "075faa4f3e8eb45e59144858202351a28706f54a6ec17eedd88c9fb9412372cc", - "build_file": "@@//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-darwin-x86_64-arm-none-eabi.tar.xz?rev=a3d8c87bb0af4c40b7d7e0e291f6541b&hash=10927356ACA904E1A0122794E036E8DDE7D8435D" } @@ -960,7 +956,6 @@ "toolchain_prefix": "arm-none-eabi", "name": "_main~arm_toolchain~arm_none_eabi_linux_aarch64", "sha256": "8fd8b4a0a8d44ab2e195ccfbeef42223dfb3ede29d80f14dcf2183c34b8d199a", - "build_file": "@@//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-aarch64-arm-none-eabi.tar.xz?rev=17baf091942042768d55c9a304610954&hash=7F32B9E3ADFAFC4F8F74C30EBBBFECEB1AC96B60" } @@ -1001,7 +996,13 @@ } } }, - "recordedRepoMappingEntries": [] + "recordedRepoMappingEntries": [ + [ + "apple_support~1.5.0", + "bazel_tools", + "bazel_tools" + ] + ] } }, "@@aspect_bazel_lib~2.0.0//lib:extensions.bzl%toolchains": { @@ -1459,25 +1460,6 @@ ] } }, - "@@bazel_tools//tools/osx:xcode_configure.bzl%xcode_configure_extension": { - "general": { - "bzlTransitiveDigest": "Qh2bWTU6QW6wkrd87qrU4YeY+SG37Nvw3A0PR4Y0L2Y=", - "accumulatedFileDigests": {}, - "envVariables": {}, - "generatedRepoSpecs": { - "local_config_xcode": { - "bzlFile": "@@bazel_tools//tools/osx:xcode_configure.bzl", - "ruleClassName": "xcode_autoconf", - "attributes": { - "name": "bazel_tools~xcode_configure_extension~local_config_xcode", - "xcode_locator": "@bazel_tools//tools/osx:xcode_locator.m", - "remote_xcode": "" - } - } - }, - "recordedRepoMappingEntries": [] - } - }, "@@bazel_tools//tools/sh:sh_configure.bzl%sh_configure_extension": { "general": { "bzlTransitiveDigest": "hp4NgmNjEg5+xgvzfh6L83bt9/aiiWETuNpwNuF1MSU=", diff --git a/deps.bzl b/deps.bzl index 417f8b1..78b2a08 100644 --- a/deps.bzl +++ b/deps.bzl @@ -11,58 +11,52 @@ GCC_ARM_NONE_EABI = { { "name": "arm_none_eabi_darwin_x86_64", "sha256": "1249f860d4155d9c3ba8f30c19e7a88c5047923cea17e0d08e633f12408f01f0", - "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", "url": "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-mac.tar.bz2?revision=c2c4fe0e-c0b6-4162-97e6-7707e12f2b6e&la=en&hash=EC9D4B5F5B050267B924F876B306D72CDF3BDDC0", }, { "name": "arm_none_eabi_linux_x86_64", "sha256": "bcd840f839d5bf49279638e9f67890b2ef3a7c9c7a9b25271e83ec4ff41d177a", - "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", "url": "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2?revision=108bd959-44bd-4619-9c19-26187abf5225&la=en&hash=E788CE92E5DFD64B2A8C246BBA91A249CB8E2D2D", }, { "name": "arm_none_eabi_linux_aarch64", "sha256": "1f5b9309006737950b2218250e6bb392e2d68d4f1a764fe66be96e2a78888d83", - "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "gcc-arm-none-eabi-9-2019-q4-major", "url": "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-aarch64-linux.tar.bz2?revision=4583ce78-e7e7-459a-ad9f-bff8e94839f1&la=en&hash=550DB9C0184B7C70B6C020A5DCBB9D1E156264B7", }, { "name": "arm_none_eabi_windows_x86_64", - "build_file": "@arm_gnu_toolchain//toolchain:compiler/win.BUILD", "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": [ { "name": "arm_none_eabi_darwin_x86_64", "sha256": "075faa4f3e8eb45e59144858202351a28706f54a6ec17eedd88c9fb9412372cc", - "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-darwin-x86_64-arm-none-eabi.tar.xz?rev=a3d8c87bb0af4c40b7d7e0e291f6541b&hash=10927356ACA904E1A0122794E036E8DDE7D8435D", }, { "name": "arm_none_eabi_linux_x86_64", "sha256": "6cd1bbc1d9ae57312bcd169ae283153a9572bd6a8e4eeae2fedfbc33b115fdbb", - "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz?rev=e434b9ea4afc4ed7998329566b764309&hash=688C370BF08399033CA9DE3C1CC8CF8E31D8C441", }, { "name": "arm_none_eabi_linux_aarch64", "sha256": "8fd8b4a0a8d44ab2e195ccfbeef42223dfb3ede29d80f14dcf2183c34b8d199a", - "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-aarch64-arm-none-eabi.tar.xz?rev=17baf091942042768d55c9a304610954&hash=7F32B9E3ADFAFC4F8F74C30EBBBFECEB1AC96B60", }, { "name": "arm_none_eabi_windows_x86_64", - "build_file": "@arm_gnu_toolchain//toolchain:compiler/win.BUILD", "sha256": "51d933f00578aa28016c5e3c84f94403274ea7915539f8e56c13e2196437d18f", "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", }, ], } @@ -72,25 +66,23 @@ GCC_ARM_NONE_LINUX_GNUEABIHF = { { "name": "arm_none_linux_gnueabihf_linux_x86_64", "sha256": "df0f4927a67d1fd366ff81e40bd8c385a9324fbdde60437a512d106215f257b3", - "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-linux-gnueabihf", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz?rev=adb0c0238c934aeeaa12c09609c5e6fc&hash=68DA67DE12CBAD82A0FA4B75247E866155C93053", - "patches": ["@arm_gnu_toolchain//toolchain:compiler/0001-Resolve-libc-relative-to-sysroot.patch"], + "patches": ["@arm_gnu_toolchain//toolchain:patches/0001-Resolve-libc-relative-to-sysroot.patch"], }, { "name": "arm_none_linux_gnueabihf_linux_aarch64", "sha256": "8ad384bb328bccc44396d85c8f8113b7b8c5e11bcfef322e77cda3ebe7baadb5", - "build_file": "@arm_gnu_toolchain//toolchain:compiler/nix.BUILD", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-linux-gnueabihf", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-aarch64-arm-none-linux-gnueabihf.tar.xz?rev=fbdb67e76c8349e5ad27a7c40fb270c9&hash=8CD3EBFFDC5E211275B705F6F9BCC0F6F5B4A53E", - "patches": ["@arm_gnu_toolchain//toolchain:compiler/0001-Resolve-libc-relative-to-sysroot.patch"], + "patches": ["@arm_gnu_toolchain//toolchain:patches/0001-Resolve-libc-relative-to-sysroot.patch"], }, { "name": "arm_none_linux_gnueabihf_windows_x86_64", "sha256": "047e72bcef8f7767691f36929a8c74ef66f717cf6264a31f48dd31bfb067f4c8", - "build_file": "@arm_gnu_toolchain//toolchain:compiler/win.BUILD", "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": ["@arm_gnu_toolchain//toolchain:compiler/0001-Resolve-libc-relative-to-sysroot.patch"], + "patches": ["@arm_gnu_toolchain//toolchain:patches/0001-Resolve-libc-relative-to-sysroot.patch"], + "bin_extension": ".exe", }, ], } @@ -104,9 +96,10 @@ def _arm_gnu_cross_hosted_platform_specific_repo_impl(repository_ctx): ) repository_ctx.template( "BUILD.bazel", - Label(repository_ctx.attr.build_file), + Label("@arm_gnu_toolchain//toolchain:templates/compiler.BUILD"), substitutions = { "%prefix%": repository_ctx.attr.toolchain_prefix, + "%bin_extension%": repository_ctx.attr.bin_extension, }, ) for patch in repository_ctx.attr.patches: @@ -117,10 +110,10 @@ arm_gnu_cross_hosted_platform_specific_repo = repository_rule( attrs = { 'sha256': attr.string(mandatory=True), 'url': attr.string(mandatory=True), - 'build_file': attr.label(mandatory=True), 'toolchain_prefix': attr.string(mandatory=True), 'strip_prefix': attr.string(), 'patches': attr.label_list(), + 'bin_extension': attr.string(default = ""), }, ) @@ -128,7 +121,7 @@ def _arm_gnu_toolchain_repo_impl(repository_ctx): """Defines the top-level toolchain repository.""" repository_ctx.template( "BUILD", - Label("@arm_gnu_toolchain//toolchain:top.BUILD"), + Label("@arm_gnu_toolchain//toolchain:templates/top.BUILD"), substitutions = { "%toolchain_name%": repository_ctx.attr.toolchain_name, "%toolchain_prefix%": repository_ctx.attr.toolchain_prefix, @@ -137,7 +130,7 @@ def _arm_gnu_toolchain_repo_impl(repository_ctx): repository_ctx.template( "toolchain/BUILD", - Label("@arm_gnu_toolchain//toolchain:toolchain.BUILD"), + Label("@arm_gnu_toolchain//toolchain:templates/toolchain.BUILD"), substitutions = { "%toolchain_name%": repository_ctx.attr.toolchain_name, "%version%": repository_ctx.attr.version, diff --git a/toolchain/compiler/nix.BUILD b/toolchain/compiler/nix.BUILD deleted file mode 100644 index 6201d80..0000000 --- a/toolchain/compiler/nix.BUILD +++ /dev/null @@ -1,51 +0,0 @@ -load("@arm_gnu_toolchain//toolchain:toolchain.bzl", "tools") - -package(default_visibility = ["//visibility:public"]) - -# export the executable files to make them available for direct use. -exports_files(glob(["**"], exclude_directories=0)) - -PREFIX = "%prefix%" - -# executables. -[ - filegroup( - name = tool, - srcs = ["bin/{}-{}".format(PREFIX, tool)], - ) - for tool in tools -] - -# libraries and headers. -filegroup( - name = "compiler_pieces", - srcs = glob([ - "bin/**", - "libexec/**", - "{}/**".format(PREFIX), - "lib/**", - "lib/gcc/{}/**".format(PREFIX), - ]), -) - -# files for executing compiler. -filegroup( - name = "compiler_files", - srcs = [":compiler_pieces"], -) - -filegroup( - name = "ar_files", - srcs = [":compiler_pieces"], -) - -filegroup( - name = "linker_files", - srcs = [":compiler_pieces"], -) - -# collection of executables. -filegroup( - name = "compiler_components", - srcs = [":compiler_pieces"], -) diff --git a/toolchain/compiler/0001-Resolve-libc-relative-to-sysroot.patch b/toolchain/patches/0001-Resolve-libc-relative-to-sysroot.patch similarity index 100% rename from toolchain/compiler/0001-Resolve-libc-relative-to-sysroot.patch rename to toolchain/patches/0001-Resolve-libc-relative-to-sysroot.patch diff --git a/toolchain/compiler/win.BUILD b/toolchain/templates/compiler.BUILD similarity index 78% rename from toolchain/compiler/win.BUILD rename to toolchain/templates/compiler.BUILD index 648336c..4bc3116 100644 --- a/toolchain/compiler/win.BUILD +++ b/toolchain/templates/compiler.BUILD @@ -1,3 +1,8 @@ +""" +This BUILD file marks the top of the host-specific cross-toolchain repository. +If the host needs @arm_none_eabi_linux_x86_64, this is the build file at the +top of that repository. +""" load("@arm_gnu_toolchain//toolchain:toolchain.bzl", "tools") package(default_visibility = ["//visibility:public"]) @@ -11,7 +16,7 @@ PREFIX = "%prefix%" [ filegroup( name = tool, - srcs = ["bin/{}-{}.exe".format(PREFIX, tool)], + srcs = ["bin/{}-{}%bin_extension%".format(PREFIX, tool)], ) for tool in tools ] diff --git a/toolchain/toolchain.BUILD b/toolchain/templates/toolchain.BUILD similarity index 100% rename from toolchain/toolchain.BUILD rename to toolchain/templates/toolchain.BUILD diff --git a/toolchain/top.BUILD b/toolchain/templates/top.BUILD similarity index 100% rename from toolchain/top.BUILD rename to toolchain/templates/top.BUILD From 4d1793eefc8c1b2a23fb0ea0a9bc4b8a12076cdd Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sat, 16 Mar 2024 12:40:15 -0500 Subject: [PATCH 15/23] Fix various custom toolchain issues Previously, there was a change that required the version of the toolchain to be specified in the cc_arm_*_config rules. This isn't ideal, because it requires consumers to list the version in two places. So instead, introduce some new filegroup targets in the cross-hosted toolchain repository that allows these rules to infer the toolchain version. Also fix some other existing issues with the examples. --- MODULE.bazel.lock | 31 ++++++++++++++++++++++++++++-- deps.bzl | 9 +++++++-- toolchain/templates/compiler.BUILD | 25 ++++++++++++++++++++++-- toolchain/toolchain.bzl | 10 ++-------- 4 files changed, 61 insertions(+), 14 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index fee46c5..02c51df 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -850,7 +850,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_toolchain": { "general": { - "bzlTransitiveDigest": "LtrsY8GJj9yBjTo2/9Z5KEDpQjsbDVxhbPOUN4dHknA=", + "bzlTransitiveDigest": "ZBjbAO9SvG43wcxInVi5XfotuubwnPLpdvYQlpOQYzQ=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -859,8 +859,10 @@ "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { "toolchain_prefix": "arm-none-eabi", + "version": "13.2.1", "name": "_main~arm_toolchain~arm_none_eabi_windows_x86_64", "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" } @@ -870,6 +872,7 @@ "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { "toolchain_prefix": "arm-none-linux-gnueabihf", + "version": "13.2.1", "name": "_main~arm_toolchain~arm_none_linux_gnueabihf_linux_x86_64", "sha256": "df0f4927a67d1fd366ff81e40bd8c385a9324fbdde60437a512d106215f257b3", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-linux-gnueabihf", @@ -884,6 +887,7 @@ "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { "toolchain_prefix": "arm-none-linux-gnueabihf", + "version": "13.2.1", "name": "_main~arm_toolchain~arm_none_linux_gnueabihf_linux_aarch64", "sha256": "8ad384bb328bccc44396d85c8f8113b7b8c5e11bcfef322e77cda3ebe7baadb5", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-linux-gnueabihf", @@ -898,6 +902,7 @@ "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { "toolchain_prefix": "arm-none-linux-gnueabihf", + "version": "13.2.1", "name": "_main~arm_toolchain~arm_none_linux_gnueabihf_windows_x86_64", "sha256": "047e72bcef8f7767691f36929a8c74ef66f717cf6264a31f48dd31bfb067f4c8", "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", @@ -922,6 +927,7 @@ "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { "toolchain_prefix": "arm-none-eabi", + "version": "13.2.1", "name": "_main~arm_toolchain~arm_none_eabi_linux_x86_64", "sha256": "6cd1bbc1d9ae57312bcd169ae283153a9572bd6a8e4eeae2fedfbc33b115fdbb", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", @@ -933,9 +939,10 @@ "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { "toolchain_prefix": "arm-none-eabi", + "version": "13.2.1", "name": "_main~arm_toolchain~arm_none_eabi_darwin_x86_64", "sha256": "075faa4f3e8eb45e59144858202351a28706f54a6ec17eedd88c9fb9412372cc", - "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", + "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-darwin-x86_64-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-darwin-x86_64-arm-none-eabi.tar.xz?rev=a3d8c87bb0af4c40b7d7e0e291f6541b&hash=10927356ACA904E1A0122794E036E8DDE7D8435D" } }, @@ -954,6 +961,7 @@ "ruleClassName": "arm_gnu_cross_hosted_platform_specific_repo", "attributes": { "toolchain_prefix": "arm-none-eabi", + "version": "13.2.1", "name": "_main~arm_toolchain~arm_none_eabi_linux_aarch64", "sha256": "8fd8b4a0a8d44ab2e195ccfbeef42223dfb3ede29d80f14dcf2183c34b8d199a", "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi", @@ -1460,6 +1468,25 @@ ] } }, + "@@bazel_tools//tools/osx:xcode_configure.bzl%xcode_configure_extension": { + "general": { + "bzlTransitiveDigest": "Qh2bWTU6QW6wkrd87qrU4YeY+SG37Nvw3A0PR4Y0L2Y=", + "accumulatedFileDigests": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "local_config_xcode": { + "bzlFile": "@@bazel_tools//tools/osx:xcode_configure.bzl", + "ruleClassName": "xcode_autoconf", + "attributes": { + "name": "bazel_tools~xcode_configure_extension~local_config_xcode", + "xcode_locator": "@bazel_tools//tools/osx:xcode_locator.m", + "remote_xcode": "" + } + } + }, + "recordedRepoMappingEntries": [] + } + }, "@@bazel_tools//tools/sh:sh_configure.bzl%sh_configure_extension": { "general": { "bzlTransitiveDigest": "hp4NgmNjEg5+xgvzfh6L83bt9/aiiWETuNpwNuF1MSU=", diff --git a/deps.bzl b/deps.bzl index 78b2a08..eae8e5f 100644 --- a/deps.bzl +++ b/deps.bzl @@ -37,7 +37,7 @@ GCC_ARM_NONE_EABI = { { "name": "arm_none_eabi_darwin_x86_64", "sha256": "075faa4f3e8eb45e59144858202351a28706f54a6ec17eedd88c9fb9412372cc", - "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", + "strip_prefix": "arm-gnu-toolchain-13.2.Rel1-darwin-x86_64-arm-none-eabi", "url": "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-darwin-x86_64-arm-none-eabi.tar.xz?rev=a3d8c87bb0af4c40b7d7e0e291f6541b&hash=10927356ACA904E1A0122794E036E8DDE7D8435D", }, { @@ -55,6 +55,7 @@ GCC_ARM_NONE_EABI = { { "name": "arm_none_eabi_windows_x86_64", "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", }, @@ -98,7 +99,8 @@ def _arm_gnu_cross_hosted_platform_specific_repo_impl(repository_ctx): "BUILD.bazel", Label("@arm_gnu_toolchain//toolchain:templates/compiler.BUILD"), substitutions = { - "%prefix%": repository_ctx.attr.toolchain_prefix, + "%toolchain_prefix%": repository_ctx.attr.toolchain_prefix, + "%version%": repository_ctx.attr.version, "%bin_extension%": repository_ctx.attr.bin_extension, }, ) @@ -111,6 +113,7 @@ arm_gnu_cross_hosted_platform_specific_repo = repository_rule( 'sha256': attr.string(mandatory=True), 'url': attr.string(mandatory=True), 'toolchain_prefix': attr.string(mandatory=True), + 'version': attr.string(mandatory=True), 'strip_prefix': attr.string(), 'patches': attr.label_list(), 'bin_extension': attr.string(default = ""), @@ -124,6 +127,7 @@ def _arm_gnu_toolchain_repo_impl(repository_ctx): Label("@arm_gnu_toolchain//toolchain:templates/top.BUILD"), substitutions = { "%toolchain_name%": repository_ctx.attr.toolchain_name, + "%version%": repository_ctx.attr.version, "%toolchain_prefix%": repository_ctx.attr.toolchain_prefix, }, ) @@ -158,6 +162,7 @@ def arm_gnu_toolchain_deps(toolchain, toolchain_prefix, version, archives): for attrs in archives[version]: arm_gnu_cross_hosted_platform_specific_repo( toolchain_prefix=toolchain_prefix, + version = version, **attrs, ) diff --git a/toolchain/templates/compiler.BUILD b/toolchain/templates/compiler.BUILD index 4bc3116..5255ab1 100644 --- a/toolchain/templates/compiler.BUILD +++ b/toolchain/templates/compiler.BUILD @@ -10,7 +10,8 @@ package(default_visibility = ["//visibility:public"]) # export the executable files to make them available for direct use. exports_files(glob(["**"], exclude_directories = 0)) -PREFIX = "%prefix%" +PREFIX = "%toolchain_prefix%" +VERSION = "%version%" # executables. [ @@ -21,7 +22,27 @@ PREFIX = "%prefix%" for tool in tools ] -# libraries and headers. +filegroup( + name = "include_path", + srcs = [ + "{}/include".format(PREFIX), + "lib/gcc/{}/{}/include".format(PREFIX, VERSION), + "lib/gcc/{}/{}/include-fixed".format(PREFIX, VERSION), + "{}/include/c++/{}".format(PREFIX, VERSION), + "{}/include/c++/{}/{}".format(PREFIX, VERSION, PREFIX), + ], +) + +# Just the components to add to the library path. +filegroup( + name = "library_path", + srcs = [ + PREFIX, + "{}/lib".format(PREFIX), + ] + glob(["lib/gcc/{}/*".format(PREFIX)]), +) + +# libraries, headers and executables. filegroup( name = "compiler_pieces", srcs = glob([ diff --git a/toolchain/toolchain.bzl b/toolchain/toolchain.bzl index 08748b3..f08eb33 100644 --- a/toolchain/toolchain.bzl +++ b/toolchain/toolchain.bzl @@ -69,16 +69,10 @@ def _arm_gnu_toolchain(name, toolchain = "", toolchain_prefix = "", toolchain_identifier = "{}_{}_{}".format(toolchain, host, name), toolchain_bins = "@{}_{}//:compiler_components".format(toolchain, host), include_path = [ - "@{}_{}//:{}/include".format(toolchain, host, toolchain_prefix), - "@{}_{}//:lib/gcc/{}/{}/include".format(toolchain, host, toolchain_prefix, version), - "@{}_{}//:lib/gcc/{}/{}/include-fixed".format(toolchain, host, toolchain_prefix, version), - "@{}_{}//:{}/include/c++/{}".format(toolchain, host, toolchain_prefix, version), - "@{}_{}//:{}/include/c++/{}/{}".format(toolchain, host, toolchain_prefix, version, toolchain_prefix), + "@{}_{}//:include_path".format(toolchain, host), ], library_path = [ - "@{}_{}//:{}".format(toolchain, host, toolchain_prefix), - "@{}_{}//:{}/lib".format(toolchain, host, toolchain_prefix), - "@{}_{}//:lib/gcc/{}/{}".format(toolchain, host, toolchain_prefix, version), + "@{}_{}//:library_path".format(toolchain, host), ], copts = copts, linkopts = linkopts, From 1fc5bae2321e148c1636cdc7481364ab9103bfd6 Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sat, 16 Mar 2024 14:14:56 -0500 Subject: [PATCH 16/23] Slightly reorganize examples Organize the examples by toolchain so that CI workflows can selectively build examples based on which toolchains are available for the host platform. --- .github/workflows/mac.yml | 4 ++-- MODULE.bazel | 2 +- MODULE.bazel.lock | 4 ++-- examples/{simple-linux => arm-linux/simple}/BUILD | 0 .../{simple-linux => arm-linux/simple}/includes/library.h | 0 .../{simple-linux => arm-linux/simple}/source/library.cpp | 0 examples/{simple-linux => arm-linux/simple}/source/main.cpp | 0 examples/{ => arm-none}/custom/BUILD | 4 ++-- examples/{ => arm-none}/custom/README.md | 0 examples/{ => arm-none}/custom/cpu/BUILD | 0 examples/{ => arm-none}/custom/main.c | 0 examples/{ => arm-none}/custom/platform/BUILD | 4 ++-- examples/{ => arm-none}/custom/toolchain/BUILD | 4 ++-- examples/{ => arm-none}/simple/BUILD | 0 examples/{ => arm-none}/simple/includes/library.h | 0 examples/{ => arm-none}/simple/source/library.cpp | 0 examples/{ => arm-none}/simple/source/main.cpp | 0 examples/{ => arm-none}/tools/BUILD | 0 examples/{ => arm-none}/tools/README.md | 0 19 files changed, 11 insertions(+), 11 deletions(-) rename examples/{simple-linux => arm-linux/simple}/BUILD (100%) rename examples/{simple-linux => arm-linux/simple}/includes/library.h (100%) rename examples/{simple-linux => arm-linux/simple}/source/library.cpp (100%) rename examples/{simple-linux => arm-linux/simple}/source/main.cpp (100%) rename examples/{ => arm-none}/custom/BUILD (77%) rename examples/{ => arm-none}/custom/README.md (100%) rename examples/{ => arm-none}/custom/cpu/BUILD (100%) rename examples/{ => arm-none}/custom/main.c (100%) rename examples/{ => arm-none}/custom/platform/BUILD (73%) rename examples/{ => arm-none}/custom/toolchain/BUILD (90%) rename examples/{ => arm-none}/simple/BUILD (100%) rename examples/{ => arm-none}/simple/includes/library.h (100%) rename examples/{ => arm-none}/simple/source/library.cpp (100%) rename examples/{ => arm-none}/simple/source/main.cpp (100%) rename examples/{ => arm-none}/tools/BUILD (100%) rename examples/{ => arm-none}/tools/README.md (100%) diff --git a/.github/workflows/mac.yml b/.github/workflows/mac.yml index b0e7a7a..35465dd 100644 --- a/.github/workflows/mac.yml +++ b/.github/workflows/mac.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v2 - name: Build examples run: | - bazelisk build //examples/... + bazelisk build //examples/arm-none/... - name: Bazel backwards compatibility run: | - USE_BAZEL_VERSION=6.4.0 bazelisk build //examples/... + USE_BAZEL_VERSION=6.4.0 bazelisk build //examples/arm-none/... diff --git a/MODULE.bazel b/MODULE.bazel index aa72dae..6f1bd1a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -41,6 +41,6 @@ register_toolchains( ) register_toolchains( - "@arm_gnu_toolchain//examples/custom/toolchain:all", + "@arm_gnu_toolchain//examples/arm-none/custom/toolchain:all", dev_dependency = True, ) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 02c51df..fd93b61 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 3, - "moduleFileHash": "cc7772f488e471a657eb70ac10d6e02215a54e58fa654a90b9fdfbf5e0cfb2e3", + "moduleFileHash": "7a22bcb260999b65ca598fd8196b09500aeb275609a9832ba19cf6385b9fd48a", "flags": { "cmdRegistries": [ "https://bcr.bazel.build/" @@ -25,7 +25,7 @@ "toolchainsToRegister": [ "@arm_none_eabi//toolchain:all", "@arm_none_linux_gnueabihf//toolchain:all", - "@arm_gnu_toolchain//examples/custom/toolchain:all" + "@arm_gnu_toolchain//examples/arm-none/custom/toolchain:all" ], "extensionUsages": [ { diff --git a/examples/simple-linux/BUILD b/examples/arm-linux/simple/BUILD similarity index 100% rename from examples/simple-linux/BUILD rename to examples/arm-linux/simple/BUILD diff --git a/examples/simple-linux/includes/library.h b/examples/arm-linux/simple/includes/library.h similarity index 100% rename from examples/simple-linux/includes/library.h rename to examples/arm-linux/simple/includes/library.h diff --git a/examples/simple-linux/source/library.cpp b/examples/arm-linux/simple/source/library.cpp similarity index 100% rename from examples/simple-linux/source/library.cpp rename to examples/arm-linux/simple/source/library.cpp diff --git a/examples/simple-linux/source/main.cpp b/examples/arm-linux/simple/source/main.cpp similarity index 100% rename from examples/simple-linux/source/main.cpp rename to examples/arm-linux/simple/source/main.cpp diff --git a/examples/custom/BUILD b/examples/arm-none/custom/BUILD similarity index 77% rename from examples/custom/BUILD rename to examples/arm-none/custom/BUILD index ed7ee0f..c1a0dc9 100644 --- a/examples/custom/BUILD +++ b/examples/arm-none/custom/BUILD @@ -17,11 +17,11 @@ cc_binary( platform_transition_filegroup( name = "cortex_m3_elf", srcs = [":binary"], - target_platform = "//examples/custom/platform:cortex_m3", + target_platform = "//examples/arm-none/custom/platform:cortex_m3", ) platform_transition_filegroup( name = "cortex_m4_elf", srcs = [":binary"], - target_platform = "//examples/custom/platform:cortex_m4", + target_platform = "//examples/arm-none/custom/platform:cortex_m4", ) diff --git a/examples/custom/README.md b/examples/arm-none/custom/README.md similarity index 100% rename from examples/custom/README.md rename to examples/arm-none/custom/README.md diff --git a/examples/custom/cpu/BUILD b/examples/arm-none/custom/cpu/BUILD similarity index 100% rename from examples/custom/cpu/BUILD rename to examples/arm-none/custom/cpu/BUILD diff --git a/examples/custom/main.c b/examples/arm-none/custom/main.c similarity index 100% rename from examples/custom/main.c rename to examples/arm-none/custom/main.c diff --git a/examples/custom/platform/BUILD b/examples/arm-none/custom/platform/BUILD similarity index 73% rename from examples/custom/platform/BUILD rename to examples/arm-none/custom/platform/BUILD index 14f58bc..7bfe91a 100644 --- a/examples/custom/platform/BUILD +++ b/examples/arm-none/custom/platform/BUILD @@ -2,7 +2,7 @@ platform( name = "cortex_m4", constraint_values = [ "@platforms//os:none", - "//examples/custom/cpu:cortex_m4", + "//examples/arm-none/custom/cpu:cortex_m4", ], visibility = ["//visibility:public"], ) @@ -11,7 +11,7 @@ platform( name = "cortex_m3", constraint_values = [ "@platforms//os:none", - "//examples/custom/cpu:cortex_m3", + "//examples/arm-none/custom/cpu:cortex_m3", ], visibility = ["//visibility:public"], ) diff --git a/examples/custom/toolchain/BUILD b/examples/arm-none/custom/toolchain/BUILD similarity index 90% rename from examples/custom/toolchain/BUILD rename to examples/arm-none/custom/toolchain/BUILD index a4b41d8..b8ad0f0 100644 --- a/examples/custom/toolchain/BUILD +++ b/examples/arm-none/custom/toolchain/BUILD @@ -18,7 +18,7 @@ arm_none_eabi_toolchain( ], target_compatible_with = [ "@platforms//os:none", - "//examples/custom/cpu:cortex_m3", + "//examples/arm-none/custom/cpu:cortex_m3", ], ) @@ -41,6 +41,6 @@ arm_none_eabi_toolchain( ], target_compatible_with = [ "@platforms//os:none", - "//examples/custom/cpu:cortex_m4", + "//examples/arm-none/custom/cpu:cortex_m4", ], ) diff --git a/examples/simple/BUILD b/examples/arm-none/simple/BUILD similarity index 100% rename from examples/simple/BUILD rename to examples/arm-none/simple/BUILD diff --git a/examples/simple/includes/library.h b/examples/arm-none/simple/includes/library.h similarity index 100% rename from examples/simple/includes/library.h rename to examples/arm-none/simple/includes/library.h diff --git a/examples/simple/source/library.cpp b/examples/arm-none/simple/source/library.cpp similarity index 100% rename from examples/simple/source/library.cpp rename to examples/arm-none/simple/source/library.cpp diff --git a/examples/simple/source/main.cpp b/examples/arm-none/simple/source/main.cpp similarity index 100% rename from examples/simple/source/main.cpp rename to examples/arm-none/simple/source/main.cpp diff --git a/examples/tools/BUILD b/examples/arm-none/tools/BUILD similarity index 100% rename from examples/tools/BUILD rename to examples/arm-none/tools/BUILD diff --git a/examples/tools/README.md b/examples/arm-none/tools/README.md similarity index 100% rename from examples/tools/README.md rename to examples/arm-none/tools/README.md From a758855472f58c899ac6d3f1bbef401e80880ace Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sat, 16 Mar 2024 14:36:10 -0500 Subject: [PATCH 17/23] Fix linux toolchain for mingw-i686 --- deps.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/deps.bzl b/deps.bzl index eae8e5f..819899a 100644 --- a/deps.bzl +++ b/deps.bzl @@ -81,6 +81,7 @@ GCC_ARM_NONE_LINUX_GNUEABIHF = { { "name": "arm_none_linux_gnueabihf_windows_x86_64", "sha256": "047e72bcef8f7767691f36929a8c74ef66f717cf6264a31f48dd31bfb067f4c8", + "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": ["@arm_gnu_toolchain//toolchain:patches/0001-Resolve-libc-relative-to-sysroot.patch"], "bin_extension": ".exe", From c9d353ce650972f7f66de4c0c63be4d269dd22bd Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sun, 17 Mar 2024 15:14:27 -0500 Subject: [PATCH 18/23] CI: use --output_user_root to avoid max path length limitation Previously, CI builds were failing for Windows because the arm-linux toolchain include paths exceeded the Maximum Path Length. Use --output_user_root in the workflow to avoid this limitation. --- .github/workflows/windows.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index af88f9a..a69261f 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -15,8 +15,8 @@ jobs: - uses: actions/checkout@v2 - name: Build examples run: | - bazelisk build //examples/... + bazelisk --output_user_root=C:/bzl build //examples/... - name: Bazel backwards compatibility run: | $Env:USE_BAZEL_VERSION = "6.4.0" - bazelisk build //examples/... + bazelisk --output_user_root=C:/bzl build //examples/... From dcfe27f20a4dff8978d233d268e48f682b9dd92a Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sun, 17 Mar 2024 17:41:55 -0500 Subject: [PATCH 19/23] Use rules_cc for many definitions previously provided by bazel_tools This commit gets us almost all the way to using rules_cc instead of bazel_tools for forward compatibility after the starlarkification of the C++ rules is complete. The only import that can't currently be changes is ACTION_NAMES, because ACTION_NAMES.llvm_cov is not defined in rules_cc as of today. --- MODULE.bazel | 1 + MODULE.bazel.lock | 122 ++++++++++++++++++++++------------------ toolchain/config.bzl | 2 +- toolchain/toolchain.bzl | 3 +- 4 files changed, 71 insertions(+), 57 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 6f1bd1a..f4e0f4a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -5,6 +5,7 @@ module( ) bazel_dep(name = "platforms", version = "0.0.8") +bazel_dep(name = "rules_cc", version = "0.0.9") arm_toolchain = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_toolchain") # NOTE: It's important that we update these versions whenever a new toolchain diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index fd93b61..0d5848d 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 3, - "moduleFileHash": "7a22bcb260999b65ca598fd8196b09500aeb275609a9832ba19cf6385b9fd48a", + "moduleFileHash": "c7170efca44f6b8567f05e4e870c613665b4c9c1d64094b4c2d5a88f835c14f4", "flags": { "cmdRegistries": [ "https://bcr.bazel.build/" @@ -34,7 +34,7 @@ "usingModule": "", "location": { "file": "@@//:MODULE.bazel", - "line": 9, + "line": 10, "column": 30 }, "imports": { @@ -58,7 +58,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 14, + "line": 15, "column": 28 } }, @@ -70,7 +70,7 @@ "devDependency": false, "location": { "file": "@@//:MODULE.bazel", - "line": 24, + "line": 25, "column": 39 } } @@ -81,6 +81,7 @@ ], "deps": { "platforms": "platforms@0.0.8", + "rules_cc": "rules_cc@0.0.9", "aspect_bazel_lib": "aspect_bazel_lib@2.0.0", "bazel_skylib": "bazel_skylib@1.5.0", "bazel_tools": "bazel_tools@_", @@ -115,6 +116,56 @@ } } }, + "rules_cc@0.0.9": { + "name": "rules_cc", + "version": "0.0.9", + "key": "rules_cc@0.0.9", + "repoName": "rules_cc", + "executionPlatformsToRegister": [], + "toolchainsToRegister": [ + "@local_config_cc_toolchains//:all" + ], + "extensionUsages": [ + { + "extensionBzlFile": "@bazel_tools//tools/cpp:cc_configure.bzl", + "extensionName": "cc_configure_extension", + "usingModule": "rules_cc@0.0.9", + "location": { + "file": "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel", + "line": 9, + "column": 29 + }, + "imports": { + "local_config_cc_toolchains": "local_config_cc_toolchains" + }, + "devImports": [], + "tags": [], + "hasDevUseExtension": false, + "hasNonDevUseExtension": true + } + ], + "deps": { + "platforms": "platforms@0.0.8", + "bazel_tools": "bazel_tools@_", + "local_config_platform": "local_config_platform@_" + }, + "repoSpec": { + "bzlFile": "@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_archive", + "attributes": { + "name": "rules_cc~0.0.9", + "urls": [ + "https://github.com/bazelbuild/rules_cc/releases/download/0.0.9/rules_cc-0.0.9.tar.gz" + ], + "integrity": "sha256-IDeHW5pEVtzkp50RKorohbvEqtlo5lh9ym5k86CQDN8=", + "strip_prefix": "rules_cc-0.0.9", + "remote_patches": { + "https://bcr.bazel.build/modules/rules_cc/0.0.9/patches/module_dot_bazel_version.patch": "sha256-mM+qzOI0SgAdaJBlWOSMwMPKpaA9b7R37Hj/tp5bb4g=" + }, + "remote_patch_strip": 0 + } + } + }, "aspect_bazel_lib@2.0.0": { "name": "aspect_bazel_lib", "version": "2.0.0", @@ -489,56 +540,6 @@ } } }, - "rules_cc@0.0.9": { - "name": "rules_cc", - "version": "0.0.9", - "key": "rules_cc@0.0.9", - "repoName": "rules_cc", - "executionPlatformsToRegister": [], - "toolchainsToRegister": [ - "@local_config_cc_toolchains//:all" - ], - "extensionUsages": [ - { - "extensionBzlFile": "@bazel_tools//tools/cpp:cc_configure.bzl", - "extensionName": "cc_configure_extension", - "usingModule": "rules_cc@0.0.9", - "location": { - "file": "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel", - "line": 9, - "column": 29 - }, - "imports": { - "local_config_cc_toolchains": "local_config_cc_toolchains" - }, - "devImports": [], - "tags": [], - "hasDevUseExtension": false, - "hasNonDevUseExtension": true - } - ], - "deps": { - "platforms": "platforms@0.0.8", - "bazel_tools": "bazel_tools@_", - "local_config_platform": "local_config_platform@_" - }, - "repoSpec": { - "bzlFile": "@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_archive", - "attributes": { - "name": "rules_cc~0.0.9", - "urls": [ - "https://github.com/bazelbuild/rules_cc/releases/download/0.0.9/rules_cc-0.0.9.tar.gz" - ], - "integrity": "sha256-IDeHW5pEVtzkp50RKorohbvEqtlo5lh9ym5k86CQDN8=", - "strip_prefix": "rules_cc-0.0.9", - "remote_patches": { - "https://bcr.bazel.build/modules/rules_cc/0.0.9/patches/module_dot_bazel_version.patch": "sha256-mM+qzOI0SgAdaJBlWOSMwMPKpaA9b7R37Hj/tp5bb4g=" - }, - "remote_patch_strip": 0 - } - } - }, "rules_java@7.1.0": { "name": "rules_java", "version": "7.1.0", @@ -850,7 +851,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_toolchain": { "general": { - "bzlTransitiveDigest": "ZBjbAO9SvG43wcxInVi5XfotuubwnPLpdvYQlpOQYzQ=", + "bzlTransitiveDigest": "kgWYePlN0l+GqeEjj7ux00Mkx2C+UHF3ueOLFwG/Myg=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { @@ -905,6 +906,7 @@ "version": "13.2.1", "name": "_main~arm_toolchain~arm_none_linux_gnueabihf_windows_x86_64", "sha256": "047e72bcef8f7767691f36929a8c74ef66f717cf6264a31f48dd31bfb067f4c8", + "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": [ "@@//toolchain:patches/0001-Resolve-libc-relative-to-sysroot.patch" @@ -979,6 +981,16 @@ "", "bazel_tools", "bazel_tools" + ], + [ + "", + "rules_cc", + "rules_cc~0.0.9" + ], + [ + "rules_cc~0.0.9", + "bazel_tools", + "bazel_tools" ] ] } diff --git a/toolchain/config.bzl b/toolchain/config.bzl index 563af05..22bc583 100644 --- a/toolchain/config.bzl +++ b/toolchain/config.bzl @@ -1,5 +1,5 @@ load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "action_config", "feature", "flag_group", "flag_set") +load("@rules_cc//cc:cc_toolchain_config_lib.bzl", "action_config", "feature", "flag_group", "flag_set") def _tool_path(bins, toolchain_prefix, tool_name): for file in bins: diff --git a/toolchain/toolchain.bzl b/toolchain/toolchain.bzl index f08eb33..da833b6 100644 --- a/toolchain/toolchain.bzl +++ b/toolchain/toolchain.bzl @@ -3,6 +3,7 @@ This module provides functions to register an arm-none-eabi toolchain """ load("@arm_gnu_toolchain//toolchain:config.bzl", "cc_arm_gnu_toolchain_config") +load("@rules_cc//cc:defs.bzl", "cc_toolchain") tools = [ "as", @@ -79,7 +80,7 @@ def _arm_gnu_toolchain(name, toolchain = "", toolchain_prefix = "", include_std = include_std, ) - native.cc_toolchain( + cc_toolchain( name = "cc_toolchain_{}_{}".format(host, name), all_files = "@{}_{}//:compiler_pieces".format(toolchain, host), ar_files = "@{}_{}//:ar_files".format(toolchain, host), From 6acba694d0f196d505629685631f7fad9fb7ad7b Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sun, 17 Mar 2024 17:48:21 -0500 Subject: [PATCH 20/23] Document Windows path length issues in README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 01a7e6b..be5054e 100644 --- a/README.md +++ b/README.md @@ -182,3 +182,16 @@ genrule( ## Remote execution This toolchain is compatible with remote execution, see [`remote.yml`](.github/workflows/remote.yml) +## Building with the ARM Linux toolchain on Windows + +The Windows maximum path length limitation may cause build failures with the +`arm-none-linux-gnueabihf` toolchain. In some cases, it's enough to avoid this +by setting a shorter output directory. Add this to your `.bazelrc` file: + +``` +startup --output_user_root=C:/tmp +``` + +See [avoid long path issues][1] for more information. + +[1]: https://bazel.build/configure/windows#long-path-issues From ffe8ec3b64e9946154367992d941d891979feec3 Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sun, 17 Mar 2024 18:04:13 -0500 Subject: [PATCH 21/23] examples/arm-linux: Link to libc and libstdc++ by default --- examples/arm-linux/simple/includes/library.h | 3 ++- examples/arm-linux/simple/source/library.cpp | 11 +++-------- examples/arm-linux/simple/source/main.cpp | 11 +++++++---- toolchain/toolchain.bzl | 6 ++++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/examples/arm-linux/simple/includes/library.h b/examples/arm-linux/simple/includes/library.h index 8d8469b..298320e 100644 --- a/examples/arm-linux/simple/includes/library.h +++ b/examples/arm-linux/simple/includes/library.h @@ -1,4 +1,5 @@ #include uint16_t baz(uint8_t var); -uint32_t foo(void); \ No newline at end of file +uint32_t foo(void); +uint16_t foobaz(); diff --git a/examples/arm-linux/simple/source/library.cpp b/examples/arm-linux/simple/source/library.cpp index eef1ad8..0f153b3 100644 --- a/examples/arm-linux/simple/source/library.cpp +++ b/examples/arm-linux/simple/source/library.cpp @@ -1,19 +1,14 @@ #include "library.h" #include -uint16_t baz(int a) -{ - return a * 2; -} +uint16_t baz(uint8_t a) { return a * 2; } -uint32_t foo() -{ +uint32_t foo() { static constexpr int k = 5; return baz(k); } -uint16_t foobaz() -{ +uint16_t foobaz() { std::vector vec(10); vec.push_back(1); return vec[0]; diff --git a/examples/arm-linux/simple/source/main.cpp b/examples/arm-linux/simple/source/main.cpp index b61259d..6638d58 100644 --- a/examples/arm-linux/simple/source/main.cpp +++ b/examples/arm-linux/simple/source/main.cpp @@ -1,5 +1,8 @@ -// The simplest possible main function +#include +#include -int main(){ - return 0; -} \ No newline at end of file +int main() { + std::cout << "baz(4) -> " << baz(4) << "\n"; + std::cout << "foo=" << foo() << "\n"; + std::cout << "foobaz=" << foobaz() << "\n"; +} diff --git a/toolchain/toolchain.bzl b/toolchain/toolchain.bzl index da833b6..07402b9 100644 --- a/toolchain/toolchain.bzl +++ b/toolchain/toolchain.bzl @@ -120,7 +120,8 @@ def arm_none_eabi_toolchain(name, version = "9.2.1", copts = [], **kwargs): abi_version = "eabi", copts = ["-nostdinc"] + copts, **kwargs) -def arm_none_linux_gnueabihf_toolchain(name, version = "13.2.1", **kwargs): +def arm_none_linux_gnueabihf_toolchain(name, version = "13.2.1", linkopts = [], + **kwargs): """ Create an arm-none-linux-gnueabihf toolchain with the given configuration. @@ -134,7 +135,8 @@ def arm_none_linux_gnueabihf_toolchain(name, version = "13.2.1", **kwargs): """ _arm_gnu_toolchain(name, toolchain = "arm_none_linux_gnueabihf", toolchain_prefix = "arm-none-linux-gnueabihf", - version = version, abi_version = "gnueabihf", **kwargs) + version = version, abi_version = "gnueabihf", + linkopts = ["-lc", "-lstdc++"] + linkopts, **kwargs) def register_arm_gnu_toolchain(name): for host in hosts: From 6876b0e427f46926cad9b0aadc5e16d8e48f7248 Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Sun, 17 Mar 2024 18:10:10 -0500 Subject: [PATCH 22/23] non-functional: Bump arm-none-eabi version to 13.2.1 in a few places This affects default arguments and the README, but should not have any effect on consumers using older toolchains. --- MODULE.bazel.lock | 2 +- README.md | 2 +- deps.bzl | 2 +- toolchain/toolchain.bzl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 0d5848d..a56cdee 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -851,7 +851,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_toolchain": { "general": { - "bzlTransitiveDigest": "kgWYePlN0l+GqeEjj7ux00Mkx2C+UHF3ueOLFwG/Myg=", + "bzlTransitiveDigest": "iBxmVprJjktYWza5eW9kuDYRqIPD9iWPLtWUVBP2xns=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { diff --git a/README.md b/README.md index be5054e..2f9e570 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ git_override( bazel_dep(name = "arm_none_eabi", version = "1.0.0") arm_toolchain = use_extension("@arm_gnu_toolchain//:extensions.bzl", "arm_toolchain") -arm_toolchain.arm_none_eabi(version = "9.2.1") +arm_toolchain.arm_none_eabi(version = "13.2.1") use_repo( arm_toolchain, "arm_none_eabi", diff --git a/deps.bzl b/deps.bzl index 819899a..37a5411 100644 --- a/deps.bzl +++ b/deps.bzl @@ -173,7 +173,7 @@ def register_default_arm_gnu_toolchains(toolchain_prefix): # arm-none-eabi -def arm_none_eabi_deps(version = "9.2.1", archives = GCC_ARM_NONE_EABI): +def arm_none_eabi_deps(version = "13.2.1", archives = GCC_ARM_NONE_EABI): """Workspace dependencies for the arm none eabi gcc toolchain Args: diff --git a/toolchain/toolchain.bzl b/toolchain/toolchain.bzl index 07402b9..f1e898c 100644 --- a/toolchain/toolchain.bzl +++ b/toolchain/toolchain.bzl @@ -102,7 +102,7 @@ def _arm_gnu_toolchain(name, toolchain = "", toolchain_prefix = "", toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", ) -def arm_none_eabi_toolchain(name, version = "9.2.1", copts = [], **kwargs): +def arm_none_eabi_toolchain(name, version = "13.2.1", copts = [], **kwargs): """ Create an arm-none-eabi toolchain with the given configuration. From 13b0b9070e0cf393e38daa38395552888a1400f6 Mon Sep 17 00:00:00 2001 From: "Ethan D. Twardy" Date: Mon, 25 Mar 2024 06:51:47 -0500 Subject: [PATCH 23/23] arm-linux: Default include_std to true --- MODULE.bazel.lock | 2 +- toolchain/toolchain.bzl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index a56cdee..2616311 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -851,7 +851,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_toolchain": { "general": { - "bzlTransitiveDigest": "iBxmVprJjktYWza5eW9kuDYRqIPD9iWPLtWUVBP2xns=", + "bzlTransitiveDigest": "klsTYDJI5Guz2L2xgvg3B2+skQyF7NHTyVM/D104jm4=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { diff --git a/toolchain/toolchain.bzl b/toolchain/toolchain.bzl index f1e898c..a4fce8e 100644 --- a/toolchain/toolchain.bzl +++ b/toolchain/toolchain.bzl @@ -136,7 +136,8 @@ def arm_none_linux_gnueabihf_toolchain(name, version = "13.2.1", linkopts = [], _arm_gnu_toolchain(name, toolchain = "arm_none_linux_gnueabihf", toolchain_prefix = "arm-none-linux-gnueabihf", version = version, abi_version = "gnueabihf", - linkopts = ["-lc", "-lstdc++"] + linkopts, **kwargs) + linkopts = ["-lc", "-lstdc++"] + linkopts, + include_std = True, **kwargs) def register_arm_gnu_toolchain(name): for host in hosts: