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

Cannot add extra actions using variables #246

Open
keith opened this issue Sep 24, 2024 · 2 comments
Open

Cannot add extra actions using variables #246

keith opened this issue Sep 24, 2024 · 2 comments

Comments

@keith
Copy link
Member

keith commented Sep 24, 2024

Currently @rules_cc//cc/toolchains/actions:compile_actions doesn't contain @rules_cc//cc/toolchains/actions:objc_compile. If I want to define a toolchain that supports objc_compile, I would expect to be able to create cc_args like this:

cc_args(
    name = "my_user_compile_args",
    actions = [
        "@rules_cc//cc/toolchains/actions:compile_actions",
        "@rules_cc//cc/toolchains/actions:objc_compile",
    ],
    args = ["{flags}"],
    format = {
        "flags": "@rules_cc//cc/toolchains/variables:user_compile_flags",
    },
    iterate_over = "@rules_cc//cc/toolchains/variables:user_compile_flags",
)

But when I do this it fails with:

ERROR: /Users/ksmiley/dev/keith/bazel-cc-toolchain-example/toolchain/llvm/BUILD.bazel:276:8: in _cc_args rule //toolchain/llvm:user_compile_args2:
Traceback (most recent call last):
        File "/private/var/tmp/_bazel_ksmiley/9ab617f34b5a1a9018f0a6157e69be65/external/rules_cc~/cc/toolchains/args.bzl", line 46, column 29, in _cc_args_impl
                validate_nested_args(
        File "/private/var/tmp/_bazel_ksmiley/9ab617f34b5a1a9018f0a6157e69be65/external/rules_cc~/cc/toolchains/impl/args_utils.bzl", line 63, column 28, in validate_nested_args
                type = get_type(
        File "/private/var/tmp/_bazel_ksmiley/9ab617f34b5a1a9018f0a6157e69be65/external/rules_cc~/cc/toolchains/impl/variables.bzl", line 132, column 21, in get_type
                fail("The variable {var} is inaccessible from the action {action}. This is required because it is referenced in {nested_label}, which is included by {args_label}, which references that action".format(
Error in fail: The variable @@rules_cc~//cc/toolchains/variables:user_compile_flags is inaccessible from the action @@rules_cc~//cc/toolchains/actions:objc_compile. This is required because it is referenced in @@//toolchain/llvm:user_compile_args2, which is included by @@//toolchain/llvm:user_compile_args2, which references that action

If I remove the fail

if variables[outer].actions != None:
valid_actions = variables[outer].actions.to_list()
for action in actions:
if action not in valid_actions:
fail("The variable {var} is inaccessible from the action {action}. This is required because it is referenced in {nested_label}, which is included by {args_label}, which references that action".format(
var = variables[outer].label,
nested_label = nested_label,
args_label = args_label,
action = action.label,
))
it does seem to work as I expect, but I assume that would have some unintended side effects eventually?

My first attempt at this was to override the default feature, which suffered from the same issue.

@keith
Copy link
Member Author

keith commented Sep 24, 2024

This specific example would be fixed by #245, but I suppose there might be more cases like this

@keith
Copy link
Member Author

keith commented Sep 24, 2024

Actually this example isn't fixed automatically with that change, since the upstream feature also doesn't have objc-compile in that set. But with my fix I can define my custom feature overriding the default to fix it.

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