Platform-independent menuconfig/kconfig

Hi!

So I have been trying to evolve my setup and tries to use PlatformIO to work more platform- and board independently. Recently put up a multiplatform/board example project that I am thinking could be of use for others.

One thing annoys me, though; and that is that I can only use menuconfig for esp-idf-stuff, and not for Native platform stuff.

I have looked around a little, and to me it would appear that that should not be impossible to implement for almost any platform. I mean, an sdkconfig.h-file could be included by anyone and generated by anyone.

Anyone know if there has been any work on this? Is it just me that think this would be great?

Kind regards. Nicklas

What things would be configurable in the menuconfig for platform = native?

I don’t know about any general stuff, but it would be very useful for me to configure my own projects, I use Kconfig-files a lot for that for ESP32, so it would really nice to have that in Native (or Arduino or any other platform) as well to be able to have the same configuration options available regardless if my code runs on native or some board.

I found this minimal example which indicates that it shouldn’t be all that hard:

@maxgerhardt

For the record, I have found a way that works, and it way easier than the above.
It uses kconfiglib (pip install kconfiglib), which installs all of the tools, and seemed to be installed already, possibly by ESP-IDF.

So now I have added Kconfigs to both Native and Arduino in my project (ESP-IDF obviously already has it). It adds itself automatically, it might work with more frameworks.
As I don’t control the Arduino and Native platforms, It isn’t the most elegant as I need extra_scripts .
Neither it is the most intelligent, as it doesn’t look for Kconfigs everywhere like ESP-IDF. So far though, my configs all orsource each other, so it doesn’t matter. But for it to be general, that would have to be added.

It has the following scripts and templates, and they are in the [env] extra_scripts, hence called by all environments.

  1. scripts/init_env.py
    If the framework isn’t ESP-IDF, it adds a “Run Menuconfig” project task to the current environment.

  2. scripts/run_menuconfig.py
    When the “Run Menuconfig” task is clicked, it passes the environment name, let’s says it is uno, for my Arduino environment to scripts/run_menuconfig.py.
    First it copies scripts/Kconfig.template to ./Kconfig.uno.
    Then it runs:
    KCONFIG_CONFIG=.config.uno menuconfig ./Kconfig.uno
    …producing .config.uno when the user saves the settings.

  3. pre:scripts/pre-build.py
    This is run on every build, it runs:
    KCONFIG_CONFIG=.config.uno genconfig Kconfig.uno --header-path $BUILD_DIR/config/someconfig.h
    …to create the header file in $BUILD_DIR/config and adds it to the CPPPATH and env.BuildSources.

That is it. I have actually added another header file into $BUILD_DIR/config that imports sdkconfig.h if it is ESP-IDF and my own file if its not, so the code can be unaware of the platform, at least config-wise. But that is not needed for replicating the ESP-IDF config, or much of it, at least.

Personally, I have a huge number of settings in what I am doing now (a framework for making code way more platform-oblivious), it’s timeouts, GPIOs names, I2C addresses, LoRa settings and whatnot, so I would not have been able to make it work without Kconfig.

I added it to my config-demo-repo:

Docs: