G0: add a build example to check G0 dependencies

This commit is contained in:
Omar Chebib 2022-04-28 16:41:02 +08:00
parent 5bcd9b2db8
commit 33ac70a3ed
5 changed files with 92 additions and 1 deletions

View File

@ -11,7 +11,6 @@ subgraph cluster_g0 {
esp_common;
esp_rom;
${CONFIG_IDF_TARGET_ARCH};
${CONFIG_IDF_TARGET};
}
subgraph cluster_g1 {

View File

@ -0,0 +1,46 @@
# 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)
# Force this project to use only G0 components
set(all_g0_components esp_rom soc hal esp_common main) # also <arch>, i.e. xtensa or riscv, will be added below
set(COMPONENTS ${all_g0_components})
# By default, common components include some G1+ components. Override common components to only have G0 ones
idf_build_set_property(__COMPONENT_REQUIRES_COMMON "${all_g0_components}")
# Generate a graph to visually see the dependencies between G0 and G1+ (if any)
idf_build_set_property(__BUILD_COMPONENT_DEPGRAPH_ENABLED 1)
project(g0_components)
# As a workaround for ESP32-C2, we need to define the MMU page size here, until MMU hal-driver
# is refactored
if(CONFIG_IDF_TARGET_ESP32C2)
idf_build_set_property(C_COMPILE_OPTIONS "-DCONFIG_MMU_PAGE_SIZE=64" APPEND)
endif()
# Now that the project has been initialized, let's check which components it is using
# The following variable lists all the components that shall be used by this project
set(expected_components
${COMPONENTS}
${CONFIG_IDF_TARGET_ARCH} # xtensa or riscv
)
# Do not include libc into the build, we don't have any libC in G0
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nostdlib")
# Get all the components that were required to initialize this project
idf_build_get_property(build_components BUILD_COMPONENTS)
# Sort lists to be able to compare them literally
list(SORT expected_components)
list(SORT build_components)
if(NOT "${expected_components}" STREQUAL "${build_components}")
message(FATAL_ERROR "Unexpected components list in G0 build\n"
"Expected: ${expected_components}\n"
"Actual: ${build_components}")
endif()

View File

@ -0,0 +1,33 @@
| Supported Targets | ESP32-C3 | ESP32-C2 | ESP32-H2 |
| ----------------- | -------- | -------- | -------- |
All Xtensa based targets (ESP32, ESP32-S2, ESP32-S3) are currently not supported by this test, because their components having dependencies on G1+ components.
# "G0"-components-only app
This test application will compile ESP-IDF and this test's main component with G0 components only. The goal is to make sure that no G0 component depends
on G1 or higher component.
Currently, this test only supports RISC-V based targets as Xtensa ones still have some G0 components depending on G1+ components.
Compiling this test with an Xtensa based target will result in a CMake error, showing all the non-G0 components included in the build file generation.
The purpose of this example is to make sure that any modification to ESP-IDF doesn't violate the G0-G1+ dependency rule.
# Using this test app
Set the target to a RISC-V based, `esp32c3` for example:
```bash
idf.py set-target esp32c3
```
Then, trigger the build:
```bash
idf.py build
```
Build should be successful if there is no dependency problem between G0 and upper layers.
# Component dependencies graph (`component_deps.dot`)
When this project is configured, `component_deps.dot` file in the build directory is generated. This file contains a Graphviz graph showing the component dependencies. You can visualize this graph (using `dot` tool or online at https://dreampuf.github.io/GraphvizOnline/) to see why an extra component got added. You can also build the project for the base branch, to compare the graph to a known good one.

View File

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

View File

@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
void app_main(void)
{
}