ESP32 exclude components from compilation


I am currently working on a project to create a very simple embedded project for an esp32dev board.
I imported configuration files from the helloworld example project and it compiles perfectly.

My problem is that it compiles unneeded libraries such as the bluetooth (bluedroid) library. It is not used in my application and I would like to ignore this libs. I tried multiple solutions:

  • lib_ignore in the ini file
  • Remove the #define CONFIG_BLUEDROID_ENABLED and all relaed bluetooth defines from the sdkconfig.h file. The only result is that the compilation of the bluedroid lib fails bescause of the missing defines.
  • Create my own (with the default options) sdkconfig.h with the ESP32 tool ( menuconfig and build) and copy it in my project. Same result, the compilation failed because of the missing bluedroid defines.
  • I was wondering if it was coming form the board esp32dev.json configuration file. Removing the connectivity node didn’t change anything.

I can’t find why this is compiled and where it is specified.

Here is my plateform.ini:
platform = espressif32
framework = espidf
board = esp32dev
board_build.partitions = partitions.csv
monitor_speed = 115200
lib_ldf_mode = deep+

The output gives me 0 dependencies. And the whole compilation starts again.
Please send help :slight_smile:

You mean the esp-idf/components/bt at release/v3.3 · espressif/esp-idf · GitHub component?

Per default, all components in the components folder are compiled. If they’re not used, the linker will remove them again, so they don’t affect the final binary.

Some files also look for

What kind of errors do you get?

Yes exactly. I just want to exclude that and other unused libs from the compilation as I have no need for it. Everytime I modify a Header file, it recompiles all the components and I didn’t find how to avoid that.

In file included from C:\Users\nhh\.platformio\packages\framework-espidf\components\bt\bluedroid\bta\gatt\bta_gattc_act.c:27:0:
C:/Users/nhh/.platformio/packages/framework-espidf/components/bt/bluedroid/common/include/common/bt_target.h:866:37: error: 'MAX_ACL_CONNECTIONS' undeclared here (not in a function)
#define MAX_L2CAP_CHANNELS          MAX_ACL_CONNECTIONS  //This is used in the BLE client when start connected with the peer device

It looks for MAX_ACL_CONNECTIONS but I removed every bluetooth related define from the sdkconfig.h in order to try to exclude the lib from the compilation.

Does that mean I have to manually modify the ignore_dirs list in the file to ignore components? This solution seems very hard to maintain between projects as I might need the component for another project and I would have to modify it again. Did I miss a way to do it in the .ini file?
I understand that it is the default behaviour but as it takes 5 min to recompile my project everytime, I’m just looking for a way to avoid the recompilation of unused components.

EDIT: I tried modifying the ignore_dirs in C:\Users\user\.platformio\platforms\espressif32\builder\frameworks\ and it worked perferctly. As I said before, this solution is okay and works for now but is there any other way to do it and make it project dependent with plateformio ?

Do you see a significant difference in the resulting binary sizes btw?

I don’t think there’s a way to modify this internal build procedure from the platformio.ini or an advanced script (if it’s not accessing internal vodoo), but generally you can always fork the GitHub - platformio/platform-espressif32: Espressif 32: development platform for PlatformIO repo, make modifications to it, and then use platform = <link to your modified espressif32 repo to use it.

As you mentioned before, if the components are not used, the linker removes them from the binary. The binary final size is exactly the same in both cases.

I will try the Fork solution but I’m hoping ESP changes that and make it configurable through the build command.

Thanks a lot for your help.

1 Like