bazelbuild / bazelbuild/rules_android_ndk

Proposal to change `tools` to have absolute paths

Open
#96 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
43
Forks
32
PR merge metrics
No merged PRs in 30d

Description

Hi, I am building low-level software with this repository, and I found some problems here.

## Some binaries do not return absolute paths
This can be problematic when some bazel rules use `cc_common.get_tool_for_action` and execute them.
This is a use case that compiles a C code into an object and `objcopy` the content.
```starlark
def _gen_c_bin_impl(ctx):
"""
A rule that compiles C sources into an object, then extracts the .text section into a .bin file using objcopy.
"""
toolchain = ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]

feature_configuration = cc_common.configure_features(
ctx = ctx,
cc_toolchain = toolchain,
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
)

_, compilation_outputs = cc_common.compile(
actions = ctx.actions,
feature_configuration = feature_configuration,
cc_toolchain = toolchain,
name = ctx.label.name,
srcs = ctx.files.srcs,
public_hdrs = ctx.files.hdrs,
)

object_files = compilation_outputs.objects + compilation_outputs.pic_objects
if len(object_files) == 0:
fail("No object files produced from srcs = %s" % (ctx.files.srcs))
object_file = object_files[0]

bin_file = ctx.actions.declare_file(ctx.label.name + ".bin")

objcopy_tool = cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = "objcopy_embed_data",
)
if objcopy_tool == None:
fail("The C/C++ toolchain does not provide an objcopy tool.")

ctx.actions.run_shell(
inputs = [object_file],
outputs = [bin_file],
command = """
'{objcopy}' --only-section=.text -O binary '{in_o}' '{out_bin}'
""".format(
objcopy = objcopy_tool,
in_o = object_file.path,
out_bin = bin_file.path,
),
mnemonic = "Objcopy",
progress_message = "Extracting .text section from %s" % (object_file.path),
)

return [
DefaultInfo(
files = depset([bin_file]),
),
]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.