diff --git a/BUILD b/BUILD index 5484a31..c32ddfc 100644 --- a/BUILD +++ b/BUILD @@ -1,23 +1,10 @@ # BUILD -load("//toolchain:toolchain.bzl", "hosts") +load("//toolchain:toolchain.bzl", "hosts", "tools") package(default_visibility = ["//visibility:public"]) -TOOLS = [ - "bin", - "gcc", - "ar", - "ld", - "nm", - "readelf", - "objcopy", - "objdump", - "strip", - "size", - "gdb", - "as", -] +TOOLS = tools + ["bin"] [ config_setting( diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 736217c..440c8d0 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -832,7 +832,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_none_eabi": { "general": { - "bzlTransitiveDigest": "w6FoxDH5UMqUd/+Aj661LOkG5eu1KFX2uSnJSNy3qvE=", + "bzlTransitiveDigest": "TBXaznRVLACieywI746foE9heDPOJCL7pDKibX+RJEc=", "accumulatedFileDigests": {}, "envVariables": {}, "generatedRepoSpecs": { diff --git a/deps.bzl b/deps.bzl index 8995513..c72155b 100644 --- a/deps.bzl +++ b/deps.bzl @@ -33,6 +33,35 @@ GCC = { "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", }, ], + "13.2.1": [ + { + "name": "arm_none_eabi_darwin_x86_64", + "sha256": "075faa4f3e8eb45e59144858202351a28706f54a6ec17eedd88c9fb9412372cc", + "build_file": "@arm_none_eabi//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", + "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", + "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", + "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_none_eabi_deps(version = "9.2.1", archives = GCC): diff --git a/examples/custom/platform/BUILD b/examples/custom/platform/BUILD index 4748ed2..14f58bc 100644 --- a/examples/custom/platform/BUILD +++ b/examples/custom/platform/BUILD @@ -1,9 +1,8 @@ - platform( name = "cortex_m4", constraint_values = [ "@platforms//os:none", - "//examples/custom/cpu:cortex_m4" + "//examples/custom/cpu:cortex_m4", ], visibility = ["//visibility:public"], ) @@ -12,7 +11,7 @@ platform( name = "cortex_m3", constraint_values = [ "@platforms//os:none", - "//examples/custom/cpu:cortex_m3" + "//examples/custom/cpu:cortex_m3", ], visibility = ["//visibility:public"], ) diff --git a/examples/custom/toolchain/BUILD b/examples/custom/toolchain/BUILD index 6a13912..a51c3a1 100644 --- a/examples/custom/toolchain/BUILD +++ b/examples/custom/toolchain/BUILD @@ -1,11 +1,8 @@ load("@arm_none_eabi//toolchain:toolchain.bzl", "arm_none_eabi_toolchain") +# Cortex-M3 toolchain arm_none_eabi_toolchain( name = "cortex_m3_toolchain", - target_compatible_with = [ - "@platforms//os:none", - "//examples/custom/cpu:cortex_m3" - ], copts = [ "-mcpu=cortex-m3", "-mthumb", @@ -19,20 +16,22 @@ arm_none_eabi_toolchain( "-mfpu=fpv4-sp-d16", "-nostartfiles", ], + target_compatible_with = [ + "@platforms//os:none", + "//examples/custom/cpu:cortex_m3", + ], ) +# Cortex-M4 toolchain, compiled using g++ instead of gcc arm_none_eabi_toolchain( name = "cortex_m4_toolchain", - target_compatible_with = [ - "@platforms//os:none", - "//examples/custom/cpu:cortex_m4" - ], copts = [ "-mcpu=cortex-m4", "-mthumb", "-mfloat-abi=hard", "-mfpu=fpv4-sp-d16", ], + gcc_tool = "g++", linkopts = [ "-mcpu=cortex-m4", "-mthumb", @@ -40,4 +39,8 @@ arm_none_eabi_toolchain( "-mfpu=fpv4-sp-d16", "-nostartfiles", ], + target_compatible_with = [ + "@platforms//os:none", + "//examples/custom/cpu:cortex_m4", + ], ) diff --git a/toolchain/compiler/nix.BUILD b/toolchain/compiler/nix.BUILD index a8c27fb..092ae1b 100644 --- a/toolchain/compiler/nix.BUILD +++ b/toolchain/compiler/nix.BUILD @@ -1,92 +1,24 @@ -# toolchains/compiler.BUILD +load("@arm_none_eabi//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)) -# gcc executables. -filegroup( - name = "gcc", - srcs = ["bin/arm-none-eabi-gcc"], -) - -# cpp executables. -filegroup( - name = "cpp", - srcs = ["bin/arm-none-eabi-cpp"], -) - -# gcov executables. -filegroup( - name = "gcov", - srcs = ["bin/arm-none-eabi-gcov"], -) - -# gdb executables. -filegroup( - name = "gdb", - srcs = ["bin/arm-none-eabi-gdb"], -) - -# ar executables. -filegroup( - name = "ar", - srcs = ["bin/arm-none-eabi-ar"], -) - -# ld executables. -filegroup( - name = "ld", - srcs = ["bin/arm-none-eabi-ld"], -) - -# nm executables. -filegroup( - name = "nm", - srcs = ["bin/arm-none-eabi-nm"], -) - -# objcopy executables. -filegroup( - name = "objcopy", - srcs = ["bin/arm-none-eabi-objcopy"], -) - -# objdump executables. -filegroup( - name = "objdump", - srcs = ["bin/arm-none-eabi-objdump"], -) - -# strip executables. -filegroup( - name = "strip", - srcs = ["bin/arm-none-eabi-strip"], -) - -# as executables. -filegroup( - name = "as", - srcs = ["bin/arm-none-eabi-as"], -) - -# readelf executables. -filegroup( - name = "readelf", - srcs = ["bin/arm-none-eabi-readelf"], -) - -# size executables. -filegroup( - name = "size", - srcs = ["bin/arm-none-eabi-size"], -) +# executables. +[ + filegroup( + name = tool, + srcs = ["bin/arm-none-eabi-{}".format(tool)], + ) + for tool in tools +] # libraries and headers. filegroup( name = "compiler_pieces", srcs = glob([ + "bin/**", "libexec/**", "arm-none-eabi/**", "lib/**", @@ -94,49 +26,24 @@ filegroup( ]), ) +# files for executing compiler. filegroup( - name = "ar_files", - srcs = [ - ":ar", - ":compiler_pieces", - ":gcc", - ], + name = "compiler_files", + srcs = [":compiler_pieces"], ) -# files for executing compiler. filegroup( - name = "compiler_files", - srcs = [ - ":compiler_pieces", - ":cpp", - ":gcc", - ], + name = "ar_files", + srcs = [":compiler_pieces"], ) filegroup( name = "linker_files", - srcs = [ - ":ar", - ":compiler_pieces", - ":gcc", - ":ld", - ], + srcs = [":compiler_pieces"], ) # collection of executables. filegroup( name = "compiler_components", - srcs = [ - ":ar", - ":as", - ":compiler_pieces", - ":cpp", - ":gcc", - ":gcov", - ":ld", - ":nm", - ":objcopy", - ":objdump", - ":strip", - ], + srcs = [":compiler_pieces"], ) diff --git a/toolchain/compiler/win.BUILD b/toolchain/compiler/win.BUILD index 7961378..a958d65 100644 --- a/toolchain/compiler/win.BUILD +++ b/toolchain/compiler/win.BUILD @@ -1,92 +1,24 @@ -# toolchains/compiler.BUILD +load("@arm_none_eabi//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)) -# gcc executables. -filegroup( - name = "gcc", - srcs = ["bin/arm-none-eabi-gcc.exe"], -) - -# cpp executables. -filegroup( - name = "cpp", - srcs = ["bin/arm-none-eabi-cpp.exe"], -) - -# gcov executables. -filegroup( - name = "gcov", - srcs = ["bin/arm-none-eabi-gcov.exe"], -) - -# gdb executables. -filegroup( - name = "gdb", - srcs = ["bin/arm-none-eabi-gdb.exe"], -) - -# ar executables. -filegroup( - name = "ar", - srcs = ["bin/arm-none-eabi-ar.exe"], -) - -# ld executables. -filegroup( - name = "ld", - srcs = ["bin/arm-none-eabi-ld.exe"], -) - -# nm executables. -filegroup( - name = "nm", - srcs = ["bin/arm-none-eabi-nm.exe"], -) - -# objcopy executables. -filegroup( - name = "objcopy", - srcs = ["bin/arm-none-eabi-objcopy.exe"], -) - -# objdump executables. -filegroup( - name = "objdump", - srcs = ["bin/arm-none-eabi-objdump.exe"], -) - -# strip executables. -filegroup( - name = "strip", - srcs = ["bin/arm-none-eabi-strip.exe"], -) - -# as executables. -filegroup( - name = "as", - srcs = ["bin/arm-none-eabi-as.exe"], -) - -# readelf executables. -filegroup( - name = "readelf", - srcs = ["bin/arm-none-eabi-readelf.exe"], -) - -# size executables. -filegroup( - name = "size", - srcs = ["bin/arm-none-eabi-size.exe"], -) +# executables. +[ + filegroup( + name = tool, + srcs = ["bin/arm-none-eabi-{}.exe".format(tool)], + ) + for tool in tools +] # libraries and headers. filegroup( name = "compiler_pieces", srcs = glob([ + "bin/**", "libexec/**", "arm-none-eabi/**", "lib/**", @@ -94,49 +26,24 @@ filegroup( ]), ) +# files for executing compiler. filegroup( - name = "ar_files", - srcs = [ - ":ar", - ":compiler_pieces", - ":gcc", - ], + name = "compiler_files", + srcs = [":compiler_pieces"], ) -# files for executing compiler. filegroup( - name = "compiler_files", - srcs = [ - ":compiler_pieces", - ":cpp", - ":gcc", - ], + name = "ar_files", + srcs = [":compiler_pieces"], ) filegroup( name = "linker_files", - srcs = [ - ":ar", - ":compiler_pieces", - ":gcc", - ":ld", - ], + srcs = [":compiler_pieces"], ) # collection of executables. filegroup( name = "compiler_components", - srcs = [ - ":ar", - ":as", - ":compiler_pieces", - ":cpp", - ":gcc", - ":gcov", - ":ld", - ":nm", - ":objcopy", - ":objdump", - ":strip", - ], + srcs = [":compiler_pieces"], ) diff --git a/toolchain/config.bzl b/toolchain/config.bzl index b11aa16..1e6eeec 100644 --- a/toolchain/config.bzl +++ b/toolchain/config.bzl @@ -42,7 +42,7 @@ def _impl(ctx): ACTION_NAMES.cpp_compile, ACTION_NAMES.cpp_header_parsing, ], - "gcc", + ctx.attr.gcc_tool, ) action_configs += _action_configs( @@ -145,6 +145,7 @@ cc_arm_none_eabi_config = rule( "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"), "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 4403b6e..ebb1cff 100644 --- a/toolchain/toolchain.bzl +++ b/toolchain/toolchain.bzl @@ -4,6 +4,23 @@ This module provides functions to register an arm-none-eabi toolchain load("@arm_none_eabi//toolchain:config.bzl", "cc_arm_none_eabi_config") +tools = [ + "as", + "ar", + "c++", + "cpp", + "g++", + "gcc", + "gdb", + "ld", + "nm", + "objcopy", + "objdump", + "readelf", + "strip", + "size", +] + compatible_cpus = { "arm": "@platforms//cpu:arm", "armv6-m": "@platforms//cpu:armv6-m", @@ -20,12 +37,13 @@ hosts = { "windows_x86_64": ["@platforms//os:windows", "@platforms//cpu:x86_64"], } -def arm_none_eabi_toolchain(name, target_compatible_with = [], copts = [], linkopts = [], version = "9.2.1"): +def arm_none_eabi_toolchain(name, gcc_tool = "gcc", target_compatible_with = [], copts = [], linkopts = [], version = "9.2.1"): """ 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. @@ -37,6 +55,7 @@ def arm_none_eabi_toolchain(name, target_compatible_with = [], copts = [], linko name = "config_{}_{}".format(host, name), gcc_repo = "arm_none_eabi_{}".format(host), gcc_version = version, + gcc_tool = gcc_tool, host_system_name = host, toolchain_identifier = "arm_none_eabi_{}_{}".format(host, name), toolchain_bins = "@arm_none_eabi_{}//:compiler_components".format(host),