Aaron Siddhartha Mondal 459420c33a
[Bazel] Use dynamic workspace root determination
The `clang:ast` and `clang:builtin_headers_gen` targets currently use hardcoded `external/llvm-project`
paths to access generated headers.

With bzlmod this path becomes dependent on the module name, module version and module extension,
so we need a more dynamic approach.

Does not affect the WORKSPACE build.

Reviewed By: GMNGeoffrey, #bazel_build

Differential Revision: https://reviews.llvm.org/D137007
2023-04-18 01:54:49 +02:00

18 lines
520 B
Python

def _workspace_root_impl(ctx):
"""Dynamically determine the workspace root from the current context.
The path is made available as a `WORKSPACE_ROOT` environmment variable and
may for instance be consumed in the `toolchains` attributes for `cc_library`
and `genrule` targets.
"""
return [
platform_common.TemplateVariableInfo({
"WORKSPACE_ROOT": ctx.label.workspace_root,
}),
]
workspace_root = rule(
implementation = _workspace_root_impl,
attrs = {},
)