Multiple Libraries in a single Git repository

Hi PlatformIO-World!
I am creating a library to do things I (and hopefully others :slight_smile:) 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 :sweat_smile:. 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:

  1. How do I make PlatformIO pick up that there are two libraries behind that single lib_deps pointing to Github?
  2. How do I tell PlatformIO to only use one of those for my current project?


1 Like

According to How can I create a repository with multiple libraries in it on GitHub and use them in a project? having more than one library in a repository simply isn’t supported by platformio.

Thread resurrection! If anyone else reads this, and wants to sometimes remove one section of a library, you can use #define and #ifdef to control what is included by the compiler. Many libraries do this, for example TFT_eSPI/User_Setup.h at master · Bodmer/TFT_eSPI · GitHub

I am aware that you can mutate your code in arbitrary ways using the preprocessor. However, doing that is incredibly awkward and unnecessarily error prone, especially if your code has a design that separates its parts. Therefore I don’t see that as a real solution and hence posted the question. I had kind of hoped that we had progressed past the 80s, here.