stage2: improve handling of the generated file builtin.zig #10290
+124
−27
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.
All Zig code is eligible to
@import("builtin")
which is mapped to agenerated file, build.zig, based on the target and other settings.
Zig invocations which share the same target settings will generate the
same builtin.zig file and thus the path to builtin.zig is in a shared
cache folder, and different projects can sometimes use the same file.
Before this commit, this led to race conditions where multiple
invocations of
zig
would race to write this file. If one processwanted to read the file while the other process wrote the file, the
reading process could observe a truncated or partially written
builtin.zig file.
This commit makes the following improvements:
(possibly by an external process)
@import("builtin")
Module.File
during the AstGenwork, based on generating the contents in memory rather than
loading from disk.
to complete until the end of the AstGen work queue so that it
can be done in parallel with everything else.
rename it into place (clobbering the inode, mtime in the cold path).
This required adding a missing function to the standard library:
std.fs.Dir.statFile
. In this commit, it does open() and then fstat()which is two syscalls. It should be improved in a future commit to only
make one.
Fixes #9439.