Github actions and C++ precompiled headers #183481
Replies: 6 comments
-
|
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
-
|
Yes, precompiled headers (PCH) can work with GitHub Actions caching, but it depends on how stable your build environment is. If the compiler version, flags, or dependencies change, the cached PCH may become invalid and force a rebuild. A common approach is to include the compiler version and build configuration in the cache key. For example:
This helps ensure the cache is only restored when the environment is compatible. However, because PCH files are sensitive to small changes, many projects still end up rebuilding them frequently. In some cases using tools like ccache or sccache with GitHub Actions can give more reliable build speed improvements than caching PCH d |
Beta Was this translation helpful? Give feedback.
-
|
Yes, this is possible, but you have to be careful with how the cache is handled. In CI environments like GitHub Actions, precompiled headers (PCH) can technically be cached using the That means things like:
must all remain the same. If any of those change, the cached PCH becomes invalid and the compiler will rebuild it anyway. A common approach is to include the compiler version and build configuration in the cache key. For example: - uses: actions/cache@v4
with:
path: build/pch
key: pch-${{ runner.os }}-${{ hashFiles('**/*.h') }}-${{ env.COMPILER_VERSION }}This way the cache is reused when nothing relevant changes, but automatically invalidated when the environment changes. In practice this can significantly reduce build time for large C++ projects, but it only works reliably when the build environment is deterministic. |
Beta Was this translation helpful? Give feedback.
-
|
Precompiled headers can be tricky to cache in GitHub Actions because most compilers treat them as very environment-specific build artifacts. A PCH usually depends on the exact compiler version, flags, include paths, and sometimes timestamps. If any of those differ between runs, the compiler will invalidate the PCH and rebuild it. Because of that, caching PCH files with "actions/cache" often doesn’t give reliable results. Even if the cache restores correctly, the build system may still decide to regenerate the PCH. A safer approach is to:
Another option is using a compiler cache like ccache or sccache in GitHub Actions, which is usually more effective for reducing compilation time than trying to cache PCH files directly. |
Beta Was this translation helpful? Give feedback.
-
|
Yeah… caching precompiled headers in CI environments like GitHub Actions can be really frustrating. Even when everything seems correct, small differences in compiler flags or environment settings end up invalidating the cache. I tried a similar setup before and it felt like the cache would restore successfully but the build system still regenerated the PCH anyway. It kind of defeats the whole purpose of trying to speed things up. In the end I also found that using something like |
Beta Was this translation helpful? Give feedback.
-
|
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Why are you starting this discussion?
Question
What GitHub Actions topic or product is this about?
Actions Cache
Discussion Details
Anybody have any idea if precompiled headers play nicely with github-actions?
My project is becoming quite large so I started precompiling STL headers.
And I am now wondering if precompiled headers can be cached and or restored without causing a rebuild?
As I want to save time recompiling STL, library headers and or project headers that dont change often.
But it seems the only way might be to touch update my pch headers? (which seems dangerous and hacky)
Similar issue:
actions/checkout#364
Git on filetime modifications.
https://archive.kernel.org/oldwiki/git.wiki.kernel.org/index.php/Git_FAQ.html#Why_isn.27t_Git_preserving_modification_time_on_files.3F
Running build:
https://github.com/soerlemans/crowlang/actions/runs/20696612853/job/59412823406?pr=72
My workflow file:
https://github.com/soerlemans/crowlang/blob/feature/pointers/.github/workflows/unit-tests.yml
Beta Was this translation helpful? Give feedback.
All reactions