Skip to content

Track header files in CMake targets for build impact analysis #16922

@pratikpugalia

Description

@pratikpugalia

Description

Motivation

Build Impact Analysis

Today, there is no reliable way to answer: "If I change Foo.h, which CMake targets need to rebuild?"

CMake's File API (codemodel-v2) reports source files associated with each target. However, headers
added via install(FILES ...) or glob-based helpers are invisible to the File API — they exist on disk but have no target association in the build graph.

By using FILE_SET HEADERS (CMake 3.23+), every header becomes a first-class source of its target, queryable through the File API.

Selective Builds

With accurate header-to-target mapping, we can build selective build tooling:

  1. A PR modifies velox/core/PlanNode.h
  2. Query the File API → PlanNode.h belongs to target velox_core
  3. Build and test only velox_core and its dependents, instead of the entire project

This significantly reduces CI time for targeted changes.

Approach

  1. HEADERS keyword in velox_add_library() — production targets declare their headers explicitly, wired to FILE_SET HEADERS internally.

  2. velox_add_test_headers() — lightweight helper for test/benchmark/fuzzer targets using raw add_library()/add_executable().

  3. CI enforcement — a check-header-ownership pre-commit hook verifies every .h file under velox/ is referenced in a CMakeLists.txt. New headers without ownership fail CI.

  4. CompatibilityVELOX_MONO_LIBRARY mode fully supported. Existing velox_install_library_headers() kept as fallback. No changes to build output or installed artifacts.

Scope

  • ~1,287 headers tracked across ~150 CMakeLists.txt files
  • ~65 new INTERFACE targets mirroring BUCK's header-only structure

Future Work

  • Build selective build tooling consuming the File API data

Related PR: #16897

cc @kgpai @czentgr @majetideepak

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions