Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared precompiled header #4350

Open
etermaw opened this issue Oct 8, 2018 · 6 comments
Open

Shared precompiled header #4350

etermaw opened this issue Oct 8, 2018 · 6 comments

Comments

@etermaw
Copy link

etermaw commented Oct 8, 2018

I have C++ project organized as few libraries. All of them use the same precompiled header. Currently meson precompiles this header for each invocation of library() call. Is there any way to precompile this header only once, and after that just share it among all library() calls?

@jpakkane
Copy link
Member

jpakkane commented Oct 8, 2018

That is not supported ATM. The problem is that if any compiler flag changes, the PCH file is no longer guaranteed to be valid.

@nioncode
Copy link
Contributor

nioncode commented Jan 1, 2019

Also, this will be backend dependent. I don't think you can easily re-use a precompiled header across multiple VS projects in a solution, but I'll gladly review a PR implementing this.

@TheHillBright
Copy link
Contributor

pch as a build target can be valuable since for compilers like clang that support chained pch, meson is better to support something like:

clang++ -x c++-header header1.h -o header1.h.pch
clang++ -x c++-header header2.h -o header2.h.pch -include-pch header1.h.pch

Where header2.h includes header1.h .
In case where multiple subprojects have commonly shared headers, the shared part can be in header1 and the rest to header2 and huge build time can potentially be saved.

True that pch outputs are sensitive to compiler flags. When having pch as a build target, it should be very easy for meson to figure this out as configuration error - so this should not be an issue with meson design.

@lf-
Copy link
Contributor

lf- commented May 30, 2024

This affects us in Lix, since we have a lot of libraries and we have little reason to not simply use the same PCH across all our libraries. It looks like we would save about 40 cpu-seconds by this being fixed, which is about 5% of our current build time. We could get more build-time savings by doing any other optimization, so this is not a huge priority for us but it would be nice.

@eli-schwartz
Copy link
Member

Probably it would be possible in the backend to take a list of all pch files and figure out which ones are called with the same flags, then merge rules.

Anyone want to look into implementing this?

@ammen99
Copy link

ammen99 commented Aug 27, 2024

@eli-schwartz Recent experiments in one of my projects (which involves many plugins which are separate .so files, but have the exact same flags for compilation) show that this could save up to 20% of compile-times so I am interested in looking into this, I have some experience with Python but unfortunately never looked into meson's codebase. Do you have some hints as to what has to happen broadly / which parts of the code I should look and hook into for this to be made possible?

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

No branches or pull requests

7 participants