examples: Add the component manager example

This commit is contained in:
Sergei Silnov 2021-08-02 18:59:33 +02:00
parent 3a4218156c
commit 018524ec7e
5 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,8 @@
# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(component_manager)

View File

@ -0,0 +1,55 @@
# Using the component manager for downloading dependencies
This example demonstrates how to use [IDF Component Manager](https://pypi.org/project/idf-component-manager/) for downloading dependencies from [the component registry](https://components.espressif.com). More details and use cases of IDF Component Manager can be found in the programming guide under `API Guides` -> `Tools` -> `IDF Component Manager`.
## How to use the example
### Hardware Required
This example is designed to work with any commonly available development kit.
### Build and Flash
Run `idf.py reconfigure` to configure this project. During CMake execution the component manager will process data from the manifest file `./main/idf_component.yml` where 2 dependencies are defined:
- `idf: ">=4.1"` - Specifies required version of ESP-IDF.
- `example/cmp: ">=3.3.3"` - Defines dependency on [example/cmp](https://components.espressif.com/component/example/cmp) component that is used by the main component.
CMake Output:
```
...
Solving dependencies requirements
Updating lock file at /home/user/esp-idf/examples/build_system/cmake/component_manager/dependencies.lock
Processing 2 dependencies:
[1/2] example/cmp
[2/2] idf
...
```
Content of the `./managed_components` directory after successful build:
```
> find ./managed_components
./managed_components
./managed_components/example__cmp
./managed_components/example__cmp/include
./managed_components/example__cmp/include/cmp.h
./managed_components/example__cmp/LICENSE
./managed_components/example__cmp/README.md
./managed_components/example__cmp/CMakeLists.txt
./managed_components/example__cmp/changelog.md
./managed_components/example__cmp/cmp.c
./managed_components/example__cmp/idf_component.yml
```
Flash the project and run the serial monitor to view the output:
```
idf.py -p PORT flash monitor
```
### Example Output
The example outputs a line from the `cmp_hello` function from the component downloaded by the component manager.
```
Hello from example component!
```

View File

@ -0,0 +1,2 @@
idf_component_register(SRCS "component_manager.c"
INCLUDE_DIRS ".")

View File

@ -0,0 +1,7 @@
#include <stdio.h>
#include "cmp.h"
void app_main(void)
{
cmp_hello();
}

View File

@ -0,0 +1,36 @@
dependencies:
# Required IDF version
idf: ">=4.1"
# Defining a dependency from the registry:
# https://components.espressif.com/component/example/cmp
example/cmp: ">=3.3.3"
# # Other ways to define dependencies
#
# # For components maintained by Espressif only name can be used.
# # Same as `espressif/cmp`
# component: "~1.0.0"
#
# # Or in a longer form with extra parameters
# component2:
# version: ">=2.0.0"
#
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect for the `main` component.
# # All dependencies of `main` are public by default.
# public: true
#
# # For components hosted on non-default registry:
# service_url: "https://componentregistry.company.com"
#
# # For components in git repository:
# test_component:
# path: test_component
# git: ssh://git@gitlab.com/user/components.git
#
# # For test projects during component development
# # components can be used from a local directory
# # with relative or absolute path
# some_local_component:
# path: ../../projects/component