precompile and cache Carbon prelude (#7432)

Refactors the link driver to automatically compile and cache the carbon
prelude for use in linking.

Implements a `carbon_library` rule for compiling the Core library
dependencies in the examples.
This commit is contained in:
Lucile Rose Nihlen
2026-07-16 18:02:14 +00:00
committed by GitHub
parent 90f6654b48
commit 625f2ca629
63 changed files with 1454 additions and 634 deletions
+20 -1
View File
@@ -481,9 +481,27 @@ auto CompileDriver::Initialize(
}
}
// Append the Core library files on request.
llvm::SmallVector<std::string> core_library;
if (options_->include_carbon_core && !options_->custom_core &&
options_->phase >= CompileOptions::Phase::Check) {
if (auto find = driver_env.installation->ReadCarbonCoreManifest();
!find.ok()) {
CARBON_DIAGNOSTIC(CompileCoreManifestError, Error, "{0}", std::string);
driver_env.emitter.Emit(CompileCoreManifestError,
PrintToString(find.error()));
return false;
} else {
// Note we also compile any .impl files, as we will need to include them
// in the subsequent link step.
core_library = std::move(*find);
}
}
// Prepare CompilationUnits before building scope exit handlers.
int unit_index = -1;
int total_unit_count = prelude.size() + options_->input_filenames.size();
int total_unit_count =
prelude.size() + core_library.size() + options_->input_filenames.size();
auto unit_builder = [&](llvm::StringRef filename) {
++unit_index;
return std::make_unique<CompilationUnit>(
@@ -491,6 +509,7 @@ auto CompileDriver::Initialize(
driver_env.consumer, filename, map_input(filename), target);
};
llvm::append_range(units_, llvm::map_range(prelude, unit_builder));
llvm::append_range(units_, llvm::map_range(core_library, unit_builder));
input_filenames_index_ = units_.size();
llvm::append_range(units_,
llvm::map_range(options_->input_filenames, unit_builder));