Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/configs/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=4096

# OpenThread support
CONFIG_OPENTHREAD_ENABLED=y

CONFIG_APP_REPRODUCIBLE_BUILD=y
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix the `esp_app_desc!` macro so that it properly embeds `CONFIG_ESP_EFUSE_BLOCK_REV_MIN_FULL`/`CONFIG_ESP_EFUSE_BLOCK_REV_MAX_FULL` with recent ESP-IDF versions (5.4+, 5.2.3+, 5.3.2+)
- Make sure that the `esp_app_desc!` macro fails at build-time if some of the fields cannot fit inside the structure
- Re-enable "esp_lcd_panel_rgb.h" after >= v5.3 for targets with SOC_LCD_RGB_SUPPORTED
- Many esp-idf kconfig attributes are now compile time verified and registerd as rustc cfg attributes (unknown_cfg lint)
- Fix unknown "alloc" feature
- Corectly use c_char instead of i8 in esp_app_desc in case of reproducibale builds

## [0.36.1] - 2025-01-10

Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "README.md"
links = "esp_idf"
build = "build/build.rs"
documentation = "https://docs.esp-rs.org/esp-idf-sys/"
rust-version = "1.66"
rust-version = "1.77"

[lib]
harness = false
Expand All @@ -29,6 +29,10 @@ libstart = []
native = []
pio = ["embuild/pio"]

# only used internally to collect all possible combinations of generated cargo confings
__collect_cfg = []
__collect_git_tags = []

[dependencies]
libc = "0.2" # Only to check if the rustc flag `-cfg espidf_time64` is properly defined
build-time = "0.1" # For esp_app_desc!()
Expand Down
72 changes: 72 additions & 0 deletions build/assets/sdkconfig_bt_classic.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this specialized sdkconfig necessary?

CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y

# Examples often require a larger than the default stack size for the main thread and for the sysloop event task.
CONFIG_ESP_TIMER_TASK_STACK_SIZE=4096 # Necessary when the `embassy-time-driver` feature is enabled
CONFIG_ESP_MAIN_TASK_STACK_SIZE=20000
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=8192
CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=8192

# Go figure...
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=4096

# Enable WS support
CONFIG_HTTPD_WS_SUPPORT=y

# SPI Ethernet demo
CONFIG_ETH_SPI_ETHERNET_DM9051=y
CONFIG_ETH_SPI_ETHERNET_W5500=y
CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL=y

# We don't have an example for classic BT - yet - we need to enable class BT
# specifically to workaround this bug in ESP IDF v5.2 (fixed in ESP IDF v5.2.1+):
# https://github.com/espressif/esp-idf/issues/13113
CONFIG_BT_CLASSIC_ENABLED=y

# BLE with Bluedroid
CONFIG_BT_ENABLED=y
CONFIG_BT_BLUEDROID_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n
CONFIG_BT_BTC_TASK_STACK_SIZE=15000
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=y

# Support for TLS with a pre-shared key.
CONFIG_ESP_TLS_PSK_VERIFICATION=y

CONFIG_LWIP_PPP_SUPPORT=y
CONFIG_LWIP_SLIP_SUPPORT=y

# Generic Thread functionality
CONFIG_OPENTHREAD_ENABLED=y

# Thread Border Router
CONFIG_OPENTHREAD_BORDER_ROUTER=y

# These are also necessary for the Joiner feature
CONFIG_MBEDTLS_CMAC_C=y
CONFIG_MBEDTLS_SSL_PROTO_DTLS=y
CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y
CONFIG_MBEDTLS_ECJPAKE_C=y

# Border Router again, LWIP
CONFIG_LWIP_IPV6_NUM_ADDRESSES=12
CONFIG_LWIP_NETIF_STATUS_CALLBACK=y
CONFIG_LWIP_IPV6_FORWARD=y
CONFIG_LWIP_MULTICAST_PING=y
CONFIG_LWIP_NETIF_STATUS_CALLBACK=y
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y
CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM=y
CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_CUSTOM=y
CONFIG_LWIP_IPV6_AUTOCONFIG=y
CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096

# Border Router again, mDNS
CONFIG_MDNS_MULTIPLE_INSTANCE=y

# Littlefs on SD cards example
CONFIG_LITTLEFS_SDMMC_SUPPORT=y
26 changes: 26 additions & 0 deletions build/assets/sdkconfig_bt_trouble.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Examples often require a larger than the default stack size for the main thread and for the sysloop event task.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto?

CONFIG_ESP_TIMER_TASK_STACK_SIZE=4096 # Necessary when the `embassy-time-driver` feature is enabled
CONFIG_ESP_MAIN_TASK_STACK_SIZE=50000

# BT-HCI only ( tested for esp32c3) - they may have different names on xtensa modems with dual stack bt
CONFIG_BT_ENABLED=y

CONFIG_BT_BLUEDROID_ENABLED=n
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y

CONFIG_BT_CONTROLLER_ONLY=y
#CONFIG_BT_CONTROLLER_ENABLED=y
#CONFIG_BT_CTRL_HCI_MODE_VHCI=y
CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY=n
# following are only needed in flash only mode, and then the bt_config struct also needs to set the following values
#CONFIG_BT_CTRL_BLE_SCAN=y
#CONFIG_BT_CTRL_BLE_MASTER=y

CONFIG_BT_HCI_LOG_DEBUG_EN=y
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE=y

CONFIG_APP_REPRODUCIBLE_BUILD=y # by not using it in bt_classic.defaults we get the compile_time_date for free
#CONFIG_APP_COMPILE_TIME_DATE=y # if CONFIG_APP_REPRODUCIBLE_BUILD this is always false
25 changes: 25 additions & 0 deletions build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use embuild::{bindgen as bindgen_utils, build, cargo, kconfig, path_buf};
mod common;
mod config;

mod rust_cfg;

// Features `native` and `pio` control whether the build is performed using the "native" ESP IDF CMake-based build,
// or via the PlatformIO `espressif32` module. They work as follows:
// - If neither the `native` nor the `pio` feature is specified, native build would be used
Expand Down Expand Up @@ -194,6 +196,29 @@ fn main() -> anyhow::Result<()> {
cfg_args.propagate();
cfg_args.output();

// Collect all valid esp-idf version git tags.
// Allowes for compile time verification of cfg attributes.
//
// Collection is done out of band using the generate_cfg.sh script.
#[cfg(feature = "__collect_git_tags")]
{
rust_cfg::collect_git_tags();
}

// Collect all cfg attributes from the build system and register them as known rustc cfg attributes.
//
// This is limited to what the current run's sdkconfig will enable. Thats why we run this out of band for
Copy link
Collaborator

@ivmarkov ivmarkov Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like a non-starter then?

As in, we need an sdkconfig that is listing ALL possible configs. Wow. But if we go this route, we can just as well list ALL possible configs from ALL ESP-IDF versions and for ALL MCUs.

And if we do the above, we need a single such file, and we don't have to run any build then, as well have everything already listed in this file?

So, are you 100% sure, that iterating the kconfig data in the build.rs really only gives you those sdkconfig settings which are "enabled" (qurious also what this means for config values which are not boolean)?

If yes, I'm starting to wonder if there is no better way to approach the whole problem. Like parsing the kconfig files themselves. There might even be some python tooling that might be doing this already, in ESP-IDF?

Copy link
Collaborator

@ivmarkov ivmarkov Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be of interest: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/kconfig/configuration_structure.html

The "kconfig parsing" alternative I'm talking about would be basically iterating all components in the esp-idf source tree, as well as all user-provided components and parsing their kconfig files, so as to gather all possible options.

My point is some of this parsing code is likely to already exist as a python code in the esp-idf source tree. After all, idf.py menuconfig does that (and more).

// all possible targets, and a variety of sdkconfig files enabling different kind of esp-idf feature sets.
//
// Collection is is done out of band using the generate_cfg.sh script.
#[cfg(feature = "__collect_cfg")]
{
rust_cfg::collect_cfg_args(cfg_args.args.iter().cloned());
}

// Register every collected esp-idf config as a rustc cfg attribute.
rust_cfg::emit_check_cfg();

// In case other crates need to have access to the ESP-IDF C headers
build_output.cincl_args.propagate();

Expand Down
Loading