simpler pch support for zig build#20879
Closed
xxxbxxx wants to merge 6 commits intoziglang:masterfrom
Closed
Conversation
…ction.
It is normally based on the file extension, however:
- it can be ambiguous. for instance,
".h" is often used for c headers or c++ headers.
".s" (instead of ".S") assembly files may still need the c preprocessor. (ziglang#20655)
- a singular file may be interpreted with different languages depending on the context.
in "single-file libraries", the source.h file can be both a c-header to include, or compiled as a C file (with a #define as toggle) (ziglang#19423)
usage example:
`zig build-pch -lc++ -x c++-header test.h`
`zig run -lc++ -cflags -include-pch test.pch -- main.cpp`
It builds the file.pch with llvm "-fpch-validate-input-files-content",
so it includes data for better integration with zig caching system.
adds a new mode to the Compile step. It shares most of the code with previous compile steps, but with extra constraints expressed by assert checks.
…led header file.
It is called after the user has fully configured the steps in the build() function.
a compile step to build the pch file will be automatically created.
To benefit from precompiled headers, it is now possible to simply change
exe.addCSourceFiles(.{
.files = &.{"file.c"},
.flags = ...,
});
into
exe.addCSourceFiles(.{
.files = &.{"file.c"},
.flags = ...,
.precompiled_header = .{ .source_header = .{ path = b.path("rootincludes.h") } },
});
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.
This is a follow-up to #17956 (included here as well), that exposes a simpler interface to use precompiled headers.
It is now possible to simply add the name of the header file to precompile:
In order to do this,
finalize()function to the build steps,I don't know if that fits the general design of the build system or if there's an other way to achieve this.
updated example patch for https://github.com/allyourcodebase/cpython: