← All notes

Vary a Bazel attribute by configuration with select()

Answer: Configurable attributes, commonly known as select(), is a Bazel feature that lets users toggle attribute values at the command line. In source, SelectorList contains the implementation of the Starlark select() function exposed to BUILD and .bzl files.

Conditions

select() is a placeholder whose value is chosen from configuration conditions. The conditions are labels that reference a config_setting. The example includes a //conditions:default key.

A cc_binary can choose deps from flags. With --cpu=arm the value is [":arm_lib"]. With -c dbg and --cpu=x86 it is [":x86_dev_lib"]. With --cpu=ppc it is [":generic_lib"], including when -c dbg is also set.

| deps | config_setting | |---|---| | [":arm_lib"] | {"cpu": "arm"} | | [":x86_dev_lib"] | {"cpu": "x86", "compilation_mode": "dbg"} | | [":generic_lib"] | //conditions:default |

Empty dictionaries

The implementation reports that select({}) with an empty dictionary can never resolve because it includes no conditions. SelectorList can wrap a single value. SelectorList.concat creates a list that concatenates two values.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Bazel docs, Configurable Build Attributes; Bazel source, SelectorList.java. Apache-2.0; Apache-2.0. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Bazel docs, Configurable Build Attributes; Bazel source, SelectorList.java. Apache-2.0; Apache-2.0.

Cite this

Permanent ID: iil:note:va1g055q

iinventedlight. 2026. "Vary a Bazel attribute by configuration with select()." iinventedlight Library, iil:note:va1g055q, version of 2026-11-19. https://iinventedlight.com/library/notes/bazel-select/. License: CC-BY-4.0.

@misc{iil_note_va1g055q,
  author = {{iinventedlight}},
  title = {{Vary a Bazel attribute by configuration with select()}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-19},
  url = {https://iinventedlight.com/library/notes/bazel-select/},
  note = {Permanent ID iil:note:va1g055q. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/bazel-select.md.