IDF Build Apps

3.0.1 · active · verified Thu Apr 16

idf-build-apps is a Python library and command-line tool designed to streamline the process of building, flashing, and testing multiple ESP-IDF applications. It integrates deeply with the ESP-IDF CMake-based build system, offering functionalities for finding, building, and flashing projects across various targets. The current version is 3.0.1, with releases typically following ESP-IDF major updates or bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `idf-build-apps` to find and perform a dry run build for multiple ESP-IDF applications. It creates a temporary directory with two dummy ESP-IDF projects to ensure the example is runnable even without a pre-existing project structure. It highlights the crucial `IDF_PATH` environment variable and uses `dry_run=True` for safe execution. For a real build, set `dry_run=False` and ensure `IDF_PATH` points to your ESP-IDF installation.

import os
import shutil
from pathlib import Path
from idf_build_apps import build_apps, find_apps

# --- Create dummy ESP-IDF app structure for demonstration ---
# In a real scenario, 'my_app_1' and 'my_app_2' would be your actual ESP-IDF project directories.
# This setup allows the example to run without a complete ESP-IDF project, using dry_run.

dummy_root = Path('./idf_build_apps_quickstart_temp')
dummy_root.mkdir(exist_ok=True)

app1_path = dummy_root / 'my_app_1'
app1_path.mkdir(exist_ok=True)
(app1_path / 'CMakeLists.txt').write_text('cmake_minimum_required(VERSION 3.16)\ninclude($ENV{IDF_PATH}/tools/cmake/project.cmake)\nproject(my_app_1)')
(app1_path / 'sdkconfig').write_text('CONFIG_FREERTOS_HZ=100\n')
(app1_path / 'main.c').write_text('void app_main() {}')

app2_path = dummy_root / 'my_app_2'
app2_path.mkdir(exist_ok=True)
(app2_path / 'CMakeLists.txt').write_text('cmake_minimum_required(VERSION 3.16)\ninclude($ENV{IDF_PATH}/tools/cmake/project.cmake)\nproject(my_app_2)')
(app2_path / 'sdkconfig').write_text('CONFIG_FREERTOS_HZ=100\n')
(app2_path / 'main.c').write_text('void app_main() {}')

# --- Set up environment for idf-build-apps (critical) ---
# For actual building, IDF_PATH must point to a valid ESP-IDF installation.
# We use a placeholder here for dry_run to avoid immediate failure.
if 'IDF_PATH' not in os.environ:
    print("WARNING: IDF_PATH environment variable is not set. Using a placeholder for dry_run.")
    os.environ['IDF_PATH'] = '/path/to/esp-idf' # Replace with your actual ESP-IDF path

# --- Find applications ---
print(f"Searching for apps in: {dummy_root}")
apps = find_apps(
    dummy_root, # The root directory to search for apps
    recursive=True,
    target='esp32', # Specify the target chip (e.g., esp32, esp32s3)
    build_dir_name='build_idf_apps' # Name for the build output directory
)

print(f"Found {len(apps)} apps:")
for app in apps:
    print(f"  - {app.path.name} (target: {app.target}, build_dir: {app.build_path})")

# --- Build applications (dry run for safety and demonstrability) ---
# Set dry_run=False and ensure IDF_PATH is correct for a real build.
try:
    build_apps(
        apps,
        parallel_jobs=1, # Number of parallel build jobs
        dry_run=True, # Set to False for a real build
        verbose=True,
        # You can also pass 'work_dir', 'keep_partial_results', etc.
    )
    print("\nSuccessfully completed dry run for building apps.")
    print("To perform an actual build, set 'dry_run=False' and ensure 'IDF_PATH' is correctly configured.")
except Exception as e:
    print(f"\nAn error occurred during the build (dry_run): {e}")
    print("This might be expected if IDF_PATH is not fully set up for a real ESP-IDF build.")

# --- Clean up dummy files ---
# shutil.rmtree(dummy_root)
# print(f"Cleaned up temporary directory: {dummy_root}")

view raw JSON →