Refactor Clang runtimes building into async builder (#6380)

Previously, the Clang runtimes building only considered building the
target resource directory, and was only _internally_ asynchronous.
Because the asynchrony was only internal, it could use the function
frame as a context object throughout the build of the resource dir. This
is simple but doesn't generalize well to more runtimes: if we want to
add 2 or 3 more runtimes, we want them to _all_ build asynchronously.
That means using some asynchronous builder that maintains the context
and allows them to proceed concurrently with other work.

This also factors all the runtimes building code into a separate set of
files. These aren't separate libraries at this point due to the
`ClangRunner` in some cases wanting to build runtimes on-demand, but it
at least lets us organize the code more cleanly.

Because this splits code between `clang_runner.*` and
`clang_runtimes.*`, it also works to update the `#include`s for both to
be roughly accurate. I used ClangD's include cleaner for this and it
probably also did some latent cleaning as it went, but that's the reason
for the churn of `#include` lines.

The archive building is also factored out into a re-usable helper. This
is a bit "over factored" in this PR, but supports the next PR that uses
the same code to build archives for other runtimes.

This also overhauls the synchronization used -- it uses a simple `Latch`
construct introduced in a previous PR to coordinate between the steps of
building the runtimes.

Last but not least, it factors the "enable leaking" state out of a
boolean in the runner to a parameter. This is important in the face of
concurrent calls as otherwise toggling this boolean can create a race.

The next PR will layer building more runtimes on top of this new
factoring.

---------

Co-authored-by: David Blaikie <dblaikie@gmail.com>
This commit is contained in:
Chandler Carruth
2025-11-18 06:08:14 +00:00
committed by GitHub
co-authored by David Blaikie
parent fbc7690157
commit 77808cd5d7
9 changed files with 960 additions and 422 deletions
+5 -8
View File
@@ -78,20 +78,17 @@ auto ClangSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
return {.success = false};
}
// Only enable Clang's leaking of memory if the driver can support that.
if (driver_env.enable_leaking) {
runner.EnableLeakingMemory();
}
ErrorOr<bool> run_result = false;
if (driver_env.prebuilt_runtimes) {
run_result = runner.RunWithPrebuiltRuntimes(options_.args,
*driver_env.prebuilt_runtimes);
*driver_env.prebuilt_runtimes,
driver_env.enable_leaking);
} else if (options_.build_runtimes_on_demand) {
run_result = runner.Run(options_.args, driver_env.runtimes_cache,
*driver_env.thread_pool);
*driver_env.thread_pool, driver_env.enable_leaking);
} else {
run_result = runner.RunWithNoRuntimes(options_.args);
run_result =
runner.RunWithNoRuntimes(options_.args, driver_env.enable_leaking);
}
if (!run_result.ok()) {
// This is not a Clang failure, but a failure to even run Clang, so we need