This example shows how Bazel flags can be generated from Kconfig values and used in conditional compilation. This relies on the root MODULE.bazel using the libkconfig and libproject_configs module extensions. libproject_configs is used to generate two repositories corresponding to examples/hello_kconfig:debug.conf
and examples/hello_kconfig:nodebug.conf
, respectively. The names of the generated repositories are @debug and @nodebug, coming from the project conf filename.
To use the generated Bazel flags, we load KCONFIG_FLAGS from @debug and @nodebug, respectively. This example provides two platforms, one with the debug flag and one without the debug flag.
To see the effect in conditional compilation, try these:
bazelisk build --verbose_failures --platforms=//examples/hello_kconfig:sample_platform_debug //exampl es/hello_kconfig:debug
bazelisk build --verbose_failures --platforms=//examples/hello_kconfig:sample_platform_nodebug //exampl es/hello_kconfig:debug
The first build will compile debug.cc while the second will not.