Repository navigation
fix: build precompiled headers after generated inputs - #360
Merged
Merged
Conversation
Object files get a target's dependencies, and its actions and rules outputs, as order-only prerequisites. The .gch built from a prefix header got neither, so a prefix header that reaches a generated header races code generation: make starts the .gch as soon as the prefix header itself exists, and a clean build fails on the missing generated header.
Move the make ordering into WritePchTargets, so all four gch rules get the target's dependencies and action/rule outputs as order-only prerequisites, not only those of languages that have objects, and set TOOLSET on them like on the objects. Give the ninja gch builds the objects' predepends too; they raced code generation the same way. The test now builds each gch on its own for a prefix header that includes a header generated by the target's action, and for one that includes a header generated by a dependency.
cmd_pch_c passed $(CXXFLAGS.$(TOOLSET)) while the C objects that include the gch are compiled with $(CFLAGS.$(TOOLSET)), so a C++-only flag such as -std=c++17 in CXXFLAGS broke the C gch, and other flag differences made it incompatible with the objects.
With GCC_PRECOMPILE_PREFIX_HEADER, assembly sources got the C objects' -include of the C gch, but nothing builds that gch for them, so a target with .S sources and no .c ones failed with "pch-c/... file not found", and others raced the C gch. There is no compiled header for assembly, so include the prefix header itself, as without precompilation. GCC also rejects a C gch for assembly. The test now builds each output from a clean build, so none passes on a header or gch that an earlier one built.
gengjiawen
approved these changes
Oct 19, 2026
gengjiawen
approved these changes
Oct 19, 2026
gengjiawen
left a comment
Member
There was a problem hiding this comment.
LGTM, thanks @kevin-sellers! I pushed follow-up commits for the ninja generator, the C PCH flags, and assembly sources; see the PR description.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Object files get a target's dependencies, and its actions and rules outputs, as
order-only prerequisites. The
.gchbuilt from a prefix header gets neither, soa prefix header that reaches a generated header races code generation: make
starts the
.gchas soon as the prefix header itself exists, and a clean buildfails on the missing generated header.
This gives the
.gchtargets the same order-only prerequisites the object filesget.
Motivation
I was attempting to enable precompiled headers for V8's largest targets in a
Node.js build. The prefix header includes
isolate-inl.h, which reachesbuiltins-definitions.h, which includes the generatedbuiltins-generated/bytecodes-builtins-list.h. A clean build died with:Any target whose
GCC_PREFIX_HEADERtransitively includes generated code hitsthis today, independently of how the prefix header was configured.
Follow-up commits
Pushed by @gengjiawen after review:
WritePchTargets,so all four
.gchrules (c, cc, m, mm) get them, not only those of languagesthat have objects, and the
.gchrules setTOOLSETas the objects do. Theninja
.gchbuilds raced code generation the same way, and now get theobjects'
predepends.cmd_pch_ccompiled the C prefix header with$(CXXFLAGS.$(TOOLSET)); it now uses$(CFLAGS.$(TOOLSET)), as the C objectsthat include it do.
GCC_PRECOMPILE_PREFIX_HEADER,.s/.Ssources got the-includeof the C.gch, which nothing built for them, so a target withassembly and no C sources failed with
pch-c/... file not found. There is nocompiled header for assembly, so they now include the prefix header itself,
as without precompilation.
Testing
TestGypMac.test_make_precompiled_prefix_headerandTestGypMac.test_ninja_precompiled_prefix_headergeneratetest/fixtures/pch_prefix.gyp, then build each.gch(c, cc, m, mm) and a.Sobject on its own, each from a clean build. The prefix header of
pch_actionincludes a header generated by the target's action, and that of
pch_deponegenerated by a dependency, so each build fails unless it waits for its
generated header. The make build also sets
CXXFLAGS=-std=c++17, which a Ccompile rejects.
BEGIN_COMMIT_OVERRIDE
fix: build precompiled headers after generated inputs (#360)
fix(make): compile the C prefix header with CFLAGS (#360)
fix: include the prefix header itself in assembly sources (#360)
END_COMMIT_OVERRIDE