Skip to content

Refactor: bundle ut/cpp shared sources into OBJECT libraries#726

Merged
ChaoWao merged 1 commit intohw-native-sys:mainfrom
ChaoWao:refactor/dedupe-ut-cpp-rebuilds
May 9, 2026
Merged

Refactor: bundle ut/cpp shared sources into OBJECT libraries#726
ChaoWao merged 1 commit intohw-native-sys:mainfrom
ChaoWao:refactor/dedupe-ut-cpp-rebuilds

Conversation

@ChaoWao
Copy link
Copy Markdown
Collaborator

@ChaoWao ChaoWao commented May 9, 2026

Summary

  • tests/ut/cpp/CMakeLists.txt listed the same runtime sources in every
    add_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 redundant Building CXX object
    lines per build.
  • Hoist the shared sources into two OBJECT libraries —
    hierarchical_objs and a2a3_rt_objs — that carry the include
    directories and -D_GLIBCXX_USE_CXX11_ABI=0 flag as PUBLIC. Each test
    executable links the OBJECT lib instead of relisting the sources.
  • Collapse the 10 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 ut job and the hw ut-a2a3 / ut-a5 jobs pick up
exactly the same set of tests as before.

Testing

  • cmake -B build -S tests/ut/cpp && cmake --build build -j on macOS
    (AppleClang) — clean build, every test target links.
  • Spot-checked test_tensormap (9/9 passed) and test_task_allocator
    (22/22 passed) — confirms the OBJECT libs link into runnable binaries.
  • Linux CI (ut, ut-a2a3, ut-a5) — relies on the same CMake
    tree; expect the redundant Building CXX object lines to disappear
    from the build log.

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.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/ut/cpp/CMakeLists.txt
Comment thread tests/ut/cpp/CMakeLists.txt
@ChaoWao ChaoWao merged commit d73142b into hw-native-sys:main May 9, 2026
14 checks passed
@ChaoWao ChaoWao deleted the refactor/dedupe-ut-cpp-rebuilds branch May 9, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant