rules_kconfig
Bazel rules for parsing Kconfig
files and generating equivalent Bazel build settings and config.h headers.
Module extension
The primary interface is the kconfig module extension. Each kconfig.repo
tag parses a Kconfig file tree and generates a repository containing:
- A
bool_flag,int_flag, orstring_flagfor everyconfigsymbol. - A
cc_librarytarget (:config) that providesconfig.hreflecting the active flag values.
kconfig = use_extension("@rules_kconfig//kconfig:extensions.bzl", "kconfig")
kconfig.repo(
name = "my_kconfig",
kconfig = "//:Kconfig",
interpreter = "@python_3_12_host//:python",
)
use_repo(kconfig, "my_kconfig")
Use kconfig.overrides to overlay a .config file onto an external kconfig
repository via a Starlark transition:
kconfig.overrides(
name = "my_board_config",
kconfig = "@ext_kconfig//:ext_kconfig",
config = "//:.config",
interpreter = "@python_3_12_host//:python",
)
use_repo(kconfig, "my_board_config")
See the Introduction for full setup and usage instructions.
Rules
Providers
Repository Rules
Module Extensions
kconfig_library
load("@rules_kconfig//kconfig:defs.bzl", "kconfig_library")
kconfig_library(name, deps, srcs, root)
Collect Kconfig source files into a single provider for use by menuconfig and repository rules.
All source files must be real (non-generated) files. If a single source is
provided, it is automatically treated as the root. When multiple sources are
present, set root explicitly to indicate the top-level Kconfig entry point.
Transitive sources from deps are included in the provider.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | Other kconfig_library targets whose sources should be included transitively. | List of labels | optional | [] |
| srcs | Kconfig source files. Must be real (non-generated) files. | List of labels | optional | [] |
| root | The top-level Kconfig file. Inferred automatically when srcs contains exactly one file. | Label | optional | None |
kconfig_toolchain
load("@rules_kconfig//kconfig:defs.bzl", "kconfig_toolchain")
kconfig_toolchain(name, kconfiglib)
Declares a kconfig toolchain backed by kconfiglib.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| kconfiglib | A py_library providing kconfiglib. | Label | required |
menuconfig
load("@rules_kconfig//kconfig:defs.bzl", "menuconfig")
menuconfig(name, config, kconfig)
Launch kconfiglib's menuconfig TUI for interactive Kconfig editing.
Run with bazel run to interactively create or edit a .config file
against a Kconfig tree. The TUI writes the resulting configuration to
the path specified by config (relative to the workspace root).
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| config | Workspace-relative path to the .config file to read/write. | String | required | |
| kconfig | A kconfig_library target providing the Kconfig source tree. | Label | required |
KConfigInfo
load("@rules_kconfig//kconfig:defs.bzl", "KConfigInfo")
KConfigInfo(root, srcs)
Encapsulates a Kconfig source tree: an optional root file and all source files (direct and transitive).
FIELDS
kconfig_overrides_repository
load("@rules_kconfig//kconfig:defs.bzl", "kconfig_overrides_repository")
kconfig_overrides_repository(name, config, interpreter, kconfig, kconfiglib_anchor)
Overlay .config values onto an existing kconfig repository.
Reads the manifest from the source kconfig repository to locate the
symlinked Kconfig source tree, then reparses with kconfiglib and a
user-provided .config file. If the source repository was itself
created with a .config, the overrides are stacked on top of those
base values. Generates a defs.bzl containing a Starlark transition
and wrapper rule that apply the overrides.
Values explicitly set on the command line take precedence over the overlay.
The generated defs.bzl creates the transition and rule:
| rule | description |
|---|---|
kconfig_override_transition | A transition that applies transitions for each default in .config |
with_kconfig_overrides | A rule similar to alias that applies kconfig_override_transition to the target |
Use with_kconfig_overrides to wrap a kconfig-dependent target:
load("@base_kconfig_override//:defs.bzl", "with_kconfig_overrides")
with_kconfig_overrides(
name = "config",
actual = ":consumer_of_base",
)
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this repository. | Name | required | |
| config | .config file with override values. | Label | required | |
| interpreter | A Python interpreter target used to run the generator. | Label | required | |
| kconfig | Label to the kconfig manifest from the source kconfig repository (e.g. @my_kconfig//:my_kconfig). | Label | required | |
| kconfiglib_anchor | Label used to locate the kconfiglib package. Managed by the module extension. | Label | required |
kconfig_repository
load("@rules_kconfig//kconfig:defs.bzl", "kconfig_repository")
kconfig_repository(name, apparent_name, defaults, interpreter, kconfig, kconfiglib_anchor)
Parse a Kconfig file tree and generate a Bazel repository with build settings.
The generated repository contains a bool_flag, int_flag, or string_flag
for every config symbol found in the Kconfig tree, plus a cc_library
target (:config) providing a config.h header that reflects the active
flag values.
The Kconfig source tree is symlinked into kconfig_srcs/ and a
kconfig.manifest.json records the root file and all visited files.
A repo-named symlink (e.g. @my_kconfig//:my_kconfig) points to
the manifest for downstream consumers.
Prefer using the kconfig module extension rather than calling this rule
directly.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this repository. | Name | required | |
| apparent_name | The user-facing repository name (used for the repo-named symlink). Defaults to the canonical name. | String | optional | "" |
| defaults | Optional .config file with explicit symbol values that override Kconfig defaults. | Label | optional | None |
| interpreter | A Python interpreter target used to run the Kconfig parser. | Label | required | |
| kconfig | The root Kconfig file to parse. All files referenced via source directives are followed automatically. | Label | required | |
| kconfiglib_anchor | Label used to locate the kconfiglib package. Managed by the module extension. | Label | required |
kconfig
kconfig = use_extension("@rules_kconfig//kconfig:defs.bzl", "kconfig")
kconfig.overrides(name, config, interpreter, kconfig)
kconfig.repo(name, defaults, interpreter, kconfig)
Configure kconfig repositories.
TAG CLASSES
overrides
Overlay .config overrides onto an existing kconfig repository.
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | The name of the generated overrides repository. | Name | required | |
| config | .config file with override values. | Label | required | |
| interpreter | A Python interpreter target (e.g. @python_3_12_host//:python). | Label | required | |
| kconfig | Label to the kconfig manifest from the source repository (e.g. @ext_kconfig//:ext_kconfig). | Label | required |
repo
Declare a kconfig repository to be generated from a Kconfig file tree.
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | The name of the generated repository. Symbols are accessible as @<name>//:CONFIG_<symbol>. | Name | required | |
| defaults | Optional .config file providing default overrides for Kconfig symbols. | Label | optional | None |
| interpreter | A Python interpreter target used to run the Kconfig parser (e.g. @python_3_12_host//:python). | Label | required | |
| kconfig | The root Kconfig file to parse. All files referenced via source directives are followed automatically. | Label | required |