carbon-lang README

The project's README from github.com/carbon-language/carbon-lang. As one markdown file: README.md.

Carbon Language:
An experimental successor to C++

Why? | Goals | Status | Getting started | Join us

See our announcement video from CppNorth. Note that Carbon is not ready for use.

Quicksort code in Carbon. Follow the link to read more.

Fast and works with C++

Modern and evolving

Welcoming open-source community

Why build Carbon?

C++ remains the dominant programming language for performance-critical software, with massive and growing codebases and investments. However, it is struggling to improve and meet developers' needs, as outlined above, in no small part due to accumulating decades of technical debt. Incrementally improving C++ is extremely difficult, both due to the technical debt itself and challenges with its evolution process. The best way to address these problems is to avoid inheriting the legacy of C or C++ directly, and instead start with solid language foundations like modern generics system, modular code organization, and consistent, simple syntax.

Existing modern languages already provide an excellent developer experience: Go, Swift, Kotlin, Rust, and many more. Developers that can use one of these existing languages should. Unfortunately, the designs of these languages present significant barriers to adoption and migration from C++. These barriers range from changes in the idiomatic design of software to performance overhead.

Carbon is fundamentally a successor language approach, rather than an attempt to incrementally evolve C++. It is designed around interoperability with C++ as well as large-scale adoption and migration for existing C++ codebases and developers. A successor language for C++ requires:

With this approach, we can build on top of C++'s existing ecosystem, and bring along existing investments, codebases, and developer populations. There are a few languages that have followed this model for other ecosystems, and Carbon aims to fill an analogous role for C++:

Language Goals

We are designing Carbon to support:

While many languages share subsets of these goals, what distinguishes Carbon is their combination.

We also have explicit non-goals for Carbon, notably including:

Our detailed goals document fleshes out these ideas and provides a deeper view into our goals for the Carbon project and language.

Project status

Carbon Language is currently an experimental project. We are hard at work on a toolchain implementation with compiler and linker. You can try out the current state at compiler-explorer.com.

We want to better understand whether we can build a language that meets our successor language criteria, and whether the resulting language can gather a critical mass of interest within the larger C++ industry and community.

Currently, we have fleshed out several core aspects of both Carbon the project and the language:

If you're interested in contributing, we're currently focused on developing the Carbon toolchain until it can support Carbon ↔ C++ interop. Beyond that, we plan to continue developing the design and toolchain until we can ship the 0.1 language and support evaluating Carbon in more detail.

You can see our full roadmap for more details.

Carbon and C++

If you're already a C++ developer, Carbon should have a gentle learning curve. It is built out of a consistent set of language constructs that should feel familiar and be easy to read and understand.

The Carbon code here is hypothetical and meant to show the look and feel of the language.

C++ code like this:

A snippet of C++ code. Follow the link to read it.

corresponds to this Carbon code:

A snippet of converted Carbon code. Follow the link to read it.

You can call Carbon from C++ without overhead and the other way around. This means you migrate a single C++ library to Carbon within an application, or write new Carbon on top of your existing C++ investment. For example:

A snippet of mixed Carbon and C++ code. Follow the link to read it.

Read more about C++ interop in Carbon.

Beyond interoperability between Carbon and C++, we're also planning to support migration tools that will mechanically translate idiomatic C++ code into Carbon code to help you switch an existing C++ codebase to Carbon.

Generics

Carbon provides a modern generics system with checked definitions, while still supporting opt-in templates for seamless C++ interop. Checked generics provide several advantages compared to C++ templates:

Without sacrificing these advantages, Carbon generics support specialization, ensuring it can fully address performance-critical use cases of C++ templates. For more details about Carbon's generics, see their design.

In addition to easy and powerful interop with C++, Carbon templates can be constrained and incrementally migrated to checked generics at a fine granularity and with a smooth evolutionary path.

Memory safety

Safety, and especially memory safety, remains a key challenge for C++ and something a successor language needs to address.

We plan to support a two step migration process:

  1. Highly automated, minimal supervision migration from C++ to a dialect of Carbon designed for C++ interop and migration.
  2. Incremental refactoring of the Carbon code to adopt memory-safe designs, patterns, and APIs.

We also want to address important, low-hanging fruit in the safety space immediately when migrating into Carbon:

For more details, see our safety design.

Getting started

To try out Carbon immediately in your browser, you can use the toolchain at: carbon.compiler-explorer.com.

We are developing a traditional toolchain for Carbon that can compile and link programs. However, Carbon is still an early, experimental project, and so we only have very experimental nightly releases of the Carbon toolchain available to download, and only on limited platforms. If you are using a recent Ubuntu Linux or similar (Debian, WSL, etc.), you can try these out by going to our releases page and download the latest nightly toolchain tar file: carbon_toolchain-0.0.0-0.nightly.YYYY.MM.DD.tar.gz. Then you can try it out:

# A variable with the nightly version from yesterday:
VERSION="$(date -d yesterday +0.0.0-0.nightly.%Y.%m.%d)"

# Get the release
wget https://github.com/carbon-language/carbon-lang/releases/download/v${VERSION}/carbon_toolchain-${VERSION}.tar.gz

# Unpack the toolchain:
tar -xvf carbon_toolchain-${VERSION}.tar.gz

# Create a simple Carbon source file:
echo "import Core library \"io\"; fn Run() { Core.Print(42); }" > forty_two.carbon

# Compile to an object file:
./carbon_toolchain-${VERSION}/bin/carbon compile \
  --output=forty_two.o forty_two.carbon

# Install minimal system libraries used for linking. Note that installing `gcc`
# or `g++` for compiling C/C++ code with GCC will also be sufficient, these are
# just the specific system libraries Carbon linking still uses.
sudo apt install libgcc-11-dev

# Link to an executable:
./carbon_toolchain-${VERSION}/bin/carbon link \
  --output=forty_two forty_two.o

# Run it:
./forty_two

As a reminder, the toolchain is still very early and many things don't yet work. Please hold off on filing lots of bugs: we know many parts of this don't work yet or may not work on all systems. We expect to have releases that are much more robust and reliable that you can try out when we reach our 0.1 milestone.

If you want to build Carbon's toolchain yourself or are thinking about contributing fixes or improvements to Carbon, you'll need to install our build dependencies (Clang, LLD, libc++) and check out the Carbon repository. For example, on Debian or Ubuntu:

# Update apt.
sudo apt update

# Install tools.
sudo apt install \
  clang \
  libc++-dev \
  libc++abi-dev \
  lld

# Download Carbon's code.
$ git clone https://github.com/carbon-language/carbon-lang
$ cd carbon-lang

Then you can try out our toolchain which has a very early-stage compiler for Carbon:

# Build and run the toolchain's help to get documentation on the command line.
$ ./scripts/run_bazelisk.py run //toolchain -- help

For complete instructions, including installing dependencies on various different platforms, see our contribution tools documentation.

Learn more about the Carbon project:

Conference talks

Carbon focused talks from the community:

2026

2025

2024

2023

2022

Other videos

We additionally have toolchain videos.

Join us

We'd love to have folks join us and contribute to the project. Carbon is committed to a welcoming and inclusive environment where everyone can contribute.

Contributing

You can also directly:

You can check out some "good first issues", or join the #contributing-help channel on Discord. See our full CONTRIBUTING documentation for more details.

carbon-lang (carbon-language/carbon-lang)

Searching Database…

这是什么?一个实验性的 C++ 后继语言:具备 C++ 级别的性能,能与现有 C++ 代码无缝互操作,并且拥有更现代、更安全的基础设计。这个仓库存放着它的文档、语言设计和工具链的实现。
那这个仓库里到底是什么——语言设计,还是一个能用的编译器?设计和实现都有:既包括语言设计(泛型、类、继承、运算符重载等),也包括一个还在开发中的编译器和链接器。较早的原型 explorer 解释器已归档,不再继续开发。
我怎么试用它?可以在浏览器里打开 carbon.compiler-explorer.com 立即体验。本地使用的话,从 GitHub releases 页面下载每夜版工具链压缩包(carbontoolchain-0.0.0-0.nightly.YYYY.MM.DD.tar.gz)并解压即可。
它能拿来开发真实项目了吗?不能——Carbon 明确表示还不适合使用。每夜版工具链非常早期,很多东西都无法正常工作;更稳健的版本预计要到 0.1 里程碑才会发布,所以团队请大家暂时不要大规模提交 bug 报告。
用 Carbon 需要先懂 C++ 吗?它面向的是现有的 C++ 开发者和 C++ 代码库,如果你已经会 C++,学习曲线会相对平缓。README 中提到,已经在用 Go、Swift、Kotlin 或 Rust 的开发者应该继续用那些语言。
这个工具链到底能在哪些平台上运行?每夜版下载目前只支持少数平台:较新的 Ubuntu Linux 及类似系统(Debian、WSL)。而 carbon.compiler-explorer.com 上的浏览器在线环境在任何地方都能用。
我能把 Carbon 和现有的 C++ 代码混着用吗?可以——这正是它的核心理念。Carbon 和 C++ 可以双向互相调用,没有额外开销,所以你可以只迁移一个库,也可以在现有 C++ 积累的基础上编写新的 Carbon 代码。另外还计划提供能把惯用的 C++ 自动翻译成 Carbon 的迁移工具。
Carbon 的泛型和 C++ 的模板有什么区别?泛型定义会提前完成完整的类型检查:不用实例化就能发现错误,错误信息会准确指出是哪个约束没满足,而且定义不会在每次实例化时被重复检查。模板仍然保留,作为 C++ 互操作时的可选项,对性能敏感的代码依然支持特化。
Carbon 在内存安全方面做了什么?计划分两步迁移:先自动把 C++ 代码转换成侧重互操作的 Carbon 方言,再逐步重构,向内存安全的设计靠拢。早期的成果包括更好的初始化追踪、动态边界检查,以及尽可能用可检出的错误行为取代未定义行为。
为什么不改进 C++ 或者直接用 Rust,而要造一门新语言?按 README 的说法,C++ 被几十年的技术债和艰难的演进流程拖住了后腿,而 Rust、Go 这类现代语言对 C++ 技术栈来说又存在采用和迁移的门槛。Carbon 的定位就是后继语言:保留 C++ 的性能和互操作性,甩掉历史包袱——就像 TypeScript 之于 JavaScript、Kotlin 之于 Java。
What are similar projects?goose, CalcKernel, swift, rust, compiler, Odin, Singeli, morloc
Size
135.6 MB
Stars
33.9K
Updated
CommitOct 17
Age
6y
Commits · 90 Days