Arduino core 3.3.5

This commit is contained in:
Jason2866
2025-12-19 16:03:25 +01:00
parent db09865583
commit 879780c5a9
22 changed files with 610 additions and 72 deletions
+109 -1
View File
@@ -45,6 +45,8 @@ class ComponentManagerConfig:
self.board = env.BoardConfig()
# Extract MCU type from board configuration, defaulting to esp32
self.mcu = self.board.get("build.mcu", "esp32").lower()
chip_variant = self.board.get("build.chip_variant", "").lower()
self.chip_variant = chip_variant if chip_variant else self.mcu
# Get project source directory path
self.project_src_dir = env.subst("$PROJECT_SRC_DIR")
@@ -74,7 +76,7 @@ class ComponentManagerConfig:
"""
if self._arduino_libs_mcu is None:
ald = self.platform.get_package_dir("framework-arduinoespressif32-libs")
self._arduino_libs_mcu = str(Path(ald) / self.mcu) if ald else ""
self._arduino_libs_mcu = str(Path(ald) / self.chip_variant) if ald else ""
return self._arduino_libs_mcu
@@ -1271,3 +1273,109 @@ class ComponentManager:
session, useful for build reporting and debugging.
"""
self.logger.print_changes_summary()
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)
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. 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()
modified = False
# 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
# 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
# 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
# Add -flto to LINKFLAGS right after the opening bracket
if 'LINKFLAGS=[' in content:
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:
f.write(content)
print("*** Added LTO flags for Arduino compile ***")
return True
except (IOError, OSError) as e:
print(f"Error adding LTO flags: {e}")
return False