Build Task Compiles Unused Libraries

Starting a build seems to cause every single available library to be compiled, even if it is not included in the project. Does anyone know what causes this and how to avoid it?

I created a fresh project for the MAX32625PICO, did not edit any source code or any project files, and simply pressed the build button. The build takes about 16 minutes as it compiles seemingly every library available.
For example, I see many object files generated under build/max32625pico/FrameworkMbedconnectivity/drivers/cellular/, but the MAX32625PICO does not have cellular capability.

Then, if the “Intellisense index” is rebuilt, all of these libraries are recompiled.

This is actually how it’s implemented – the framework “mbedos” is seen as one big block of code, there is no subdivision in libraries (which PIO may recognize as used / unused).

I think Issues · platformio/builder-framework-mbed · GitHub is already tracking this somewhere.

Okay, at least this is known behaviour. I hope in the future, there’s a way for PIO to know which MBed libraries to not bother compiling, because it does add a significant amount of compile time.

Although the original issue is not directly related, I found a workaround mentioned here: Speeding up the build time · Issue #23 · platformio/builder-framework-mbed · GitHub
Direct link to repo. with the workaround: GitHub - Copper-Bot/PlatformIO-Helpers: Contains scripts and utils to improve PlatformIO usage experience

After adding .mbedignore and the python script, my build time reduced to around 6 minutes.