Distribute GenGen as a static library #8367
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changes the distribution method of GenGen from distributing a
.cpp
file along with our sources to a static library that should be linked via--whole-archive
or equivalent.Why didn't we do this before?
Prior to CMake 3.24, there was no way to force a static library to be whole-archive linked. Now it's possible.
What benefit does it confer?
We don't have to compile GenGen.cpp so many times!
Why can't we do this with RunGenMain?
We know that GenGen will always be compiled for the same platform as libHalide; after all, it links to it. We can't say the same for RunGenMain, which might get baked into a cross compile.
This PR uncovered a race condition in the generator logic. Two generators in the same directory could try (via a
POST_BUILD
custom command) to placeHalide.dll
next to them on Windows. Although this originally used thecopy_if_different
option, the difference check seemed to holdHalide.dll
open and prevent a neighboring generator from launching. The solution was to use Powershell and a system mutex along with timestamp checking to ensure that eachHalide.dll
is only written to once during a build.