From 558d52fa9b9f2155ea9c476e0a3b587fc635a956 Mon Sep 17 00:00:00 2001 From: Yurii Date: Mon, 23 Nov 2026 08:41:21 +0300 Subject: [PATCH] fix: support clean SDK builds and portable C6 compiler flags Create the SDK source directory before pioarduino populates it so its project generator supplies app_main when Arduino autostart is disabled. Skip TinyUSB setup for S2 clean targets before accessing SDK packages. Move C6 constexpr attributes into a forced include header to preserve the size optimizations across SDK metadata parsing and POSIX shell execution. --- include/c6_compiler_flags.h | 5 +++++ platformio.ini | 5 ++--- tools/after_build_sdk.py | 4 ++++ tools/tinyusb_s2.py | 5 +++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 include/c6_compiler_flags.h diff --git a/include/c6_compiler_flags.h b/include/c6_compiler_flags.h new file mode 100644 index 0000000..5ba039f --- /dev/null +++ b/include/c6_compiler_flags.h @@ -0,0 +1,5 @@ +#pragma once + +// Preserve C6 size optimizations through SDK metadata and shell parsing. +#define _GLIBCXX20_CONSTEXPR __attribute__((cold)) constexpr +#define _GLIBCXX23_CONSTEXPR __attribute__((cold)) constexpr diff --git a/platformio.ini b/platformio.ini index 3951b96..f7d3d56 100644 --- a/platformio.ini +++ b/platformio.ini @@ -264,8 +264,7 @@ build_flags = ${esp32_defaults.build_flags} -msave-restore -fno-exceptions -Oz - -D _GLIBCXX20_CONSTEXPR=__attribute__((cold))constexpr - -D _GLIBCXX23_CONSTEXPR=__attribute__((cold))constexpr + -include "$PROJECT_DIR/include/c6_compiler_flags.h" -D USE_BLE=1 -D DEFAULT_OT_IN_GPIO=15 -D DEFAULT_OT_OUT_GPIO=23 @@ -286,7 +285,7 @@ custom_sdkconfig = ${esp32_defaults.custom_sdkconfig} '# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE is not set' '# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE is not set' CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y - ; Use the compact definitions above instead of spaced native metadata. + ; Constexpr attributes are supplied by the forced compiler header. '# CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD_CONSTEXPR is not set' '# CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_COLD is not set' CONFIG_COMPILER_CXX_GLIBCXX_CONSTEXPR_NO_CHANGE=y diff --git a/tools/after_build_sdk.py b/tools/after_build_sdk.py index db6e79c..86fb20c 100644 --- a/tools/after_build_sdk.py +++ b/tools/after_build_sdk.py @@ -5,6 +5,10 @@ import re Import("env") +# HybridCompile generates app_main when the SDK source directory is empty. +dummy = Path(env.subst("$PROJECT_DIR")) / ".dummy" +dummy.mkdir(exist_ok=True) + build_frameworks = env.BuildFrameworks diff --git a/tools/tinyusb_s2.py b/tools/tinyusb_s2.py index 242f671..e5d4422 100644 --- a/tools/tinyusb_s2.py +++ b/tools/tinyusb_s2.py @@ -4,8 +4,13 @@ from pathlib import Path import shutil import subprocess +from SCons.Script import Return + Import("env") +if env.IsCleanTarget(): + Return() + def checkout(repository, revision, directory): if not (directory / ".git").is_dir():