18 lines · plain
1def _workspace_root_impl(ctx):2 """Dynamically determine the workspace root from the current context.3 4 The path is made available as a `WORKSPACE_ROOT` environmment variable and5 may for instance be consumed in the `toolchains` attributes for `cc_library`6 and `genrule` targets.7 """8 return [9 platform_common.TemplateVariableInfo({10 "WORKSPACE_ROOT": ctx.label.workspace_root,11 }),12 ]13 14workspace_root = rule(15 implementation = _workspace_root_impl,16 attrs = {},17)18