From cd56894517a42f428eafcbdac41d3ee9bdb78204 Mon Sep 17 00:00:00 2001 From: Davide Asnaghi <30296575+hexdae@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:57:29 -0400 Subject: [PATCH] [BAZEL] make tools native binaries (#51) --- MODULE.bazel | 2 +- MODULE.bazel.lock | 66 +++++++++++++++++------------------ test/arm-none-eabi/BUILD | 19 +++++++--- toolchain/templates/top.BUILD | 14 ++++---- 4 files changed, 56 insertions(+), 45 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index fd1da6f..8b1c8f5 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -8,10 +8,10 @@ module( bazel_dep(name = "platforms", version = "0.0.8") bazel_dep(name = "rules_cc", version = "0.0.9") +bazel_dep(name = "bazel_skylib", version = "1.5.0") # 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) arm_toolchain = use_extension( "@toolchains_arm_gnu//:extensions.bzl", diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 43e1d25..6160c3c 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1,6 +1,6 @@ { "lockFileVersion": 3, - "moduleFileHash": "50804b6b325150c2e40e5294c534f39d2b773ffd9f789de82e7fdfd6fd60e184", + "moduleFileHash": "564041bd874693c97cb6c380a0cd1bf57be4dfbc752a5dfce9869535e010cd90", "flags": { "cmdRegistries": [ "https://bcr.bazel.build/" @@ -100,8 +100,8 @@ "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", + "aspect_bazel_lib": "aspect_bazel_lib@2.0.0", "bazel_tools": "bazel_tools@_", "local_config_platform": "local_config_platform@_" } @@ -184,6 +184,37 @@ } } }, + "bazel_skylib@1.5.0": { + "name": "bazel_skylib", + "version": "1.5.0", + "key": "bazel_skylib@1.5.0", + "repoName": "bazel_skylib", + "executionPlatformsToRegister": [], + "toolchainsToRegister": [ + "//toolchains/unittest:cmd_toolchain", + "//toolchains/unittest:bash_toolchain" + ], + "extensionUsages": [], + "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": "bazel_skylib~1.5.0", + "urls": [ + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz" + ], + "integrity": "sha256-zVWgYudjuTSZIfD124w5MyiNyLpPdt2UFqrGis7jy5Q=", + "strip_prefix": "", + "remote_patches": {}, + "remote_patch_strip": 0 + } + } + }, "aspect_bazel_lib@2.0.0": { "name": "aspect_bazel_lib", "version": "2.0.0", @@ -323,37 +354,6 @@ } } }, - "bazel_skylib@1.5.0": { - "name": "bazel_skylib", - "version": "1.5.0", - "key": "bazel_skylib@1.5.0", - "repoName": "bazel_skylib", - "executionPlatformsToRegister": [], - "toolchainsToRegister": [ - "//toolchains/unittest:cmd_toolchain", - "//toolchains/unittest:bash_toolchain" - ], - "extensionUsages": [], - "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": "bazel_skylib~1.5.0", - "urls": [ - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz" - ], - "integrity": "sha256-zVWgYudjuTSZIfD124w5MyiNyLpPdt2UFqrGis7jy5Q=", - "strip_prefix": "", - "remote_patches": {}, - "remote_patch_strip": 0 - } - } - }, "bazel_tools@_": { "name": "bazel_tools", "version": "", diff --git a/test/arm-none-eabi/BUILD b/test/arm-none-eabi/BUILD index 31dc01a..9f916a9 100644 --- a/test/arm-none-eabi/BUILD +++ b/test/arm-none-eabi/BUILD @@ -27,7 +27,7 @@ cc_library( ) cc_binary( - name = "arm_elf", + name = "app", srcs = ["main.cpp"], copts = [ "-mcpu=cortex-a5", @@ -41,15 +41,24 @@ cc_binary( ) platform_transition_filegroup( - name = "elf", - srcs = [":arm_elf"], + name = "arm_none_eabi_app", + srcs = [":app"], target_platform = ":arm_none_eabi", ) +genrule( + name = "elf", + srcs = [":arm_none_eabi_app"], + outs = ["app.elf"], + cmd = "cp $< $@", + executable = True, + visibility = ["//visibility:public"], +) + genrule( name = "hex", - srcs = [":elf"], - outs = ["mock.hex"], + srcs = [":arm_none_eabi_app"], + outs = ["app.hex"], cmd = "$(execpath @arm_none_eabi//:objcopy) -O ihex $< $@", tools = ["@arm_none_eabi//:objcopy"], visibility = ["//visibility:public"], diff --git a/toolchain/templates/top.BUILD b/toolchain/templates/top.BUILD index 648fe46..4141165 100644 --- a/toolchain/templates/top.BUILD +++ b/toolchain/templates/top.BUILD @@ -5,6 +5,7 @@ repository, i.e., the targets defined here appear in the workspace as """ load("@toolchains_arm_gnu//toolchain:toolchain.bzl", "hosts", "tools") +load("@bazel_skylib//rules:native_binary.bzl", "native_binary") package(default_visibility = ["//visibility:public"]) @@ -15,19 +16,20 @@ TOOLS = tools + ["bin"] name = host, constraint_values = constraint_values, ) - for host, constraint_values in hosts['%toolchain_prefix%'].items() + for host, constraint_values in hosts["%toolchain_prefix%"].items() ] [ - filegroup( + native_binary( name = tool, - srcs = select({ - host: ["@%toolchain_name%_{}//:{}".format(host, tool)] - for host in hosts['%toolchain_prefix%'].keys() + src = select({ + host: "@%toolchain_name%_{}//:{}".format(host, tool) + for host in hosts["%toolchain_prefix%"].keys() }), + out = tool, target_compatible_with = select({ host: constraint_values - for host, constraint_values in hosts['%toolchain_prefix%'].items() + for host, constraint_values in hosts["%toolchain_prefix%"].items() } | { "//conditions:default": ["@platforms//:incompatible"], }),