Skip to content

Commit

Permalink
[BAZEL] make tools native binaries (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexdae authored Apr 23, 2024
1 parent 7c7e899 commit cd56894
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 45 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
66 changes: 33 additions & 33 deletions MODULE.bazel.lock

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

19 changes: 14 additions & 5 deletions test/arm-none-eabi/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cc_library(
)

cc_binary(
name = "arm_elf",
name = "app",
srcs = ["main.cpp"],
copts = [
"-mcpu=cortex-a5",
Expand All @@ -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"],
Expand Down
14 changes: 8 additions & 6 deletions toolchain/templates/top.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand All @@ -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"],
}),
Expand Down

0 comments on commit cd56894

Please sign in to comment.