Platform Rules
constraint_setting
constraint_setting(name, default_constraint_value, deprecation, distribs, exec_compatible_with, features, licenses, tags, testonly, visibility)
This rule is used to introduce a new constraint type for which a platform may specify a value.
For instance, you might define a constraint_setting
named "glibc_version" to represent
the capability for platforms to have different versions of the glibc library installed. See the
Platforms page for more
details.
Each constraint_setting
has an extensible set of associated
constraint_value
s. 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 @bazel_tools//platforms:cpu
can be extended with a custom value in order to
define a platform targeting an obscure cpu architecture.
Arguments
Attributes | |
---|---|
name |
A unique name for this target. |
default_constraint_value
|
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 |
constraint_value
constraint_value(name, constraint_setting, deprecation, distribs, exec_compatible_with, features, licenses, tags, testonly, visibility)This rule introduces a new value for a given constraint type. See the Platforms page for more details.
Example
The following creates a new possible value for the predefined constraint_value
representing cpu architecture.
constraint_value( name = "mips", constraint_setting = "@bazel_tools//platforms:cpu", )Platforms can then declare that they have the
mips
architecture as an alternative to
x86_64
, arm
, and so on.
Arguments
Attributes | |
---|---|
name |
A unique name for this target. |
constraint_setting
|
constraint_setting for which this constraint_value is a
possible choice.
|
platform
platform(name, constraint_values, deprecation, distribs, exec_compatible_with, features, licenses, parents, remote_execution_properties, tags, testonly, visibility)
This rule defines a new platform -- a named collection of constraint choices (such as cpu architecture or compiler version) describing an environment in which part of the build may run. See the Platforms page for more details.
Example
This defines a platform that describes any environment running Linux on ARM.
platform( name = "linux_arm", constraint_values = [ "@bazel_tools//platforms:linux", "@bazel_tools//platforms:arm", ], )
Platform Inheritance
Platforms may use the "parents" 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 can also inherit the "remote_execution_properties" attribute from the parent platform. The logic for setting the "remote_execution_platform" is as follows when there is a parent platform:
- If "remote_execution_property" is not set on the child platform, the parent's "remote_execution_properties" will be used.
- If "remote_execution_property" is set on the child platform, and contains the literal string "{PARENT_REMOTE_EXECUTION_PROPERTIES}", that macro will be replaced with the contents of the parent's "remote_execution_property" attribute.
- If "remote_execution_property" is set on the child platform, and does not contain the macro, the child's "remote_execution_property" will be used unchanged.
Example
platform( name = "parent", constraint_values = [ "@bazel_tools//platforms:linux", "@bazel_tools//platforms:arm", ], remote_execution_properties = """ parent properties """, ) platform( name = "child_a", parents = [":parent"], constraint_values = [ "@bazel_tools//platforms:x86_64", ], remote_execution_properties = """ child a properties """, ) platform( name = "child_b", parents = [":parent"], remote_execution_properties = """ child b properties {PARENT_REMOTE_EXECUTION_PROPERTIES} more child b properties """, )
In these examples, the child platforms have the following properties:
- "child_a" has the constraint values "@bazel_tools//platforms:linux" (inherited from the parent) and "@bazel_tools//platforms:x86_64" (set directly on the platform). It has the "remote_execution_properties" set to "child a properties"
-
"child_b" inherits all constraint values from the parent, and doesn't set any of its own.
It has the "remote_execution_properties" set to:
child b properties parent properties more child b properties
Arguments
Attributes | |
---|---|
name |
A unique name for this target. |
constraint_values
|
Each |
parents
|
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.
|
remote_execution_properties
|
|
toolchain
toolchain(name, deprecation, distribs, exec_compatible_with, features, licenses, tags, target_compatible_with, testonly, toolchain, toolchain_type, visibility)
This rule declares a specific toolchain's type and constraints so that it can be selected during toolchain resolution. See the Toolchains page for more details.
Arguments
Attributes | |
---|---|
name |
A unique name for this target. |
exec_compatible_with
|
constraint_value s 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
|
constraint_value s that must be satisfied by the target platform in
order for this toolchain to be selected for a target building for that platform.
|
toolchain
|
|
toolchain_type
|
toolchain_type target that represents the role that this
toolchain serves.
|