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
+14 -2
View File
@@ -458,13 +458,25 @@ auto CheckParseTrees(
// Add the prelude import. It's added to explicit_import_map so that it can
// conflict with an explicit import of the prelude.
// We add the prelude to every Carbon unit except for the prelude itself.
if (options.prelude_import &&
!(packaging && packaging->names.package_id == PackageNameId::Core)) {
(!packaging || packaging->names.package_id != PackageNameId::Core ||
packaging->names.library_id == StringLiteralValueId::None ||
!unit_info.unit->value_stores->string_literal_values()
.Get(packaging->names.library_id)
.starts_with("prelude"))) {
auto prelude_id =
unit_info.unit->value_stores->string_literal_values().Add("prelude");
// Adding the prelude to the non-prelude parts of Core requires different
// semantics because it is not valid to mention the name of the package
// for a library import from the same package.
auto package_id =
(packaging && packaging->names.package_id == PackageNameId::Core)
? PackageNameId::None
: PackageNameId::Core;
TrackImport(api_map, &explicit_import_map, unit_info,
{.node_id = Parse::NoneNodeId(),
.package_id = PackageNameId::Core,
.package_id = package_id,
.library_id = prelude_id},
options.fuzzing);
}