Documentation

Edit

Platform Rules

constraint_setting

constraint_setting(name, default_constraint_value, deprecation, distribs, 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_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 @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

Name; required

A unique name for this target.

default_constraint_value

Name; optional

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

constraint_value(name, constraint_setting, deprecation, distribs, 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

Name; required

A unique name for this target.

constraint_setting

Label; required

The constraint_setting for which this constraint_value is a possible choice.

platform

platform(name, constraint_values, deprecation, distribs, features, licenses, 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",
    ],
)

Arguments

Attributes
name

Name; required

A unique name for this target.

constraint_values

List of labels; optional

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 @bazel_tools//platforms:x86_64 and @bazel_tools//platforms:arm.

remote_execution_properties

String; optional

A string used to configure a remote execution platform. Actual builds make no attempt to interpret this, it is treated as opaque data that can be used by a specific SpawnRunner.

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

Name; required

A unique name for this target.

exec_compatible_with

List of labels; optional; nonconfigurable

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; optional; nonconfigurable

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.
toolchain

Name; required; nonconfigurable

The target representing the actual tool or tool suite that is made available when this toolchain is selected.
toolchain_type

Name; required; nonconfigurable

The label of a toolchain_type target that represents the role that this toolchain serves.