bazelbuild / bazelbuild/rules_cc
Cannot add extra actions using variables
- Dominant language
- Starlark
- Stars
- 247
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
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:
```bzl
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:
```bzl
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 https://github.com/bazelbuild/rules_cc/blob/848d56aa290b17535797f56ceafca39ab64d577f/cc/toolchains/impl/variables.bzl#L127-L136 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.
Contributor guide
Research direction
Start with cc/toolchains/impl/variables.bzl at the validation around lines 127-136 and reproduce the failure using the issue's cc_args example with objc_compile. Trace how variable accessibility is checked for nested actions; done means the requested extra action works without weakening the intended validation, with coverage added for this case if the repository has a suitable test entry point.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100