Skip to content

[CMake] rewrite precompiled header usage - #2222

Draft
tdavidcl wants to merge 10 commits into
Shamrock-code:mainfrom
tdavidcl:claude/build-profile-analysis-6lhutp
Draft

[CMake] rewrite precompiled header usage#2222
tdavidcl wants to merge 10 commits into
Shamrock-code:mainfrom
tdavidcl:claude/build-profile-analysis-6lhutp

Conversation

@tdavidcl

Copy link
Copy Markdown
Member

No description provided.

…ries

SHAMROCK_USE_PCH existed but only wired shamrock_exe/shamrock_pylib/
shamrock_test to `REUSE_FROM shamrock_lib`, a target that does not exist yet
(src/shamrock/CMakeLists.txt still has a TODO to rename shamlib to
shamrock_lib), so enabling the option did nothing for the 20 actual
compiled libraries, including the ones that dominate build time per the
build-profile report (shammodels_sph, shammodels_gsph, shamalgs, shamtree,
shamlib).

Add cmake/ShamrockPCH.cmake with sham_pch_root()/sham_pch_reuse() helpers:
shambackends precompiles the small set of headers that get re-parsed in
nearly every translation unit (sycl.hpp, DeviceBuffer.hpp, nlohmann/json.hpp),
and every library that depends on it directly or transitively reuses that
same precompiled object instead of re-parsing the headers itself. Still
off by default.

Assisted-by: Claude Code
… env

This is the machine config CI's build-profile job (and most other
acpp-clang CI jobs) uses, so this gets the now-fixed PCH plumbing exercised
by CI to see its actual effect, without changing the SHAMROCK_USE_PCH
default (still Off) for any other machine config.

Assisted-by: Claude Code
@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks @tdavidcl for opening this PR!

You can do multiple things directly here:
1 - Comment pre-commit.ci run to run pre-commit checks.
2 - Comment pre-commit.ci autofix to apply fixes.
3 - Add label autofix.ci to fix authorship & pre-commit for every commit made.
4 - Add label full-ci to run the full test suite (default is light CI; full CI also runs on Mergify merge-queue branches).
5 - Add label profile-build to run the compile-time build profile job even in light CI.
6 - Add label trigger-ci to create an empty commit to trigger the CI.

Once the workflow completes a message will appear displaying informations related to the run.

Also the PR gets automatically reviewed by gemini, you can:
1 - Comment /gemini review to trigger a review
2 - Comment /gemini summary for a summary
3 - Tag it using @gemini-code-assist either in the PR or in review comments on files

CI hit "error: is pie differs in PCH file vs. current file" repeatedly
in shamrock_test: shambackends (the PCH-owning target) is a shared
library and gets -fPIC from CMake automatically, but the plain
executable targets (shamrock_exe, shamrock_test) got no such override
and fell back to -fPIE, which Clang's PCH validator rejects as a
mismatch.

Force -fPIC uniformly via CMAKE_CXX_FLAGS whenever SHAMROCK_USE_PCH is
on, mirroring the existing object-lib-mode workaround for the same
class of problem. Verified locally: main.cpp, main_test.cpp and a real
test file (tests/shammath/AABB_tests.cpp) all now compile cleanly
against the reused shambackends PCH.

Assisted-by: Claude Code
Precompiling shambackends/sycl.hpp standalone (-x c++-header) skips
AdaptiveCpp's normal per-TU multipass compilation for the cuda/hip
backends, so compiler-injected builtins the generic hiplike kernel
launcher relies on (__acpp_warp_size, the kernel launch macros) end up
undeclared when generating the PCH:

  error: use of undeclared identifier '__acpp_warp_size'
  error: use of undeclared identifier 'decomposition'

Scope the PCH to the CPU-only backends (omp*, generic) where it works;
env_tests.yml's cuda.integrated-multipass/cuda.explicit-multipass
matrix entries build this same debian-generic.acpp machine config.

Assisted-by: Claude Code
github-actions Bot and others added 3 commits August 29, 2026 15:03
pybind11_add_module forces CXX_VISIBILITY_PRESET=hidden (and, when
supported, -flto) specifically on the module target it creates, neither
of which shambackends' PCH was built with:

  error: default visibility for functions and variables [-fvisibility]
  differs in PCH file vs. current file

shamrock_exe (a plain executable, unaffected by those pybind11-module-only
properties) still reuses the PCH.

Assisted-by: Claude Code
The clang-tidy CI job only configures and generates version.cpp, it never
runs a full ninja build, so shambackends' cmake_pch.hxx.pch is never
actually built. Every compile command clang-tidy inherited from
compile_commands.json still asked for it via
"-Xclang -include-pch -Xclang <path>.pch", which clang-tidy then reports
as a hard error:

  error: PCH file '.../cmake_pch.hxx.pch' not found: module file not found
  error: unable to read PCH file ...: 'No such file or directory'

Drop that pair (and -Winvalid-pch, now pointless) in
make_clang_tidy_db.py; the plain "-Xclang -include -Xclang <path>.hxx"
stays, so clang-tidy still sees the same header content, just parsed
normally instead of via the (missing) precompiled form. Verified locally:
clang-tidy now runs clean on a file that previously hit this error.

Assisted-by: Claude Code
@codecov

codecov Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Workflow report

workflow report corresponding to commit 855e60a
Commiter email is 41898282+github-actions[bot]@users.noreply.github.com
You are using github private e-mail. This prevent proper tracing of who contributed what, please disable it (see Keep my email addresses private).

Pre-commit check report

Pre-commit check: ✅

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check for merge conflicts................................................Passed
check that executables have shebangs.....................................Passed
check that scripts with shebangs are executable..........................Passed
check for added large files..............................................Passed
check for case conflicts.................................................Passed
check for broken symlinks................................................Passed
check yaml...............................................................Passed
detect private key.......................................................Passed
No-tabs checker..........................................................Passed
Tabs remover.............................................................Passed
cmake-format.............................................................Passed
Validate GitHub Workflows................................................Passed
clang-format.............................................................Passed
ruff check...............................................................Passed
ruff format..............................................................Passed
Check doxygen headers....................................................Passed
Check license headers....................................................Passed
Check #pragma once.......................................................Passed
Check SYCL #include......................................................Passed
No ssh in git submodules remote..........................................Passed
No UTF-8 in files (except for authors)...................................Passed

Test pipeline can run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant