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
- id: C1 claim: select() lets users toggle build rule attribute values from the command line. source: S1 evidence: "lets users toggle the values of build rule attributes at the command line"
- id: C2 claim: select() chooses among configuration conditions that are labels referencing config_setting. source: S1 evidence: "which are labels referencing [
config_setting]"
- id: C3 claim: Bazel's SelectorList class implements the Starlark select() function for BUILD and .bzl files. source: S2 evidence: "Implementation of the Starlark {@code select()} function exposed to BUILD and .bzl files."
Sources
- [S1] Configurable Build Attributes. Bazel docs. https://bazel.build/configure/attributes . License: Apache-2.0. Accessed 2026-11-19.
- [S2] SelectorList.java. Bazel source. https://raw.githubusercontent.com/bazelbuild/bazel/master/src/main/java/com/google/devtools/build/lib/packages/SelectorList.java . License: Apache-2.0. Accessed 2026-11-19.
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
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.},
}
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.
- bazel-select.table.json (table; CC-BY-4.0)
- bazel-select.schema.json (schema; CC-BY-4.0)
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.