You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable formatting of environment variables in cc_args
Copybara Import from #413
BEGIN_PUBLIC
Enable formatting of environment variables in cc_args (#413)
Windows does not follow the Unix sysroot convention.
Instead, it uses the `INCLUDE` and `LIB` environment variables
to specify the include and library search paths.
This change enables formatting of the values of envirnoment variables set
in the `env` attribute of `cc_args` using the standard `format` attribute.
This allows Windows users to download a hermetic "sysroot" as part of the build,
and set the relevant "INCLUDE" and "LIB" environment variables.
Example usage:
```
cc_args(
name = "arg-include",
actions = [
"@rules_cc//cc/toolchains/actions:c_compile",
"@rules_cc//cc/toolchains/actions:cpp_compile_actions",
],
env = {
"INCLUDE": "{include}",
},
format = {
"include": ":sysroot-include",
},
data = [
":sysroot-include",
],
)
```
example repo: https://github.com/reutermj/windows-rules-based-toolchain-example
Future work:
Current implementation for the format substitution only allows for a single variable to be substituted. Users of the API often will need to substitute in multiple paths into the `INCLUDE`/`LIB` environment variables.
Closes#413
END_PUBLIC
COPYBARA_INTEGRATE_REVIEW=#413 from reutermj:main 4c59d66
PiperOrigin-RevId: 780817009
Change-Id: Ifab4889f94f788f24a2e585d124444b49102839b
Copy file name to clipboardExpand all lines: docs/toolchain_api.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -662,7 +662,7 @@ For more extensive examples, see the usages here:
662
662
| <aid="cc_args-args"></a>args | (List[str]) The command-line arguments that are applied by using this rule. This is mutually exclusive with [nested](#cc_args-nested). |`None`|
663
663
| <aid="cc_args-data"></a>data | (List[Label]) A list of runtime data dependencies that are required for these arguments to work as intended. |`None`|
664
664
| <aid="cc_args-env"></a>env | (Dict[str, str]) Environment variables that should be set when the tool is invoked. |`None`|
665
-
| <aid="cc_args-format"></a>format | (Dict[str, Label]) A mapping of format strings to the label of the corresponding [`cc_variable`](#cc_variable)that the value should be pulled from. All instances of `{variable_name}` will be replaced with the expanded value of `variable_name` in this dictionary. The complete list of possible variables can be found in https://github.com/bazelbuild/rules_cc/tree/main/cc/toolchains/variables/BUILD. It is not possible to declare custom variables--these are inherent to Bazel itself. |`{}`|
665
+
| <aid="cc_args-format"></a>format | (Dict[str, Label]) A mapping of format strings to the label of a corresponding target. This target can be a `directory`, `subdirectory`, [`cc_variable`](#cc_variable), or a single file that the value should be pulled from. All instances of `{variable_name}`in the `args` list will be replaced with the expanded value in this dictionary. The complete list of possible variables can be found in https://github.com/bazelbuild/rules_cc/tree/main/cc/toolchains/variables/BUILD. It is not possible to declare custom variables--these are inherent to Bazel itself. |`{}`|
666
666
| <aid="cc_args-iterate_over"></a>iterate_over | (Label) The label of a [`cc_variable`](#cc_variable) that should be iterated over. This is intended for use with built-in variables that are lists. |`None`|
667
667
| <aid="cc_args-nested"></a>nested | (List[Label]) A list of [`cc_nested_args`](#cc_nested_args) rules that should be expanded to command-line arguments when this rule is used. This is mutually exclusive with [args](#cc_args-args). |`None`|
668
668
| <aid="cc_args-requires_not_none"></a>requires_not_none | (Label) The label of a [`cc_variable`](#cc_variable) that should be checked for existence before expanding this rule. If the variable is None, this rule will be ignored. |`None`|
0 commit comments