Make public headers self-contained and stop relying on PCH - #40
Conversation
Every public header now compiles on its own, and every source states its own dependencies rather than inheriting them (implicit) from StdAfx.h. Additionally, extend the CI to check if compiling without PCH still works. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2415707 to
16df0e4
Compare
|
Hi, as you mentioned, this is more of a discussion. 😄 In general, pre-compiled headers are here to stay, and we are not going to move away from them. I wonder if the way CMake does PCH masks any such missing include issues because it force includes the precompiled header via the compiler's command-line (e.g. no more requirement for `#include "stdafx.h" in the .cpp file). However, testing this through a CMake build option is probably not a good way to go about it. Every build option for this kind of balloons the build matrix, which is already quite large and something we want to reduce in the mid to long term. |
|
Yeah, so currently PCH does mask. Two alternatives that come to mind:
Edit: thinking some more, I could remove the CI part, then this PR would ensure public headers are self-contained at least. It adds a new cmake target for that which runs the headers without PCH. Would that be a good step? |
|
The clang-tidy path is something that would be very much welcomed. 👍 It's currently on the list to integrate it anyway (for example, to add the naming convention check according to our style guide), and that might be a good first step. |
Summary
Initially I wanted to make an issue first, to talk this over. But code speaks louder than any words, so I ended up making this PR instead. But this PR is much more a "do you want to go in this direction?" question that should have been asked in an issue.
Sorry :(
When compiling this (and many of the other carbon) repositories on Linux, you run into the issue that a bunch of include headers are missing. And this totally make sense, as these repositories use PCH with
<windows.h>. Which means on Windows, a ton of system headers are added without people realizing (aswindows.his a terrible header in this regard).Building on MacOS will tell about most: but not all. And this is because GCC has a different opinion about system headers than others do: it minimizes them as much as it can. Famously, since GCC 13 they removed the inclusion of
cstdintby their headers. To take this as example, it means:<windows.h>will transitively include this header.So we run into compiler-errors on Linux. Fixing this can be done in several ways, but it also highlights a bigger problem: something that works on one platform, fails on another. And those can be annoying to deal with after-the-fact.
While delving into this further, I noticed a bit of a more tricky problem to deal with:
No file in the "include" folder includes
StdAfx.h, but some do depend on its context via PCH. This means there is a knock-on effect through all repositories that depend oncore: they all need a PCH to at least cover the include files in the PCH ofcore. And that can be unexpected.So this PR sets out to fix these issues:
Additionally, I let Claude write some code for the CI, so it covers that non-PCH keeps on building. Just to prevent regression on this front.
After this PR you end up with public-headers that don't implicitly need a PCH to contain some includes. In other words: this fixes that silently the
StdAfx.hleaked into the public headers, althoughStdAfx.hitself wasn't made public. This also means that after this PR PCH becomes a compile-performance optimization again, and not a dependency of its own.That all said and done, the actual requirement to build on Linux is a much smaller change: https://github.com/carbonengine/core/compare/main...TrueBrain:carbonengine-core:push-xkzzrvtkskxx?expand=1. I am also fine if that is the route to take.
PS: of course if this PR is accepted, I can do the same work on other repositories that have the same issue. About 50% of them currently fail on missing headers, in different degrees.
PPS: the no-PCH build most likely fails on MacOS till #41 lands.
AI assistance disclosure
Claude wrote the code; I instructed what I wanted to achieve. Verified it is matching up with my expectations.
Type of change
Linked issue (optional)
What changed
Testing
Platforms tested
Screenshots / captures
Checklist
Full disclosure: I am employed by Fenris Creations, although I have no involvement with the Carbon project. I work on this in my free time under my own name.