Turn a simple build.config into a Bazel extension.

key_value_repo

Exposes a Bazel repository with key value pairs defined from srcs.

Configuration files shall contain a single pair of key and value separated by ‘=’. Keys and values are stripped, hence whitespace characters around the separator are allowed.

Example: Given a file common/build.config.constants with content

    CLANG_VERSION=r433403

The workspace file can instantiate a repository rule with

load("//build/kernel/kleaf:key_value_repo.bzl", "key_value_repo")

key_value_repo(
    name = "kernel_toolchain_info",
    srcs = ["//common:build.config.constants"],
)

and users of the repository can refer to the values with

load("@kernel_toolchain_info//:dict.bzl", "CLANG_VERSION")

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this repository.Namerequired
srcsConfiguration files storing ‘key=value’ pairs.List of labelsrequired
additional_valuesAdditional values in dict.bzlDictionary: String -> Stringoptional{}
repo_mappingIn WORKSPACE context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.

For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target).

This attribute is not supported in MODULE.bazel context (when invoking a repository rule inside a module extension's implementation function).
Dictionary: String -> Stringoptional