Refactor: bundle ut/cpp shared sources into OBJECT libraries#726
Merged
ChaoWao merged 1 commit intohw-native-sys:mainfrom May 9, 2026
Merged
Conversation
Each test executable in tests/ut/cpp listed the same runtime sources in its add_executable() call, so the 9 hierarchical sources compiled 5x and the 5 a2a3 runtime sources compiled 10x on every clean build. Hoist them into two OBJECT libraries (hierarchical_objs, a2a3_rt_objs) that carry the include dirs and -D_GLIBCXX_USE_CXX11_ABI=0 as PUBLIC properties, and link each test against the OBJECT lib. Sources now compile exactly once; per-test executables, ctest labels, and the existing CI label filters (-L/-LE requires_hardware) are unchanged. Also collapses the 10 add_a2a3_runtime_test(... SOURCES ... EXTRA_SOURCES ...) call sites to plain (name src) one-liners.
There was a problem hiding this comment.
Code Review
This pull request refactors the CMake configuration for C++ unit tests by introducing OBJECT libraries for shared A2A3 and hierarchical runtime sources. This optimization ensures shared components are compiled once and reused across multiple test executables, improving build performance. The review feedback highlights that the simplified helper functions for adding tests now restrict the number of source files; it is recommended to use ${ARGN} to restore flexibility for tests requiring multiple source files or mocks.
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.
Summary
tests/ut/cpp/CMakeLists.txtlisted the same runtime sources in everyadd_executable(), so on every clean build the 9 hierarchical sources(
types.cpp,tensormap.cpp,ring.cpp,scope.cpp,orchestrator.cpp,worker_manager.cpp,scheduler.cpp,worker.cpp,chip_worker.cpp)recompiled 5x and the 5 a2a3 runtime sources (
pto_ring_buffer.cpp,pto_shared_memory.cpp,pto_scheduler.cpp,pto_tensormap.cpp,test_stubs.cpp) recompiled 10x — about 41 redundantBuilding CXX objectlines per build.
OBJECTlibraries —hierarchical_objsanda2a3_rt_objs— that carry the includedirectories and
-D_GLIBCXX_USE_CXX11_ABI=0flag asPUBLIC. Each testexecutable links the OBJECT lib instead of relisting the sources.
add_a2a3_runtime_test(... SOURCES ... EXTRA_SOURCES ${A2A3_RUNTIME_SOURCES})call sites to plain
(name src)one-liners.Per-test executables, ctest labels (
no_hardware,requires_hardware_a2a3),and the CI label filters (
-L/-LE requires_hardware) are all unchanged,so both the no-hw
utjob and the hwut-a2a3/ut-a5jobs pick upexactly the same set of tests as before.
Testing
cmake -B build -S tests/ut/cpp && cmake --build build -jon macOS(AppleClang) — clean build, every test target links.
test_tensormap(9/9 passed) andtest_task_allocator(22/22 passed) — confirms the OBJECT libs link into runnable binaries.
ut,ut-a2a3,ut-a5) — relies on the same CMaketree; expect the redundant
Building CXX objectlines to disappearfrom the build log.