Skip to content

Commit

Permalink
pw_build: Use plain action name variables
Browse files Browse the repository at this point in the history
rules_cc does not yet export providers that offer direct access to the
literal underlying action names. For now, use the variables to remove
the dependency on pw_toolchain_bazel things.

Bug: b/346388161, b/367352331
Change-Id: Ia3fa4a07d33dcc44da3fc9b0ae0958ff97675d5d
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/254553
Pigweed-Auto-Submit: Armando Montanez <[email protected]>
Lint: Lint 🤖 <[email protected]>
Reviewed-by: Ted Pudlik <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Docs-Not-Needed: Armando Montanez <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
  • Loading branch information
armandomontanez authored and CQ Bot Account committed Dec 16, 2024
1 parent d08f106 commit 0a0160e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
17 changes: 10 additions & 7 deletions pw_build/binary_tools.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
# the License.
"""Rules for processing binary executables."""

load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
load("@pw_toolchain//actions:providers.bzl", "ActionNameInfo")
load("//pw_toolchain/action:action_names.bzl", "PW_ACTION_NAMES")

def _run_action_on_executable(
ctx,
Expand Down Expand Up @@ -62,7 +63,9 @@ def _run_action_on_executable(
def _pw_elf_to_bin_impl(ctx):
return _run_action_on_executable(
ctx = ctx,
action_name = ctx.attr._objcopy[ActionNameInfo].name,
# TODO: https://github.com/bazelbuild/rules_cc/issues/292 - Add a helper
# to rules cc to make it possible to get this from ctx.attr._objcopy.
action_name = ACTION_NAMES.objcopy_embed_data,
action_args = "{args} {input} {output}".format(
args = "-Obinary",
input = ctx.executable.elf_input.path,
Expand All @@ -84,8 +87,7 @@ pw_elf_to_bin = rule(
"bin_out": attr.output(mandatory = True),
"elf_input": attr.label(mandatory = True, executable = True, cfg = "target"),
"_objcopy": attr.label(
default = "@pw_toolchain//actions:objcopy_embed_data",
providers = [ActionNameInfo],
default = "@rules_cc//cc/toolchains/actions:objcopy_embed_data",
),
},
executable = True,
Expand All @@ -96,7 +98,9 @@ pw_elf_to_bin = rule(
def _pw_elf_to_dump_impl(ctx):
return _run_action_on_executable(
ctx = ctx,
action_name = ctx.attr._objdump[ActionNameInfo].name,
# TODO: https://github.com/bazelbuild/rules_cc/issues/292 - Add a helper
# to rules cc to make it possible to get this from ctx.attr._objdump.
action_name = PW_ACTION_NAMES.objdump_disassemble,
action_args = "{args} {input} > {output}".format(
args = "-dx",
input = ctx.executable.elf_input.path,
Expand All @@ -116,8 +120,7 @@ pw_elf_to_dump = rule(
"dump_out": attr.output(mandatory = True),
"elf_input": attr.label(mandatory = True, executable = True, cfg = "target"),
"_objdump": attr.label(
default = "@pw_toolchain//actions:objdump_embed_data",
providers = [ActionNameInfo],
default = "//pw_toolchain/action:objdump_disassemble",
),
},
toolchains = use_cpp_toolchain(),
Expand Down
5 changes: 3 additions & 2 deletions pw_toolchain/action/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
# the License.

load("@rules_cc//cc/toolchains:actions.bzl", "cc_action_type")
load(":action_names.bzl", "PW_ACTION_NAMES")

package(default_visibility = ["//visibility:public"])

# TODO: https://pwbug.dev/367352331 - Rename and upstream this to Bazel
# (rules_cc, bazeltools).
cc_action_type(
name = "objdump",
action_name = "objdump_embed_data",
name = "objdump_disassemble",
action_name = PW_ACTION_NAMES.objdump_disassemble,
)
20 changes: 20 additions & 0 deletions pw_toolchain/action/action_names.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Custom toolchain action names unique to Pigweed."""

PW_OBJDUMP_DISASSEMBLE = "objdump-disassemble"

PW_ACTION_NAMES = struct(
objdump_disassemble = PW_OBJDUMP_DISASSEMBLE,
)
2 changes: 1 addition & 1 deletion pw_toolchain/build_external/arm_none_eabi_gcc.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cc_tool_map(
"@rules_cc//cc/toolchains/actions:cpp_compile_actions": ":arm-none-eabi-g++",
"@rules_cc//cc/toolchains/actions:link_actions": ":arm-none-eabi-ld",
"@rules_cc//cc/toolchains/actions:objcopy_embed_data": ":arm-none-eabi-objcopy",
"@pigweed//pw_toolchain/action:objdump": ":arm-none-eabi-objdump",
"@pigweed//pw_toolchain/action:objdump_disassemble": ":arm-none-eabi-objdump",
"@rules_cc//cc/toolchains/actions:strip": ":arm-none-eabi-strip",
"@rules_cc//cc/toolchains/actions:ar_actions": ":arm-none-eabi-ar"
},
Expand Down
2 changes: 1 addition & 1 deletion pw_toolchain/build_external/llvm_clang.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ COMMON_TOOLS = {
"@rules_cc//cc/toolchains/actions:cpp_compile_actions": ":clang++",
"@rules_cc//cc/toolchains/actions:link_actions": ":lld",
"@rules_cc//cc/toolchains/actions:objcopy_embed_data": ":llvm-objcopy",
"@pigweed//pw_toolchain/action:objdump": ":llvm-objdump",
"@pigweed//pw_toolchain/action:objdump_disassemble": ":llvm-objdump",
"@rules_cc//cc/toolchains/actions:strip": ":llvm-strip",
}

Expand Down
3 changes: 2 additions & 1 deletion pw_toolchain_bazel/actions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# the License.

load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
load("@pigweed//pw_toolchain/action:action_names.bzl", "PW_ACTION_NAMES")
load("//actions:defs.bzl", "pw_cc_action_name", "pw_cc_action_name_set")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -152,7 +153,7 @@ pw_cc_action_name(
# This action name isn't yet a well-known action name.
pw_cc_action_name(
name = "objdump_embed_data",
action_name = "objdump_embed_data",
action_name = PW_ACTION_NAMES.objdump_disassemble,
)

pw_cc_action_name_set(
Expand Down

0 comments on commit 0a0160e

Please sign in to comment.