Build the library as a single translation unit - #365
Merged
Merged
Conversation
Rename every implementation file to *.inl and include them from src/M5Unified.cpp. All of them pull in the same framework headers, so parsing those once instead of once per file cuts the library build time substantially; the Arduino build also pre-scans each source file for includes, which doubled that cost. Measured with the Arduino toolchain on Windows (CoreS3 sketch, sequential): compiling this library went from 71 s to 6 s, and the detection pass shrank by the same 35 files. File-local names that collided once they shared a scope: - led_count (LED_PaperMono / LED_PowerHub): moved into each class - bcd2ToByte / byteToBcd2 (three RTC drivers): moved to RTC_Base - I2S helpers and handle arrays in Speaker / Mic: renamed _spk_i2s_* / _mic_i2s_* (the two arrays are distinct on purpose, TX and RX channels of the same port) - i2c_freq and shared device addresses (M5Unified / Power / LED_PaperMono): moved to utility/m5unified_i2c_addr.hpp - IS_BIT_SET (AXP2101): undefined at the end of the file ESP-IDF: CMakeLists.txt lists the hub file instead of globbing *.cpp. The hub file carries the maintenance notes. Each *.inl checks for M5UNIFIED_IMPLEMENTATION, which the hub defines around its includes, and stops with a clear #error when included on its own.
ainyan03
force-pushed
the
unity_build
branch
from
September 15, 2026 00:21
18e0565 to
226266b
Compare
Merged
lovyan03
added a commit
that referenced
this pull request
Sep 21, 2026
Build the library as a single translation unit (cherry picked from commit 935b9e8)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Every implementation file pulls in the same set of framework headers, and the Arduino build pre-scans every source file for includes before compiling it, so that header parsing happened about 70 times per build. On Windows each pass costs around 3 s.
This PR builds the library as one translation unit: the
.cppfiles become.inland are included fromsrc/M5Unified.cpp.Measured with arduino-cli, CoreS3 sketch, sequential build:
(The detection pass shrinks by the same 35 files.)
What changed
src/**/*.cpp→*.inl, included from the new hubsrc/M5Unified.cpp(36 → 1 translation unit; the formerM5Unified.cppis nowM5Unified.inl). The hub file carries the maintenance notes.led_countinLED_PaperMono/LED_PowerHub: privatestatic constexprmember of each classbcd2ToByte/byteToBcd2, duplicated in three RTC drivers: protected static helpers ofRTC_BaseSpeaker_Class/Mic_Class:_spk_i2s_*/_mic_i2s_*(the two arrays are distinct on purpose: TX and RX channels of the same port)i2c_freqand the shared on-board device addresses:utility/m5unified_i2c_addr.hppIS_BIT_SET(AXP2101):#undefat the end of the fileCMakeLists.txtlists the hub instead of globbing*.cpp.*.inlchecks forM5UNIFIED_IMPLEMENTATION, which the hub defines around its includes, and stops with a clear#errorwhen included on its own (a direct include used to surface only as duplicate symbols at link time).Compatibility
src/**/*.cppwill now pick upM5Unified.cpponly, which is the intended set.Verification
develop; ESP-IDF 5.5 build; native SDL build.