[PROJ] "Unity" builds

Even Rouault even.rouault at spatialys.com
Mon Nov 27 08:03:46 PST 2023


Hi,

Few days ago I've proposed in https://github.com/OSGeo/PROJ/pull/3962 to 
add the capability to enable "unity" / "jumbo" builds (for the core 
library), through CMake's -DCMAKE_UNITY_BUILD=ON.

Basically CMake concatenates a few .cpp file until it generates a 
translation unit that is big enough but not too big. That can result in 
twice faster builds (at least for libproj, excluding tests or proj.db 
generation). But as code is not always ready to be concatenated with 
other files, I had to do quite a lot of changes for that (like making 
sure to #undef stuff at end of .cpp files, or that structures in 
anonymous namespaces or static functions have unique names), which by 
themselves should be harmless (and also makes it easier to debug, as 
instead of having >10 static setup() functions, they have a distinct 
name now) when doing regular builds.

But as discussed in the PR this feature isn't entirely riskless when 
enabled, so this capability is not enabled by default and there will be 
a note in the doc about that (cf my last comment in the PR).

That said, in some cases unity builds might be useful to uncover latent 
bugs (I've for example spotted that way a latent bug in GDAL where a 
file was relying on a undefined behaviour, and we were lucky compilers 
did compile it the way we intended it for regular builds), or identify 
some ODR (One Definition Rule) violations.

CI has a mix of non-unity and unity builds (most configs are already 
doing a shared and a static build. so typically one of them is done with 
a default build and the other one with a unity one)

Is there some agreement to merge that? (master only of course)

Even

-- 
http://www.spatialys.com
My software is free, but my time generally not.



More information about the PROJ mailing list