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
+42 -2
View File
@@ -2,13 +2,13 @@
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("//bazel/carbon_rules:defs.bzl", "carbon_library")
load("//bazel/manifest:defs.bzl", "manifest")
# Raw prelude files.
# TODO: This includes all of Core, not just the prelude.
filegroup(
name = "prelude_files",
srcs = glob(["**/*.carbon"]),
srcs = ["prelude.carbon"] + glob(["prelude/**/*.carbon"]),
visibility = ["//visibility:public"],
)
@@ -29,3 +29,43 @@ filegroup(
],
visibility = ["//visibility:public"],
)
filegroup(
name = "core_library_files",
srcs = glob(
include = ["**/*.carbon"],
exclude = [
"prelude.carbon",
"prelude/**",
],
),
visibility = ["//visibility:public"],
)
manifest(
name = "core_library_manifest.txt",
srcs = [":core_library_files"],
strip_package_dir = True,
)
filegroup(
name = "core_library",
srcs = [
":core_library_files",
":core_library_manifest.txt",
],
visibility = ["//visibility:public"],
)
carbon_library(
name = "io",
api = "io.carbon",
impls = ["io.impl.carbon"],
visibility = ["//visibility:public"],
)
carbon_library(
name = "range",
api = "range.carbon",
visibility = ["//visibility:public"],
)
+2 -11
View File
@@ -7,24 +7,15 @@
package Core library "io";
import library "prelude";
// TODO: Support printing other types.
// TODO: Consider rewriting using native support once library support exists.
fn Print(x: i32) = "print.int";
fn PrintChar(x: char) -> i32 = "print.char";
fn PrintStr(msg: str) {
let size: i64 = msg.Size() as i64;
var i: i64 = 0;
while (i < size) {
PrintChar(msg[i]);
++i;
}
}
fn PrintStr(msg: str);
// TODO: Return an `Optional(char)` instead of `i32`.
fn ReadChar() -> i32 = "read.char";
// TODO: Change this to a global constant once they are fully supported.
fn EOF() -> i32 { return -1; }
fn EOF() -> i32;
+20
View File
@@ -0,0 +1,20 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// TODO: This library is not part of the design. Either write a matching
// proposal or remove this.
impl package Core library "io";
fn PrintStr(msg: str) {
let size: i64 = msg.Size() as i64;
var i: i64 = 0;
while (i < size) {
PrintChar(msg[i]);
++i;
}
}
// TODO: Change this to a global constant once they are fully supported.
fn EOF() -> i32 { return -1; }
-9
View File
@@ -7,15 +7,6 @@
package Core library "range";
import library "prelude/destroy";
import library "prelude/iterate";
import library "prelude/operators/arithmetic";
import library "prelude/operators/as";
import library "prelude/operators/comparison";
import library "prelude/types/int";
import library "prelude/types/int_literal";
import library "prelude/types/optional";
class IntRange(N: IntLiteral) {
fn Make(start: Int(N), end: Int(N)) -> Self {
return {.start = start, .end = end};