Skip to main content

constraint

Unified constraint rule that defines both a constraint setting and its possible values. Values are exposed as subtargets, e.g., cfg//:os[linux].

Function Signature

def constraint(
*,
name: str,
default_target_platform: None | str = None,
target_compatible_with: list[str] = [],
compatible_with: list[str] = [],
exec_compatible_with: list[str] = [],
visibility: list[str] = [],
within_view: list[str] = ["PUBLIC"],
metadata: OpaqueMetadata = {},
tests: list[str] = [],
modifiers: OpaqueMetadata = [],
_apple_platforms: dict[str, str] = {},
_exec_platform_marker: str = "prelude//cfg/exec_platform/marker:is_exec_platform[true]",
aliases: dict[str, str] = {},
allow_trivial_constraint: bool = False,
default: str,
execution_modifier: bool = False,
values: list[str],
) -> None

Parameters

  • name: (required)

    name of the target

  • default_target_platform: (defaults to: None)

    specifies the default target platform, used when no platforms are specified on the command line

  • target_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with a configuration

  • exec_compatible_with: (defaults to: [])

    a list of constraints that are required to be satisfied for this target to be compatible with an execution platform

  • visibility: (defaults to: [])

    a list of visibility patterns restricting what targets can depend on this one

  • within_view: (defaults to: ["PUBLIC"])

    a list of visibility patterns restricting what this target can depend on

  • metadata: (defaults to: {})

    a key-value map of metadata associated with this target

  • tests: (defaults to: [])

    a list of targets that provide tests for this one

  • modifiers: (defaults to: [])

    an array of modifiers associated with this target

  • aliases: (defaults to: {})

    Optional mapping of alias name -> declared value. Each alias becomes an additional subtarget that resolves to the same providers as the underlying value, letting users refer to a constraint value by a stable shorthand (e.g. :version[1.4]) that maps to a brittle underlying value (e.g. 1.4.5.xxx.67890). Alias names must not collide with declared values or reserved keywords, and alias values must appear in values.

  • allow_trivial_constraint: (defaults to: False)

    If True, allow this constraint to declare only one value. Intended for constraints that have just a default value most of the time and may temporarily gain additional values (e.g., versioned packages that pick up an extra value during an upgrade and drop it once the upgrade lands). Default is False, which requires at least two values.

  • default: (required)

    Default value (must be one of the values).

  • values: (required)

    List of value names.

Examples


constraint(
name = "os",
values = ["linux", "macos", "windows"],
default = "linux",
)