Repository navigation
Let builds share a compile cache at the same time - #505
Open
dimensionscape wants to merge 4 commits into
Open
dimensionscape wants to merge 4 commits into
dimensionscape wants to merge 4 commits into
Conversation
A file group cached with asLibrary, as hxcpp_runtime, hxcpp-cppia and hxcpp_sqlite are, is linked into <cache>/<project>/lib, named only by the toolchain's object folder and the project. Builds with other defines, as a cppia host built with HXCPP_DEBUGGER and one without, compile other objects for those groups, and linked them into the same file. One after the other, each build found the other's objects in the .hash record and linked the library again. At the same time, one could link the other's library between linking its own and linking the program. On Windows with MSVC the debugger host failed on unresolved __hxcpp_dbg_* symbols and hx::sExecutionTrace, the plain host on the same symbols defined twice, and either could fail to open a library (LNK1104) while the other's lib.exe wrote it. With a warm cache, three rounds of the two hosts built at once failed both builds every time. Stock hxcpp names the library the same way, in 4.3.2 and on master. The linker now names a library in the cache by a hash of its objects' names, which already hash each object's source, flags and compiler, and of the tool, flags and libraries it is linked with. A build with other objects gets a library of its own, and builds with the same objects share one, linked again as before when an object is newer than it, as one trimmed from the cache and compiled again is. The library is linked under a name of the build's own beside it and renamed into place, so no build links one half written, and a failed link leaves nothing behind. Windows renames onto no file that is there, and deletes none another link has open. So when the rename fails and the library there is up to date, another build linked the same objects and put it there first, and this build drops its own. One older than the objects is deleted and the rename tried again, and while another link has it open, this build links its own copy, deletes it on exit, and leaves the replacing to a later build. Libraries under the old names are no longer used and are left for trimming. Tests: test/compile_cache/shared_lib.sh, run in test.yml, builds a cached library that returns VALUE in folders of its own with one cache. On Windows x64 with MSVC 14.50 and Haxe 4.3.7, before this change a build with another VALUE changed the first build's library, the first build again linked it again, and in two runs 10 and 11 of 12 builds run four at a time failed with LNK1104 or LNK1181, while one printed another build's VALUE each time. After it, all of it passes, including a library linked again in its place after its object was removed. By hand, a build that found its library older than its object while another process held it open linked its own copy and printed the right value, and the next build replaced it. Two scriptable cppia hosts, with HXCPP_DEBUGGER and without, built at the same time against one cache with its libraries removed before each of three rounds, linked their libraries and ran a cppia script each time, and an unchanged rebuild linked nothing.
Builds that share a compile cache with the same defines, as two
projects built at once do, compile the same cached objects and make the
same cached precompiled header: their names hash the source, flags and
compiler, not the build. Each compiler wrote them in place, so from an
empty cache both builds compiled every shared file into the same path.
On Windows with MSVC, two identical scriptable cppia hosts built at once
both failed on hxcpp.h's precompiled header: one could not write
hxcpp.obj while the other's cl.exe did ("Could not create PCH", C1083),
deleted its half made one, and the other then found no hxcpp.pch. A
debugger host and a plain one, which share the pcre2, zlib and other
objects that HXCPP_DEBUGGER does not change, failed with LNK1104 on an
object the other build was still writing. Stock hxcpp writes them in
place too, in 4.3.2 and on master.
An object in the cache is now compiled under a name of the build's own
beside it and renamed to its name. A precompiled header in the cache is
made in a directory of the build's own, with its MSVC object, and the
directory is renamed to its name, so the two always arrive together,
and the cache no longer makes that directory empty in advance. When the
rename fails because another build put the same one there first, as
Windows renames onto nothing that is there and POSIX onto no directory
with files in it, the one there is kept if it will do: an object not
older than its precompiled header, or a header with its object. One
that will not do is moved aside and replaced, trying for 30 seconds
while another build has it open. A failed compile deletes only its own
file, where it deleted the cached one, which another build may just
have made. Cached libraries take the same helpers from CompileCache.
PathManager.mkdir also failed when another build made the directory
between its check and its make, which builds starting on an empty
cache hit as "Could not create compiler cache directory".
Tests: test/compile_cache/same_objects.sh, run in test.yml, builds a
cached group with a precompiled header, its sources in one shared
folder, in four folders at once from an empty cache, three times. On
Windows x64 with MSVC 14.50 and Haxe 4.3.7, before this change all 12
builds failed (C1083 on the header and on objects, and the cache
directory). After it, all 12 printed 36, each having made the header
and compiled all nine files, and nothing was left half made. With
-D emscripten (emsdk 3.1.74), which makes a clang precompiled header,
all 12 built and printed 36 under node. shared_lib.sh and
compile_errors/check.sh, with the cache and without, still pass. Two
identical scriptable cppia hosts built at once from an empty cache, and
a HXCPP_DEBUGGER host with a plain one, built and ran a cppia script.
The build tool reads file dates to the second, and links a library again only for an object newer than it. On the Linux CI runner a build takes under 100 ms, so after the test removed the first build's object, the build compiled it again in the same second as the library was linked, and did not link the library again, which failed the check that it does. The object is compiled from the same source and flags, so the library was still right. The test now waits a second first, as a trimmed object compiled again later would be. Tests: test/compile_cache/shared_lib.sh passes on Windows x64 with MSVC 14.50. It failed only on Linux 64 in CI, where the build is fast enough.
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.
For 6.0.3. Builds that share one
HXCPP_COMPILE_CACHEbroke each other when they ran at the same time. This showed up while runningtest/regression/Cppia*against a shared cache and building a profiling host into it at once: a release host linked another build'sHXCPP_DEBUGGERlibrary and failed on the debugger symbols, another linked but crashed on every cppia workload, and a third failed withLNK1104: cannot open file ...hxcpp_sqlite.lib. Two commits, each with aChanges.mdline.Cached libraries (829f0ee)
A group cached with
asLibrary(hxcpp_runtime, hxcpp-cppia, hxcpp_sqlite and others) was linked to<cache>/<project>/lib/<prefix>_<project>.lib, named only by the toolchain and the project. Builds with other defines compile other objects for those groups and linked them into the same file. One after the other, each build linked it again. At the same time, one linked the other's library between linking its own and linking the program: a-D HXCPP_DEBUGGERhost and a plain one, built at once against a warm cache, failed in 3 of 3 rounds with unresolved__hxcpp_dbg_*andhx::sExecutionTrace, the same symbols defined twice, orLNK1104.Cached objects and precompiled headers (2861ad1)
Builds with the same defines compile the same cached objects and make the same cached precompiled header, and each compiler wrote them in place. Two identical scriptable cppia hosts built at once from an empty cache both failed on hxcpp.h's header: one could not write
hxcpp.objwhile the other'scl.exedid ("Could not create PCH", C1083), deleted its half-made header, and the other then found nohxcpp.pch. The debugger and plain hosts above, which share the pcre2, zlib and other objects thatHXCPP_DEBUGGERdoes not change, failed from an empty cache withLNK1104on an object the other was still writing.PathManager.mkdirno longer fails when another build makes the directory between its check and its make, which builds starting on an empty cache hit as "Could not create compiler cache directory".CompileCache, and the library code uses them too.Stock hxcpp has all of this code unchanged, in 4.3.2 and on master. I found no report of it upstream.
Tests
Run on Windows x64 with MSVC 14.50 and Haxe 4.3.7:
test/compile_cache/shared_lib.sh(new, intest.yml) builds a cached library that returns VALUE in folders of its own with one cache. Before: a build with another VALUE changed the first build's library, the first build again linked it again, and in two runs 10 and 11 of 12 builds run four at a time failed with LNK1104 or LNK1181, while one printed another build's VALUE. After: all of it passes, including a library linked again in its place after its object was removed.test/compile_cache/same_objects.sh(new, intest.yml) builds a cached group with a precompiled header, its sources in one shared folder, in four folders at once from an empty cache, three times. Before: all 12 builds failed. After: all 12 print 36, each having made the header and compiled all nine files, and nothing is left half made. With-D emscripten(emsdk 3.1.74, a clang precompiled header) all 12 build and print 36 under node.test/compile_errors/check.shpasses with the cache and without.HXCPP_DEBUGGERhost with a plain one from empty and from warm (every library removed before each of three rounds), all built and ran a cppia script. An unchanged rebuild links nothing.haxe compile-cpp.hxml --no-output).gcc on Linux and Apple clang are untested here, so the new CI steps will be their first run.
Overlap with #495
This merges cleanly with main. Merged after this, #495 conflicts in two hunks of
Compiler.precompile: its.datescheck belongs in the newcompletetest, and its.datesfile goes into the build's own directory (made) beforeCompileCache.putInPlace, not intodirafter it. #495's records of what each build used work with the new library names.