Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
3a6c66a
commit 459420c
Showing
2 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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 = {}, | ||
) |