Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[toolchains] Add helper for extracting action names from cc_action_type rules #292

Open
armandomontanez opened this issue Dec 16, 2024 · 0 comments

Comments

@armandomontanez
Copy link
Collaborator

Many rules use cc_common.get_tool_for_action() to create custom rules that employ binaries from the current C/C++ toolchain. The status-quo today is to use the string constants exposed in Starlark files. Since these are now represented as rules, it's plausible to express the action types by referencing the source-of-truth cc_action_type rule. Today this is not possible because the providers for toolchain rules are considered private and not exposed to prevent projects from relying on implementation details of the toolchain rules.

Proposed solution

The simplest path forward is to add a action_name_from_action_type(target) helper that takes a target and extracts the action name from the action type. This will work as a bridge so user can do things like:

def _foo_rule_impl(ctx):
    # ...
    tool_path = cc_common.get_tool_for_action(
        feature_configuration = action_name_from_action_type(ctx.attr._objcopy),
        action_name = action_name,
    )
    # Run tool...


foo_rule = rule(
    implementation = _foo_rule_impl,
    attrs = {
        "_objcopy": attr.label(
            default = "@rules_cc//cc/toolchains/actions:objcopy_embed_data",
        ),
    },
    toolchains = use_cpp_toolchain(),
    fragments = ["cpp"],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant