From 09bcefd08f9bcec81eaa2ce9b2fa06528d52cce6 Mon Sep 17 00:00:00 2001 From: Jason2866 Date: Fri, 14 Nov 2025 12:08:37 +0100 Subject: [PATCH 01/10] add lto handling to component manager --- builder/frameworks/component_manager.py | 123 ++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/builder/frameworks/component_manager.py b/builder/frameworks/component_manager.py index 5a34e8bde..9bd7cf78e 100644 --- a/builder/frameworks/component_manager.py +++ b/builder/frameworks/component_manager.py @@ -1271,3 +1271,126 @@ def print_changes_summary(self) -> None: session, useful for build reporting and debugging. """ self.logger.print_changes_summary() + + def remove_lto_flags(self) -> bool: + """ + Remove all -fno-lto flags from pioarduino-build.py. + + Removes all occurrences of -fno-lto from CCFLAGS, CFLAGS, CXXFLAGS, + and LINKFLAGS in the Arduino build script. + + Returns: + bool: True if successful, False otherwise + """ + build_py_path = str(Path(self.config.arduino_libs_mcu) / "pioarduino-build.py") + + if not os.path.exists(build_py_path): + print(f"Warning: pioarduino-build.py not found at {build_py_path}") + return False + + try: + with open(build_py_path, 'r', encoding='utf-8') as f: + content = f.read() + + # Remove all -fno-lto flags + modified_content = re.sub(r'["\']?-fno-lto["\']?,?\s*', '', content) + + # Clean up any resulting empty strings or double commas + modified_content = re.sub(r',\s*,', ',', modified_content) + modified_content = re.sub(r'\[\s*,', '[', modified_content) + modified_content = re.sub(r',\s*\]', ']', modified_content) + + with open(build_py_path, 'w', encoding='utf-8') as f: + f.write(modified_content) + + print("*** Removed -fno-lto flags from pioarduino-build.py ***") + return True + + except (IOError, OSError) as e: + print(f"Error removing -fno-lto flags: {e}") + return False + + def add_lto_flags(self) -> bool: + """ + Add LTO flags to pioarduino-build.py. + + Adds -flto=auto to CCFLAGS, CFLAGS, CXXFLAGS and -flto to LINKFLAGS + in the Arduino build script. + + Returns: + bool: True if successful, False otherwise + """ + build_py_path = str(Path(self.config.arduino_libs_mcu) / "pioarduino-build.py") + + if not os.path.exists(build_py_path): + print(f"Warning: pioarduino-build.py not found at {build_py_path}") + return False + + try: + with open(build_py_path, 'r', encoding='utf-8') as f: + lines = f.readlines() + + modified = False + new_lines = [] + + for line in lines: + # Add LTO flags to compiler flags + if 'CCFLAGS=' in line and '-flto' not in line: + line = line.rstrip() + if line.endswith(','): + line = line[:-1] + ', "-flto=auto",\n' + elif line.endswith(']'): + line = line[:-1] + ', "-flto=auto"]\n' + else: + line = line + '\n' + modified = True + + elif 'CFLAGS=' in line and 'CCFLAGS' not in line and '-flto' not in line: + line = line.rstrip() + if line.endswith(','): + line = line[:-1] + ', "-flto=auto",\n' + elif line.endswith(']'): + line = line[:-1] + ', "-flto=auto"]\n' + else: + line = line + '\n' + modified = True + + elif 'CXXFLAGS=' in line and '-flto' not in line: + line = line.rstrip() + if line.endswith(','): + line = line[:-1] + ', "-flto=auto",\n' + elif line.endswith(']'): + line = line[:-1] + ', "-flto=auto"]\n' + else: + line = line + '\n' + modified = True + + elif 'LINKFLAGS=' in line and '-flto' not in line: + line = line.rstrip() + if line.endswith(','): + line = line[:-1] + ', "-flto",\n' + elif line.endswith(']'): + line = line[:-1] + ', "-flto"]\n' + else: + line = line + '\n' + modified = True + + new_lines.append(line) + + if modified: + with open(build_py_path, 'w', encoding='utf-8') as f: + f.writelines(new_lines) + + print("*** Added LTO flags to pioarduino-build.py ***") + print(" CCFLAGS: -flto=auto") + print(" CFLAGS: -flto=auto") + print(" CXXFLAGS: -flto=auto") + print(" LINKFLAGS: -flto") + return True + else: + print("*** LTO flags already present in pioarduino-build.py ***") + return True + + except (IOError, OSError) as e: + print(f"Error adding LTO flags: {e}") + return False From 9a0ac789309c40908712e23e3a93341e98999dc1 Mon Sep 17 00:00:00 2001 From: Jason2866 Date: Fri, 14 Nov 2025 12:23:58 +0100 Subject: [PATCH 02/10] lto handling for Arduino HybridCompile --- builder/frameworks/arduino.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index 3ff6de9fd..e187d9eef 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -532,6 +532,7 @@ def safe_remove_sdkconfig_files(): flag_custom_component_remove = False flag_custom_component_add = False flag_lib_ignore = False +flag_lto = False if mcu == "esp32c2": flag_custom_sdkconfig = True @@ -600,6 +601,18 @@ def has_psram_config(): new_build_unflags = build_unflags.split() env.Replace(BUILD_UNFLAGS=new_build_unflags) + + # Check if BUILD_FLAGS contains -flto=auto + build_flags = env.get('BUILD_FLAGS', []) + if isinstance(build_flags, str): + build_flags = build_flags.split() + + if '-flto=auto' in build_flags: + # Remove -flto=auto from BUILD_FLAGS + build_flags = [flag for flag in build_flags if flag != '-flto=auto'] + env.Replace(BUILD_FLAGS=build_flags) + flag_lto = True + print("*** Detected -flto=auto in BUILD_FLAGS, will apply LTO management ***") def get_MD5_hash(phrase): @@ -916,6 +929,13 @@ def get_frameworks_in_current_env(): from component_manager import ComponentManager component_manager = ComponentManager(env) component_manager.handle_component_settings() + + # Handle LTO flags if flag_lto is set + if flag_lto: + # First remove existing -fno-lto flags, then add LTO flags + component_manager.remove_lto_flags() + component_manager.add_lto_flags() + silent_action = env.Action(component_manager.restore_pioarduino_build_py) # silence scons command output silent_action.strfunction = lambda target, source, env: '' From 888eba5ee14388b30fd479a3983527b3cd266520 Mon Sep 17 00:00:00 2001 From: Jason2866 Date: Fri, 14 Nov 2025 12:28:54 +0100 Subject: [PATCH 03/10] rename + safe guard --- builder/frameworks/arduino.py | 4 +++- builder/frameworks/component_manager.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index e187d9eef..cc89f1fdd 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -602,6 +602,8 @@ def has_psram_config(): new_build_unflags = build_unflags.split() env.Replace(BUILD_UNFLAGS=new_build_unflags) + if not env.get('BUILD_FLAGS'): # Initialize if not set + env['BUILD_FLAGS'] = [] # Check if BUILD_FLAGS contains -flto=auto build_flags = env.get('BUILD_FLAGS', []) if isinstance(build_flags, str): @@ -933,7 +935,7 @@ def get_frameworks_in_current_env(): # Handle LTO flags if flag_lto is set if flag_lto: # First remove existing -fno-lto flags, then add LTO flags - component_manager.remove_lto_flags() + component_manager.remove_no_lto_flags() component_manager.add_lto_flags() silent_action = env.Action(component_manager.restore_pioarduino_build_py) diff --git a/builder/frameworks/component_manager.py b/builder/frameworks/component_manager.py index 9bd7cf78e..32e22be06 100644 --- a/builder/frameworks/component_manager.py +++ b/builder/frameworks/component_manager.py @@ -1272,7 +1272,7 @@ def print_changes_summary(self) -> None: """ self.logger.print_changes_summary() - def remove_lto_flags(self) -> bool: + def remove_no_lto_flags(self) -> bool: """ Remove all -fno-lto flags from pioarduino-build.py. From dec9f8f62461fbece7f3d896e6abec3690039681 Mon Sep 17 00:00:00 2001 From: Jason2866 Date: Fri, 14 Nov 2025 13:02:57 +0100 Subject: [PATCH 04/10] fix add lto function --- builder/frameworks/component_manager.py | 105 ++++++++++++++---------- 1 file changed, 62 insertions(+), 43 deletions(-) diff --git a/builder/frameworks/component_manager.py b/builder/frameworks/component_manager.py index 32e22be06..7e93ac676 100644 --- a/builder/frameworks/component_manager.py +++ b/builder/frameworks/component_manager.py @@ -1328,58 +1328,77 @@ def add_lto_flags(self) -> bool: try: with open(build_py_path, 'r', encoding='utf-8') as f: - lines = f.readlines() + content = f.read() + original_content = content modified = False - new_lines = [] - for line in lines: - # Add LTO flags to compiler flags - if 'CCFLAGS=' in line and '-flto' not in line: - line = line.rstrip() - if line.endswith(','): - line = line[:-1] + ', "-flto=auto",\n' - elif line.endswith(']'): - line = line[:-1] + ', "-flto=auto"]\n' - else: - line = line + '\n' - modified = True - - elif 'CFLAGS=' in line and 'CCFLAGS' not in line and '-flto' not in line: - line = line.rstrip() - if line.endswith(','): - line = line[:-1] + ', "-flto=auto",\n' - elif line.endswith(']'): - line = line[:-1] + ', "-flto=auto"]\n' - else: - line = line + '\n' - modified = True - - elif 'CXXFLAGS=' in line and '-flto' not in line: - line = line.rstrip() - if line.endswith(','): - line = line[:-1] + ', "-flto=auto",\n' - elif line.endswith(']'): - line = line[:-1] + ', "-flto=auto"]\n' + # Pattern to find CCFLAGS list and add -flto=auto if not present + if 'CCFLAGS=[' in content and '"-flto' not in content[content.find('CCFLAGS=['):content.find('],', content.find('CCFLAGS=['))]: + # Find the closing bracket for CCFLAGS + start = content.find('CCFLAGS=[') + end = content.find('],', start) + 1 + ccflags_section = content[start:end] + + # Add -flto=auto before the closing bracket + new_ccflags = ccflags_section.replace('],', ',\n "-flto=auto"\n ],') + content = content[:start] + new_ccflags + content[end:] + modified = True + + # Pattern to find CFLAGS list and add -flto=auto if not present + if 'CFLAGS=[' in content and '"-flto' not in content[content.find('CFLAGS=['):content.find('],', content.find('CFLAGS=['))]: + start = content.find('CFLAGS=[') + end = content.find('],', start) + 1 + cflags_section = content[start:end] + + new_cflags = cflags_section.replace('],', ',\n "-flto=auto"\n ],') + content = content[:start] + new_cflags + content[end:] + modified = True + + # Pattern to find CXXFLAGS list and add -flto=auto if not present + if 'CXXFLAGS=[' in content and '"-flto' not in content[content.find('CXXFLAGS=['):content.find('],', content.find('CXXFLAGS=['))]: + start = content.find('CXXFLAGS=[') + end = content.find('],', start) + 1 + cxxflags_section = content[start:end] + + new_cxxflags = cxxflags_section.replace('],', ',\n "-flto=auto"\n ],') + content = content[:start] + new_cxxflags + content[end:] + modified = True + + # Pattern to find LINKFLAGS list and add -flto if not present + # Note: remove_no_lto_flags() needs to be called before + if 'LINKFLAGS=[' in content: + start = content.find('LINKFLAGS=[') + # Find the end of LINKFLAGS - look for the matching bracket + bracket_count = 0 + pos = start + len('LINKFLAGS=[') - 1 + while pos < len(content): + if content[pos] == '[': + bracket_count += 1 + elif content[pos] == ']': + bracket_count -= 1 + if bracket_count == 0: + end = pos + 1 + break + pos += 1 + + linkflags_section = content[start:end] + + # Check if -flto is already present + if '"-flto"' not in linkflags_section: + # Add -flto before the closing bracket + new_linkflags = linkflags_section.rstrip() + if new_linkflags.endswith(','): + new_linkflags = new_linkflags + '\n "-flto"' else: - line = line + '\n' - modified = True + new_linkflags = new_linkflags[:-1] + ',\n "-flto"\n ]' - elif 'LINKFLAGS=' in line and '-flto' not in line: - line = line.rstrip() - if line.endswith(','): - line = line[:-1] + ', "-flto",\n' - elif line.endswith(']'): - line = line[:-1] + ', "-flto"]\n' - else: - line = line + '\n' + content = content[:start] + new_linkflags + content[end:] modified = True - - new_lines.append(line) if modified: with open(build_py_path, 'w', encoding='utf-8') as f: - f.writelines(new_lines) + f.write(content) print("*** Added LTO flags to pioarduino-build.py ***") print(" CCFLAGS: -flto=auto") From a8905fd1b5c21cf7536755f57751ee39f02fb82f Mon Sep 17 00:00:00 2001 From: Jason2866 Date: Fri, 14 Nov 2025 13:12:46 +0100 Subject: [PATCH 05/10] more robust lto insert logic --- builder/frameworks/component_manager.py | 85 +++++++++---------------- 1 file changed, 29 insertions(+), 56 deletions(-) diff --git a/builder/frameworks/component_manager.py b/builder/frameworks/component_manager.py index 7e93ac676..e7fec1acd 100644 --- a/builder/frameworks/component_manager.py +++ b/builder/frameworks/component_manager.py @@ -1315,7 +1315,7 @@ def add_lto_flags(self) -> bool: Add LTO flags to pioarduino-build.py. Adds -flto=auto to CCFLAGS, CFLAGS, CXXFLAGS and -flto to LINKFLAGS - in the Arduino build script. + in the Arduino build script. Flags are inserted right after the opening bracket. Returns: bool: True if successful, False otherwise @@ -1333,68 +1333,41 @@ def add_lto_flags(self) -> bool: original_content = content modified = False - # Pattern to find CCFLAGS list and add -flto=auto if not present - if 'CCFLAGS=[' in content and '"-flto' not in content[content.find('CCFLAGS=['):content.find('],', content.find('CCFLAGS=['))]: - # Find the closing bracket for CCFLAGS - start = content.find('CCFLAGS=[') - end = content.find('],', start) + 1 - ccflags_section = content[start:end] - - # Add -flto=auto before the closing bracket - new_ccflags = ccflags_section.replace('],', ',\n "-flto=auto"\n ],') - content = content[:start] + new_ccflags + content[end:] + # Add -flto=auto to CCFLAGS right after the opening bracket + if 'CCFLAGS=[' in content: + ccflags_start = content.find('CCFLAGS=[') + ccflags_section_start = ccflags_start + len('CCFLAGS=[') + content = (content[:ccflags_section_start] + + '\n "-flto=auto",' + + content[ccflags_section_start:]) modified = True - # Pattern to find CFLAGS list and add -flto=auto if not present - if 'CFLAGS=[' in content and '"-flto' not in content[content.find('CFLAGS=['):content.find('],', content.find('CFLAGS=['))]: - start = content.find('CFLAGS=[') - end = content.find('],', start) + 1 - cflags_section = content[start:end] - - new_cflags = cflags_section.replace('],', ',\n "-flto=auto"\n ],') - content = content[:start] + new_cflags + content[end:] + # Add -flto=auto to CFLAGS right after the opening bracket + if 'CFLAGS=[' in content: + cflags_start = content.find('CFLAGS=[') + cflags_section_start = cflags_start + len('CFLAGS=[') + content = (content[:cflags_section_start] + + '\n "-flto=auto",' + + content[cflags_section_start:]) modified = True - # Pattern to find CXXFLAGS list and add -flto=auto if not present - if 'CXXFLAGS=[' in content and '"-flto' not in content[content.find('CXXFLAGS=['):content.find('],', content.find('CXXFLAGS=['))]: - start = content.find('CXXFLAGS=[') - end = content.find('],', start) + 1 - cxxflags_section = content[start:end] - - new_cxxflags = cxxflags_section.replace('],', ',\n "-flto=auto"\n ],') - content = content[:start] + new_cxxflags + content[end:] + # Add -flto=auto to CXXFLAGS right after the opening bracket + if 'CXXFLAGS=[' in content: + cxxflags_start = content.find('CXXFLAGS=[') + cxxflags_section_start = cxxflags_start + len('CXXFLAGS=[') + content = (content[:cxxflags_section_start] + + '\n "-flto=auto",' + + content[cxxflags_section_start:]) modified = True - # Pattern to find LINKFLAGS list and add -flto if not present - # Note: remove_no_lto_flags() needs to be called before + # Add -flto to LINKFLAGS right after the opening bracket if 'LINKFLAGS=[' in content: - start = content.find('LINKFLAGS=[') - # Find the end of LINKFLAGS - look for the matching bracket - bracket_count = 0 - pos = start + len('LINKFLAGS=[') - 1 - while pos < len(content): - if content[pos] == '[': - bracket_count += 1 - elif content[pos] == ']': - bracket_count -= 1 - if bracket_count == 0: - end = pos + 1 - break - pos += 1 - - linkflags_section = content[start:end] - - # Check if -flto is already present - if '"-flto"' not in linkflags_section: - # Add -flto before the closing bracket - new_linkflags = linkflags_section.rstrip() - if new_linkflags.endswith(','): - new_linkflags = new_linkflags + '\n "-flto"' - else: - new_linkflags = new_linkflags[:-1] + ',\n "-flto"\n ]' - - content = content[:start] + new_linkflags + content[end:] - modified = True + linkflags_start = content.find('LINKFLAGS=[') + linkflags_section_start = linkflags_start + len('LINKFLAGS=[') + content = (content[:linkflags_section_start] + + '\n "-flto",' + + content[linkflags_section_start:]) + modified = True if modified: with open(build_py_path, 'w', encoding='utf-8') as f: From 10f426050e8f3d348b97c76461ca19f8a4b6bdc4 Mon Sep 17 00:00:00 2001 From: Jason2866 Date: Fri, 14 Nov 2025 13:20:30 +0100 Subject: [PATCH 06/10] clean up --- builder/frameworks/component_manager.py | 52 +++++++++++-------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/builder/frameworks/component_manager.py b/builder/frameworks/component_manager.py index e7fec1acd..0749c9b56 100644 --- a/builder/frameworks/component_manager.py +++ b/builder/frameworks/component_manager.py @@ -1275,37 +1275,36 @@ def print_changes_summary(self) -> None: def remove_no_lto_flags(self) -> bool: """ Remove all -fno-lto flags from pioarduino-build.py. - + Removes all occurrences of -fno-lto from CCFLAGS, CFLAGS, CXXFLAGS, and LINKFLAGS in the Arduino build script. - + Returns: bool: True if successful, False otherwise """ build_py_path = str(Path(self.config.arduino_libs_mcu) / "pioarduino-build.py") - + if not os.path.exists(build_py_path): print(f"Warning: pioarduino-build.py not found at {build_py_path}") return False - + try: with open(build_py_path, 'r', encoding='utf-8') as f: content = f.read() - + # Remove all -fno-lto flags modified_content = re.sub(r'["\']?-fno-lto["\']?,?\s*', '', content) - + # Clean up any resulting empty strings or double commas modified_content = re.sub(r',\s*,', ',', modified_content) modified_content = re.sub(r'\[\s*,', '[', modified_content) modified_content = re.sub(r',\s*\]', ']', modified_content) - + with open(build_py_path, 'w', encoding='utf-8') as f: f.write(modified_content) - - print("*** Removed -fno-lto flags from pioarduino-build.py ***") + return True - + except (IOError, OSError) as e: print(f"Error removing -fno-lto flags: {e}") return False @@ -1313,26 +1312,26 @@ def remove_no_lto_flags(self) -> bool: def add_lto_flags(self) -> bool: """ Add LTO flags to pioarduino-build.py. - + Adds -flto=auto to CCFLAGS, CFLAGS, CXXFLAGS and -flto to LINKFLAGS in the Arduino build script. Flags are inserted right after the opening bracket. - + Returns: bool: True if successful, False otherwise """ build_py_path = str(Path(self.config.arduino_libs_mcu) / "pioarduino-build.py") - + if not os.path.exists(build_py_path): print(f"Warning: pioarduino-build.py not found at {build_py_path}") return False - + try: with open(build_py_path, 'r', encoding='utf-8') as f: content = f.read() - + original_content = content modified = False - + # Add -flto=auto to CCFLAGS right after the opening bracket if 'CCFLAGS=[' in content: ccflags_start = content.find('CCFLAGS=[') @@ -1341,7 +1340,7 @@ def add_lto_flags(self) -> bool: '\n "-flto=auto",' + content[ccflags_section_start:]) modified = True - + # Add -flto=auto to CFLAGS right after the opening bracket if 'CFLAGS=[' in content: cflags_start = content.find('CFLAGS=[') @@ -1350,7 +1349,7 @@ def add_lto_flags(self) -> bool: '\n "-flto=auto",' + content[cflags_section_start:]) modified = True - + # Add -flto=auto to CXXFLAGS right after the opening bracket if 'CXXFLAGS=[' in content: cxxflags_start = content.find('CXXFLAGS=[') @@ -1359,7 +1358,7 @@ def add_lto_flags(self) -> bool: '\n "-flto=auto",' + content[cxxflags_section_start:]) modified = True - + # Add -flto to LINKFLAGS right after the opening bracket if 'LINKFLAGS=[' in content: linkflags_start = content.find('LINKFLAGS=[') @@ -1368,21 +1367,14 @@ def add_lto_flags(self) -> bool: '\n "-flto",' + content[linkflags_section_start:]) modified = True - + if modified: with open(build_py_path, 'w', encoding='utf-8') as f: f.write(content) - - print("*** Added LTO flags to pioarduino-build.py ***") - print(" CCFLAGS: -flto=auto") - print(" CFLAGS: -flto=auto") - print(" CXXFLAGS: -flto=auto") - print(" LINKFLAGS: -flto") - return True - else: - print("*** LTO flags already present in pioarduino-build.py ***") + + print("*** Added LTO flags for Arduino compile ***") return True - + except (IOError, OSError) as e: print(f"Error adding LTO flags: {e}") return False From 59150e7fc494560980bdb5013288b35f173afc2f Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 14 Nov 2025 15:06:11 +0100 Subject: [PATCH 07/10] Simplify LTO management in Arduino build process Removed LTO management for BUILD_FLAGS and related checks. --- builder/frameworks/arduino.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index cc89f1fdd..724eaa426 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -599,22 +599,11 @@ def has_psram_config(): if has_unicore_flags(): build_unflags += " -ustart_app_other_cores" + if '-fno-lto' in build_unflags: + flag_lto = True + new_build_unflags = build_unflags.split() env.Replace(BUILD_UNFLAGS=new_build_unflags) - - if not env.get('BUILD_FLAGS'): # Initialize if not set - env['BUILD_FLAGS'] = [] - # Check if BUILD_FLAGS contains -flto=auto - build_flags = env.get('BUILD_FLAGS', []) - if isinstance(build_flags, str): - build_flags = build_flags.split() - - if '-flto=auto' in build_flags: - # Remove -flto=auto from BUILD_FLAGS - build_flags = [flag for flag in build_flags if flag != '-flto=auto'] - env.Replace(BUILD_FLAGS=build_flags) - flag_lto = True - print("*** Detected -flto=auto in BUILD_FLAGS, will apply LTO management ***") def get_MD5_hash(phrase): From 9bc893affdec218558b0a9f3387d4914ba60da22 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 14 Nov 2025 15:48:37 +0100 Subject: [PATCH 08/10] Remove unused variable 'original_content' --- builder/frameworks/component_manager.py | 1 - 1 file changed, 1 deletion(-) diff --git a/builder/frameworks/component_manager.py b/builder/frameworks/component_manager.py index 0749c9b56..c73a6e18c 100644 --- a/builder/frameworks/component_manager.py +++ b/builder/frameworks/component_manager.py @@ -1329,7 +1329,6 @@ def add_lto_flags(self) -> bool: with open(build_py_path, 'r', encoding='utf-8') as f: content = f.read() - original_content = content modified = False # Add -flto=auto to CCFLAGS right after the opening bracket From 4872fa24fd9472a2b0360e5257d73eb69984f7fc Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 14 Nov 2025 15:52:37 +0100 Subject: [PATCH 09/10] add comment for LTO enable with HybridCompile Add check for enabling LTO in Arduino build process. --- builder/frameworks/arduino.py | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index 724eaa426..3eb65ccfa 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -599,6 +599,7 @@ def has_psram_config(): if has_unicore_flags(): build_unflags += " -ustart_app_other_cores" + # Check for enabling LTO for Arduino HybridCompile part by unflagging -fno-lto if '-fno-lto' in build_unflags: flag_lto = True From dad332c12b4ea428693228beb2458c74ba1c20f5 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Fri, 14 Nov 2025 16:32:05 +0100 Subject: [PATCH 10/10] Enable LTO for example Tasmota --- examples/tasmota_platformio_override.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/tasmota_platformio_override.ini b/examples/tasmota_platformio_override.ini index 4ba00f20b..af8b88c5d 100644 --- a/examples/tasmota_platformio_override.ini +++ b/examples/tasmota_platformio_override.ini @@ -10,6 +10,7 @@ board = esp32 build_flags = ${env:tasmota32_base.build_flags} -DHTTPCLIENT_NOSECURE -DUPDATE_NOCRYPT +build_unflags = -fno-lto lib_ignore = ${env:tasmota32_base.lib_ignore} Micro-RTSP epdiy