ESP-IDF: Libraries vs components

Hi!

I have a library GitHub - Johboh/GCMEncryption.
This library is built and published for Arduino and ESP-IDF frameworks to PlatformIO registry (as well as Arduino IDE library manager and ESP Component Registry).

If I create platformIO project using framework=arduino and add this library as a dependency (lib_deps = Johboh/GCMEncryption), and using the example code for Arduino, it builds and links fine.
The root CMakeLists.txt is not used when added as a library, only as a component.

However, if I change the framework to espidf (and uses the espidf example), I get linker errors with missing mbedtls. mbedtls is set as a required dependency here.

If I copy the files for the repo into a GCMEncryption folder under ./lib, and remove the lib_deps = Johboh/GCMEncryption dependency, it fails with the same linker issue.
If I add the files for the repo into a folder under ./components instead, it builds and links fine.

So the question is, are libraries not the same as components, do I need to specify them differently in platformio.ini, or is the library itself configured wrongly?
My goal here is to be able to provide a library/component for users of PlatformIO and the ESP-IDF framework, and for them to be able to add it as a dependency in their platformio.ini, same as if they where using the Arduino framework.

Regards,
Johan

lib_deps and framework = espidf don’t work together well in PlatformIO when the added “library” is actually an ESP-IDF component. The CMakeLists.txt and KConfig etc of the added library are not evaluated at all, and thus dependencies like mbedTLS might not be found.

At the same time,there is no platformio.ini directive for “add this ESP-IDF component to the build”, that’s done via other ESP-IDF native files.

So, this seems to also fall back to https://github.com/platformio/platform-espressif32/issues/453.

1 Like

As hinted in the thread you linked, instead of specifying the dependency using platformio.ini, doing it the “ESP-IDF way” by adding a idf_component.yml to the root with the dependency, works:

dependencies:
  gcmencryption: ">=0.5.2"

So I assume this the correct way of specifying external ESP-IDF components when building using the espidf framework and PlatformIO. In this case, the dependency is coming from the ESP-IDF component registry, and not as a platformIO dependency.