bazelbuild / bazelbuild/bazel-skylib

Make common_settings flags return platform_common.TemplateVariableInfo

Open
#268 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Starlark
Stars
444
Forks
202
PR merge metrics
No merged PRs in 30d

Description

This would allows for `genrule` and friends to consume args as templates, for instance:
```python
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")

string_flag(
name = "myflag",
)

genrule(
name = "myrule",
outs = ["value.txt"],
cmd = """echo $(@myrepo//mypkg:myflag) > $@""",
toolchains = [":myflags"],
)
```

I have a working prototype that just forward flags as templates, and it works well:
```python
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")

def _flags_supplier_impl(ctx):
flags = {}
for flag in ctx.attr.flags:
flags[str(flag.label)] = flag[BuildSettingInfo].value
return [
platform_common.TemplateVariableInfo(flags),
]

flags_supplier = rule(
implementation = _flags_supplier_impl,
attrs = {
"flags": attr.label_list(),
},
)
```

Contributor guide

Open the contributing guide

Research direction

Start in rules:common_settings.bzl and inspect the common_settings flags alongside the supplied _flags_supplier_impl prototype. Check how the flags are consumed by genrule and similar rules through platform_common.TemplateVariableInfo. Done means the flags can be used as templates in the shown genrule pattern, with the relevant existing behavior preserved.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.