What's the recommended directory structure for reusable components?
Posted: Wed Mar 29, 2023 12:43 pm
We're currently organizing some of the boilerplate code we use frequently into idf components to facilitate reuse. Functionality such as network setup boilerplate, sensor drivers, basic infrastructure for ota device configuration, etc.
The component template generated by `idf.py create_component` seems to cater more to components that are used to structure single projects. E.g. out-of-the-box, the generated component can not even be compiled to an *.a archive for syntax checks, no test structure etc. is created, etc.
The following seems to me to be a common way for components to be structured abd is how I'm setting up our components currently :
It differs from the `create-component` template in that:
- the c implementation files are moved to a `src` directory instead of being in the top-level directory of the component
- I create an `example` (and/or `test`) project which demonstrates usage and from which I compile the component during development
Any thoughts on this? Did I skip an import part of the docs that explained how this should be structured? How is everyone else constructing their components?
The component template generated by `idf.py create_component` seems to cater more to components that are used to structure single projects. E.g. out-of-the-box, the generated component can not even be compiled to an *.a archive for syntax checks, no test structure etc. is created, etc.
The following seems to me to be a common way for components to be structured abd is how I'm setting up our components currently :
Code: Select all
.
├── CMakeLists.txt
├── example
│ ├── CMakeLists.txt
│ ├── main
│ │ ├── CMakeLists.txt
│ │ └── example.c
│ └── sdkconfig
├── include
│ └── my_component.h
├── README.md
└── src
└── my_component.c
- the c implementation files are moved to a `src` directory instead of being in the top-level directory of the component
- I create an `example` (and/or `test`) project which demonstrates usage and from which I compile the component during development
Any thoughts on this? Did I skip an import part of the docs that explained how this should be structured? How is everyone else constructing their components?