Skip to content

Commit eb59fb6

Browse files
committed
Have a default PCH for framework / infrastructure headers
1 parent 5b4bf8c commit eb59fb6

3 files changed

Lines changed: 62 additions & 2 deletions

File tree

Common/Core/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,36 @@ o2physics_add_library(AnalysisCore
2424
FFitWeights.cxx
2525
PUBLIC_LINK_LIBRARIES O2::Framework O2::DataFormatsParameters ROOT::EG O2::CCDB ROOT::Physics O2::FT0Base O2::FV0Base O2::DataFormatsParamTOF)
2626

27+
# Precompiled header shared by DPL analysis workflows. Parsing the framework
28+
# headers dominates the cost of a workflow translation unit, and there are
29+
# ~1500 of them; o2physics_add_dpl_workflow reuses this by default.
30+
#
31+
# Skipped under recc, which caches compilations remotely instead -- the two do
32+
# not combine, as a PCH is a local artefact of one compiler invocation.
33+
#
34+
# The link libraries have to match what the reusing targets compile with, so
35+
# this carries only what every workflow already links.
36+
add_library(AnalysisPCH OBJECT analysisPCH.cxx)
37+
target_link_libraries(AnalysisPCH PUBLIC O2::Framework O2Physics::AnalysisCore)
38+
if(NOT DEFINED ENV{USE_RECC})
39+
target_precompile_headers(AnalysisPCH PRIVATE
40+
<Framework/ASoA.h>
41+
<Framework/AnalysisTask.h>
42+
<Framework/ConfigContext.h>
43+
<Framework/DataProcessorSpec.h>
44+
# NOT runDataProcessing.h. It states the contract itself: "we need to
45+
# declare the customize method before include this file". Precompiling it
46+
# makes it the first include in every workflow, so a source's customize() is
47+
# never seen, its options are never registered, and the binary aborts at
48+
# --dump-workflow with "missing option: ...". The link succeeds, so this
49+
# surfaces as a runtime failure with no hint that a PCH caused it.
50+
51+
<memory>
52+
<string>
53+
<vector>
54+
)
55+
endif()
56+
2757
o2physics_target_root_dictionary(AnalysisCore
2858
HEADERS TrackSelection.h
2959
TrackSelectionDefaults.h

Common/Core/analysisPCH.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
// Carrier for the precompiled header shared by DPL analysis workflows; see
13+
// AnalysisPCH in this directory's CMakeLists.txt. It exists only to own the
14+
// PCH, so it has no code of its own.

cmake/O2PhysicsAddWorkflow.cmake

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,24 @@ function(o2physics_add_dpl_workflow baseTargetName)
4747
set_property(TARGET ${targetExeName} PROPERTY JOB_POOL_COMPILE analysis)
4848
set_property(TARGET ${targetExeName} PROPERTY JOB_POOL_LINK analysis)
4949

50-
if(A_REUSE_FROM AND NOT DEFINED ENV{USE_RECC})
51-
target_precompile_headers(${targetExeName} REUSE_FROM ${A_REUSE_FROM})
50+
# Reuse a precompiled header. Without an explicit REUSE_FROM, fall back to the
51+
# shared AnalysisPCH (Common/Core): a workflow translation unit spends most of
52+
# its time parsing the framework headers, and there are ~1500 of them, so the
53+
# default is worth more than the handful of targets that name their own.
54+
#
55+
# Set O2PHYSICS_DEFAULT_PCH to an empty string to opt out globally, e.g. when
56+
# bisecting a PCH-related build failure.
57+
if(NOT DEFINED O2PHYSICS_DEFAULT_PCH)
58+
set(O2PHYSICS_DEFAULT_PCH AnalysisPCH)
59+
endif()
60+
set(_pch "${A_REUSE_FROM}")
61+
if(NOT _pch)
62+
set(_pch "${O2PHYSICS_DEFAULT_PCH}")
63+
endif()
64+
# A target cannot reuse its own PCH, and the carrier is not built when recc
65+
# is caching compilations remotely instead.
66+
if(_pch AND NOT _pch STREQUAL targetExeName AND NOT DEFINED ENV{USE_RECC})
67+
target_precompile_headers(${targetExeName} REUSE_FROM ${_pch})
5268
endif()
5369

5470
set(jsonFile $<TARGET_FILE_BASE_NAME:${targetExeName}>.json)

0 commit comments

Comments
 (0)