I am creating a library to do things I (and hopefully others ) want to reuse in several different projects. So far my library has been monolithic and I could make it work in PlatformIO by adding a single library.json in the root of my Git repo.
However, I recently found that there is some functionality in the library which is only needed in some projects but is fairly heavy in terms of memory usage. If you are working on something like an ESP32, you would hardly notice. If you are using the same library on an Atmega328, it eats up almost all of the space. Therefore, I decided to split the code in two: The cheap base part everyone needs and the expensive fancy extension only some projects make use of. However, I have now run into trouble how to make PlatformIO aware of this fact.
I could simply split the libraries into two repositories and add a dependency between them. However, this will make developing the library as a hole very cumbersome, as both parts are tightly coupled. For every commit in one library you would always need to have the exact matching commit from the other repo. I also use a CMake-based Unit Test setup as well as Github Actions, both of which would become more difficult to manage in this setup so that I don’t consider this as an option.
The PlatformIO documentation points to an example for providing multiple libraries in a single repository. This example just has library.json files in subfolders of the repository where appropriate. I have tried to recreate this setup in my repository by providing two library.json files in the respective subdirectories. However, as I am frequently developing the library and projects in parallel (project needs drive library changes), my local platformio.ini typically points to the master branch of the library repository directly. In addition, I don’t want to release a change to the setup until I know that it actually works . With my setup, PlatformIO apparently doesn’t pick up the two library.json files in the repository. If I check
platformio run -v, I see that only the base library directory is added to the include directories (which is the wrong directory to use for my library) while all sources are used - indicative of the original behavior where I had no library.json at all.
As a result of this, I basically have two questions:
- How do I make PlatformIO pick up that there are two libraries behind that single lib_deps pointing to Github?
- How do I tell PlatformIO to only use one of those for my current project?