New WidgetRegistry - Only include non disabled widgets in the compiled binary #319

Open
dreed47 wants to merge 4 commits from dreed47/compile-optimizations into dev
dreed47 commented 2025-04-05 14:41:02 +00:00 (Migrated from github.com)

Current Issue:
As we add more widgets, our compiled binary grows because every widget is included in the compilation, even disabled ones.

Solution:
This change moves widget registration out of main.cpp and into a dedicated file (WidgetRegistry.cpp). Now:

  • Only enabled widgets are included in the build.
  • main.cpp is cleaner—it just needs to call registerWidgets(widgetSet, sm, config).

This change also adds a couple build flags to the platformio.ini to help reduce the final binary size by eliminating unused code and data. And also switches the platformio.ini to use extends.

How to Add a New Widget:

  1. Add your widget code to the repo.
  2. Register it in WidgetRegistry.cpp and config.system.h.

This makes the build more efficient and keeps the codebase better organized.

**Current Issue:** As we add more widgets, our compiled binary grows because every widget is included in the compilation, even disabled ones. **Solution:** This change moves widget registration out of `main.cpp` and into a dedicated file (`WidgetRegistry.cpp`). Now: - Only enabled widgets are included in the build. - `main.cpp` is cleaner—it just needs to call `registerWidgets(widgetSet, sm, config)`. This change also adds a couple build flags to the platformio.ini to help reduce the final binary size by eliminating unused code and data. And also switches the platformio.ini to use extends. **How to Add a New Widget:** 1. Add your widget code to the repo. 2. Register it in `WidgetRegistry.cpp` and `config.system.h`. This makes the build more efficient and keeps the codebase better organized.
flattermann commented 2025-04-05 22:56:54 +00:00 (Migrated from github.com)

Actually, disabled widgets should not increase the compiled size, because they will not be linked.
This will work, even if you #include them, i.e. you do not need to #if the #include (just the WidgetSet->add).

That being said, I'm fine with moving addWidgets() to a separate file as this will make the main.cpp cleaner.

Actually, disabled widgets should not increase the compiled size, because they will not be linked. This will work, even if you `#include` them, i.e. you do not need to `#if` the `#include` (just the WidgetSet->add). That being said, I'm fine with moving `addWidgets()` to a separate file as this will make the `main.cpp` cleaner.
dreed47 commented 2025-04-05 23:31:02 +00:00 (Migrated from github.com)

Actually, disabled widgets should not increase the compiled size, because they will not be linked. This will work, even if you #include them, i.e. you do not need to #if the #include (just the WidgetSet->add).

That being said, I'm fine with moving addWidgets() to a separate file as this will make the main.cpp cleaner.

I thought I saw a difference in the binary size between current and when I wrap the includes with '#if'. I don't have exact stats but i can check again later. But also, when i moved the widgets includes to '#if' I get compile errors because some libraries like TaskFactory and GlobalTime were no longer linked in so in dev they are getting linked in through their references in the widgets somehow. This change should make things more explicit.

> Actually, disabled widgets should not increase the compiled size, because they will not be linked. This will work, even if you `#include` them, i.e. you do not need to `#if` the `#include` (just the WidgetSet->add). > > That being said, I'm fine with moving `addWidgets()` to a separate file as this will make the `main.cpp` cleaner. I thought I saw a difference in the binary size between current and when I wrap the includes with '#if'. I don't have exact stats but i can check again later. But also, when i moved the widgets includes to '#if' I get compile errors because some libraries like TaskFactory and GlobalTime were no longer linked in so in dev they are getting linked in through their references in the widgets somehow. This change should make things more explicit.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin dreed47/compile-optimizations:dreed47/compile-optimizations
git switch dreed47/compile-optimizations

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch dev
git merge --no-ff dreed47/compile-optimizations
git switch dreed47/compile-optimizations
git rebase dev
git switch dev
git merge --ff-only dreed47/compile-optimizations
git switch dreed47/compile-optimizations
git rebase dev
git switch dev
git merge --no-ff dreed47/compile-optimizations
git switch dev
git merge --squash dreed47/compile-optimizations
git switch dev
git merge --ff-only dreed47/compile-optimizations
git switch dev
git merge dreed47/compile-optimizations
git push origin dev
Sign in to join this conversation.
No description provided.