Page 1 of 1

Component manager with circular dependencies

Posted: Thu Jun 05, 2025 10:58 am
by rocotocloc
I am trying to understand how IDF Component Manager deals with circular dependencies.

I have 2 components: "component_a" and "component_b" and they depend on each other

This is component_a.c:

Code: Select all

#include <stdio.h>
#include "component_a.h"
#include "component_b.h"

void funcA(void)
{
    printf("Function A from Component A\n");
    funcD();
}

void funcC(void)
{
    printf("Function C from Component A\n");
}

And this is component_b.c:

Code: Select all

#include <stdio.h>
#include "component_b.h"
#include "component_a.h"

void funcB(void)
{
    printf("Function B from Component B\n");
    funcC(); // Call function from Component A
}

void funcD(void)
{
    printf("Function D from Component B\n");
}

Since one needs the other, they declare the corresponding dependency.

This is idf_component.yml inside component_a:

Code: Select all

dependencies:
  component_b:
    path: ../component_b

And this is idf_component.yml inside component_b:

Code: Select all

dependencies:
  component_a:
    path: ../component_a

Ok so now I create a new project and from this one I just want to use "component_a" so idf_component.yml inside the new project looks like this:

Code: Select all

dependencies:
  component_a:
    path: ../my_components/component_a
And the source file just calls a function from "component_a" like this:

Code: Select all

#include <stdio.h>
#include "component_a.h"

void app_main(void)
{
    funcA();
    printf("Circular dependency example completed.\n");
}

If I compile it like this, then IDF Component Manager enters into a circular dependency loop and fails:

2025-06-05 12 51 19.png
2025-06-05 12 51 19.png (76.34 KiB) Viewed 202 times

The only way I can see to solve this is removing the dependencies of "component_a" and "component_b" and handle all the required dependencies in the main project.

This doesn't seem to be the perfect solution because this way I need to know all the dependencies needed by every component used, even components that I don't want to use directly in the main project (like component_b in this example)

Shouldn't the IDF Component Manager be able to handle this circular dependencies issue? Am I missing something here?

I also attach the vscode project that illustrates this example for better understanding.

Thank you.

Re: Component manager with circular dependencies

Posted: Thu Jun 05, 2025 11:35 am
by ok-home

Re: Component manager with circular dependencies

Posted: Thu Jun 05, 2025 2:42 pm
by rocotocloc
Hi @ok-home,

I had already looked into that property but that seems related to a later step. I am not getting a linker error but a dependency download loop.

Anyways if I modify the CMakeLists.txt of component_a from this:

Code: Select all

idf_component_register(SRCS "component_a.c"
                    INCLUDE_DIRS "include"
                    PRIV_REQUIRES "component_b")
To this:

Code: Select all

idf_component_register(SRCS "component_a.c"
                    INCLUDE_DIRS "include"
                    PRIV_REQUIRES "component_b")
idf_component_get_property(component_a component_a COMPONENT_LIB)
set_property(TARGET ${component_a} APPEND PROPERTY LINK_INTERFACE_MULTIPLICITY 5)
get_property(link_interface TARGET ${component_a} PROPERTY LINK_INTERFACE_MULTIPLICITY)
message(STATUS "link_interface is: ${link_interface}")
I still get the same circular dependency loop. I have also ensured the property has been propertly set by modifying the dependencies to make it run correctly so I can see the message "link_interface is: 5" in the console.

As I said I think the loop I am experimenting is previous to this configuration file. For example, even Iif I completely DELETE the contents of this file (wrong contents for sure), I still get the same infinite loop, like if this file is not processed until a later step.

Re: Component manager with circular dependencies

Posted: Tue Jun 10, 2025 2:18 pm
by rocotocloc
Hi all,

It seemed to be a bug, I posted it on GitHub and it's fixed now, just waiting for the new release: https://github.com/espressif/idf-compon ... 8076393530

Re: Component manager with circular dependencies

Posted: Fri Jun 13, 2025 5:15 am
by rocotocloc
Hi,

It's been fixed in release 2.2.2 of Component Manager: https://github.com/espressif/idf-compon ... r/releases

Run this to update in case you're interested:

Code: Select all

python -m pip install --upgrade idf-component-manager