Skip to main content

configuration_alias

configuration_alias() acts like alias() but for configuration targets.

Details

The configuration_alias itself is a configuration rule and the actual attribute is expected to be a target defined by a configuration rule (such as constraint, constraint_setting, constraint_value, config_setting, or platform).

Unlike regular alias(), configuration_alias() can be used wherever configuration targets are expected, such as in select() keys or platform.constraint_values.

This rule is particularly useful for creating backwards-compatible aliases to constraint values defined using the unified constraint() rule, where values are referenced via subtargets (e.g., :os[linux]).

Function Signature

def configuration_alias(
*,
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] = {},
actual: 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

  • actual: (required)

    The target to alias. This should be a target defined by a configuration rule such as constraint, constraint_setting, constraint_value, config_setting, or platform.

Examples


# Define a constraint with multiple values using the unified constraint rule
constraint(
name = "os",
values = ["linux", "macos", "windows", "none"],
default = "none",
)

configuration_alias(
name = "linux",
actual = ":os[linux]",
)

configuration_alias(
name = "macos",
actual = ":os[macos]",
)

# The alias can be used in platform definitions
platform(
name = "linux_platform",
constraint_values = [
":linux", # Using the alias instead of :os[linux]
],
)

# The alias can be used in select() expressions
genrule(
name = "my_rule",
cmd = select({
":linux": "echo linux",
":macos": "echo macos",
":os[none]": "echo other", # Can also use subtarget directly
}),
out = "out.txt",
)