-
Notifications
You must be signed in to change notification settings - Fork 73
HybridCompile: add Option to enable LTO for Arduino part #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Removed LTO management for BUILD_FLAGS and related checks.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes implement Link-Time Optimization (LTO) flag management for HybridCompile Arduino builds. When Changes
Sequence DiagramsequenceDiagram
participant Arduino as arduino.py
participant CompMgr as ComponentManager
participant BuildScript as pioarduino-build.py
Arduino->>Arduino: Detect -fno-lto in BUILD_UNFLAGS
Arduino->>Arduino: Set flag_lto = True
rect rgb(240, 248, 255)
note right of Arduino: Lifecycle Point 1 & 2
Arduino->>CompMgr: remove_no_lto_flags()
CompMgr->>BuildScript: Read file
CompMgr->>BuildScript: Remove all -fno-lto occurrences
CompMgr->>BuildScript: Sanitize syntax (commas/brackets)
CompMgr->>BuildScript: Write back
CompMgr-->>Arduino: Return True/False
end
rect rgb(240, 255, 240)
Arduino->>CompMgr: add_lto_flags()
CompMgr->>BuildScript: Read file
CompMgr->>BuildScript: Insert -flto into CCFLAGS, CFLAGS, CXXFLAGS, LINKFLAGS
CompMgr->>BuildScript: Write back if modified
CompMgr->>CompMgr: Print notification
CompMgr-->>Arduino: Return True/False
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Areas requiring attention:
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (2)
builder/frameworks/component_manager.py (1)
1275-1310: Consider using the logger and adding validation.The method bypasses the class's logger instance and prints directly to stdout, which is inconsistent with other methods in ComponentManager (e.g.,
_cleanup_removed_components,_batch_remove_cpppath_entries). Additionally, no validation is performed on the modified content before writing it back.Consider these improvements:
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}") + self.logger.log_change(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) + # Basic validation + if not modified_content or len(modified_content) < len(content) * 0.5: + self.logger.log_change("Warning: Modified content looks suspicious, aborting") + return False + with open(build_py_path, 'w', encoding='utf-8') as f: f.write(modified_content) + self.logger.log_change("Removed -fno-lto flags from build script") return True except (IOError, OSError) as e: - print(f"Error removing -fno-lto flags: {e}") + self.logger.log_change(f"Error removing -fno-lto flags: {e}") return Falsebuilder/frameworks/arduino.py (1)
602-603: Consider adding a comment to clarify the counterintuitive logic.The logic where
-fno-ltoinbuild_unflagsenables LTO is counterintuitive. A brief comment would help future maintainers understand this design choice.+ # Check if user wants to enable LTO for Arduino part by unflagging -fno-lto if '-fno-lto' in build_unflags: flag_lto = True
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
builder/frameworks/arduino.py(3 hunks)builder/frameworks/component_manager.py(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: Jason2866
Repo: pioarduino/platform-espressif32 PR: 0
File: :0-0
Timestamp: 2025-09-23T12:35:35.508Z
Learning: For the pioarduino/platform-espressif32 project, Jason2866 has explicitly instructed to NEVER create issues or PRs outside of his repositories (pioarduino/*). All issue and PR creation must be strictly limited to his own repositories only, never in upstream or other repositories.
Learnt from: Jason2866
Repo: pioarduino/platform-espressif32 PR: 0
File: :0-0
Timestamp: 2025-09-23T12:35:35.508Z
Learning: For the pioarduino/platform-espressif32 project, Jason2866 has explicitly instructed to NEVER create issues or PRs outside of his repositories (pioarduino/*). All issue and PR creation must be strictly limited to his own repositories only, never in upstream or other repositories.
Learnt from: Jason2866
Repo: pioarduino/platform-espressif32 PR: 281
File: builder/frameworks/component_manager.py:1047-1054
Timestamp: 2025-09-04T15:27:18.112Z
Learning: In the pioarduino/platform-espressif32 project, Jason2866 prefers not to add guard checks for missing arduino_libs_mcu in backup operations, preferring to let the operation proceed rather than silently skip when the directory might be missing.
Learnt from: Jason2866
Repo: pioarduino/platform-espressif32 PR: 268
File: builder/penv_setup.py:87-96
Timestamp: 2025-08-26T14:52:29.044Z
Learning: For the pioarduino/platform-espressif32 project, Jason2866 prefers to trust system executables when falling back to PATH-based command resolution (like "uv"), rather than implementing additional validation checks for security concerns.
🪛 Ruff (0.14.4)
builder/frameworks/component_manager.py
1306-1306: Consider moving this statement to an else block
(TRY300)
1332-1332: Local variable original_content is assigned to but never used
Remove assignment to unused variable original_content
(F841)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: build (macos-15, examples/espidf-peripherals-usb)
- GitHub Check: build (macos-15, examples/espidf-coap-server)
- GitHub Check: build (macos-15, examples/espidf-blink)
- GitHub Check: build (macos-15, examples/tasmota)
- GitHub Check: build (macos-15, examples/espidf-arduino-blink)
- GitHub Check: build (windows-latest, examples/arduino-wifiscan)
- GitHub Check: build (windows-latest, examples/arduino-blink)
🔇 Additional comments (1)
builder/frameworks/arduino.py (1)
535-535: LGTM! Clean initialization of the LTO flag.The flag initialization is consistent with other flag patterns in the file.
Add check for enabling LTO in Arduino build process.
|
@Jason2866 : so to summarize, LTO becomes activated when LTO flag is removed ? 😆 |
|
@mathieucarbou LTO gets activated since the |
Description:
To enable LTO for the Arduino HybridCompile part add in
platformio.iniin theenv:Do not set anything regarding
LTOinbuild_flagsthis would enableLTOfor the espidf HybridCompile part of the Arduino Libs! The espidf framework does not compile successfully with enabledLTO@mathieucarbou fyi
Checklist:
Summary by CodeRabbit