Rules
constraint_setting
View rule sourceopen_in_newconstraint_setting named “glibc_version” to represent
the capability for platforms to have different versions of the glibc library installed.
For more details, see the
Platforms page.
Each constraint_setting has an extensible set of associated
constraint_values. Usually these are defined in the same package, but sometimes a
different package will introduce new values for an existing setting. For instance, the predefined
setting @platforms//cpu:cpu can be extended with a custom value in order to
define a platform targeting an obscure cpu architecture.
Arguments
| Attributes | |
|---|---|
name | Name; required A unique name for this target. |
default_constraint_value | Name; nonconfigurable; default is None The label of the default value for this setting, to be used if no value is given. If this attribute is present, the constraint_value it points to must be defined in the same package as this constraint_setting. If a constraint setting has a default value, then whenever a platform does not include any constraint value for that setting, it is the same as if the platform had specified the default value. Otherwise, if there is no default value, the constraint setting is considered to be unspecified by that platform. In that case, the platform would not match against any constraint list (such as for a config_setting) that requires a particular value for that setting. |
constraint_value
View rule sourceopen_in_newExample
The following creates a new possible value for the predefinedconstraint_value
representing cpu architecture.
mips architecture as an alternative to
x86_64, arm, and so on.
Arguments
| Attributes | |
|---|---|
name | Name; required A unique name for this target. |
constraint_setting | Label; nonconfigurable; required The constraint_setting for which this constraint_value is a possible choice. |
platform
View rule sourceopen_in_newExample
This defines a platform that describes any environment running Linux on ARM.Platform Flags
Platforms may use theflags attribute to specify a list of flags that will be added
to the configuration whenever the platform is used as the target platform (i.e., as the value of
the --platforms flag).
Flags set from the platform effectively have the highest precedence and overwrite any previous
value for that flag, from the command line, rc file, or transition.
Example
foo. When this is the target platform (either because
the user specified --platforms//:foo, because a transition set the
//command_line_option:platforms flag to ["//:foo"], or because
//:foo was used as an execution platform), then the given flags will be set in the
configuration.
Platforms and Repeatable Flags
Some flags will accumulate values when they are repeated, such as--features,
--copt, any Starlark flag created as config.string(repeatable = True).
These flags are not compatible with setting the flags from the platform: instead, all previous
values will be removed and overwritten with the values from the platform.
As an example, given the following platform, the invocation build --platforms=//:repeat_demo --features feature_a --features feature_b will end up with the value of the
--feature flag being ["feature_c", "feature_d"], removing the features
set on the command line.
flags attribute.
Platform Inheritance
Platforms may use theparents attribute to specify another platform that they will
inherit constraint values from. Although the parents attribute takes a list, no
more than a single value is currently supported, and specifying multiple parents is an error.
When checking for the value of a constraint setting in a platform, first the values directly set
(via the constraint_values attribute) are checked, and then the constraint values on
the parent. This continues recursively up the chain of parent platforms. In this manner, any
values set directly on a platform will override the values set on the parent.
Platforms inherit the exec_properties attribute from the parent platform.
The dictionary entries in exec_properties of the parent and child platforms
will be combined.
If the same key appears in both the parent’s and the child’s exec_properties,
the child’s value will be used. If the child platform specifies an empty string as a value, the
corresponding property will be unset.
Example: Constraint Values
child_ahas the constraint values@platforms//os:linux(inherited from the parent) and@platforms//cpu:x86_64(set directly on the platform).child_binherits all constraint values from the parent, and doesn’t set any of its own.
Example: Execution properties
child_ainherits the “exec_properties” of the parent and does not set its own.child_binherits the parent’sexec_propertiesand overrides the value ofk1. Itsexec_propertieswill be:{ "k1": "child", "k2": "v2" }.child_cinherits the parent’sexec_propertiesand unsetsk1. Itsexec_propertieswill be:{ "k2": "v2" }.child_dinherits the parent’sexec_propertiesand adds a new property. Itsexec_propertieswill be:{ "k1": "v1", "k2": "v2", "k3": "v3" }.
Arguments
| Attributes | |
|---|---|
name | Name; required A unique name for this target. |
constraint_values | List of labels; nonconfigurable; default is [] The combination of constraint choices that this platform comprises. In order for a platform to apply to a given environment, the environment must have at least the values in this list. Each constraint_value in this list must be for a different constraint_setting. For example, you cannot define a platform that requires the cpu architecture to be both @platforms//cpu:x86_64 and @platforms//cpu:arm. |
exec_properties | Dictionary: String -> String; nonconfigurable; default is {} A map of strings that affect the way actions are executed remotely. Bazel makes no attempt to interpret this, it is treated as opaque data that’s forwarded via the Platform field of the remote execution protocol. This includes any data from the parent platform’s exec_properties attributes. If the child and parent platform define the same keys, the child’s values are kept. Any keys associated with a value that is an empty string are removed from the dictionary. |
flags | List of strings; nonconfigurable; default is [] A list of flags that will be enabled when this platform is used as the target platform in a configuration. Only flags that are part of the configuration can be set, such as those that can be used in transitions, or the --define flag. |
missing_toolchain_error | String; nonconfigurable; default is "For more information on platforms or toolchains see https://bazel.build/concepts/platforms-intro." A custom error message that is displayed when a mandatory toolchain requirement cannot be satisfied for this target platform. Intended to point to relevant documentation users can read to understand why their toolchains are misconfigured. Not inherited from parent platforms. |
parents | List of labels; nonconfigurable; default is [] The label of a platform target that this platform should inherit from. Although the attribute takes a list, there should be no more than one platform present. Any constraint_settings not set directly on this platform will be found in the parent platform. See the section on Platform Inheritance for details. |
required_settings | List of labels; default is [] A list of config_settings that must be satisfied by the target configuration in order for this platform to be used as an execution platform during toolchain resolution. Required settings are not inherited from parent platforms. |
toolchain
View rule sourceopen_in_newArguments
| Attributes | |
|---|---|
name | Name; required A unique name for this target. |
exec_compatible_with | List of labels; nonconfigurable; default is [] A list of constraint_values that must be satisfied by an execution platform in order for this toolchain to be selected for a target building on that platform. |
target_compatible_with | List of labels; nonconfigurable; default is [] A list of constraint_values that must be satisfied by the target platform in order for this toolchain to be selected for a target building for that platform. |
target_settings | List of labels; default is [] A list of config_settings that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution. |
toolchain | Name; required The target representing the actual tool or tool suite that is made available when this toolchain is selected. |
toolchain_type | Label; nonconfigurable; required The label of a toolchain_type target that represents the role that this toolchain serves. |
use_target_platform_constraints | Boolean; nonconfigurable; default is False If True, this toolchain behaves as if its exec_compatible_with and target_compatible_with constraints are set to those of the current target platform. exec_compatible_with and target_compatible_with must not be set in that case. |
toolchain_type
View rule sourceopen_in_newExample
This defines a toolchain type for a custom rule.Arguments
| Attributes | |
|---|---|
name | Name; required A unique name for this target. |
no_match_error | String; nonconfigurable; default is "" A custom error message to display when no matching toolchain is found for this type. |