From Googles Carbon Github Repo ….
“Carbon is fundamentally a successor language approach, rather than an attempt to evolve C++ incrementally. 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:
- Performance matching C++, is an essential property for our developers.
- Seamless, bidirectional interoperability with C++, such that a library anywhere in an existing C++ stack can adopt Carbon without porting the rest.
- A gentle learning curve with reasonable familiarity for C++ developers.
- Comparable expressivity and support for existing software’s design and architecture.
- Scalable migration, with some level of source-to-source translation for idiomatic C++ code.
With this approach, we can build on top of C++’s existing ecosystem, and bring along existing investments, codebases, and developer populations.
Installation:
- Install homebrew
- /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
- If you have already installed homebrew in the past, then worth updating it with
- brew update — Checks if anything is out of date
- brew upgrade.
- Install Bazel
- brew install bazelisk
- Install llvm
- brew install llvm
- echo ‘export PATH=”/usr/local/opt/llvm/bin:$PATH”‘ >> ~/.bash_profile
- export LDFLAGS=”-L/opt/homebrew/opt/llvm/lib”
- export CPPFLAGS=”-I/opt/homebrew/opt/llvm/include”
- export CC=$(which clang)
- Install Carbon
- mkdir ~/Carbon; cd ~/Carbon
- git clone https://github.com/carbon-language/carbon-lang
- cd carbon-lang
- Run Hello, World to check its working
- bazel run //explorer — ./explorer/testdata/print/format_only.carbon
- NOTE: This command takes a long time the first time you run it, just keep an eye out for errors. Eventually, you will see ‘Hello world!’ printed on the terminal. Subsequent times it’s much quicker.
- bazel run //explorer — ./explorer/testdata/print/format_only.carbon
- You now have a working version of Carbon and are ready to get started….
Getting Started:
Create a folder where you can start to write carbon projects. I choice ~/Carbon/projects
I then created a folder to start my first project in ~/Carbon/projects.test
In this folder, I create a file called “test.carbon” and added the hello world example
1 2 3 4 5 6 7 | package ExplorerTest api; fn Main() -> i32 { var s: auto = "Hello world!"; Print(s); return 0; } |
And to run it I used the following command
1 2 3 | # From the folder containing carbon-lang $ bazel run //explorer -- ../projects/test/test.carbon |
And you will see something like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | INFO: Invocation ID: f68d7151-d3b2-4f7c-ac31-6454cb600a47 : : : INFO: Analyzed target //explorer:explorer (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //explorer:explorer up-to-date: bazel-bin/explorer/explorer INFO: Elapsed time: 0.103s, Critical Path: 0.00s INFO: 1 process: 1 internal. INFO: Build completed successfully, 1 total action INFO: Running command line: bazel-bin/explorer/explorer ../projects/test/test.carbon Hello world! result: 0 |
Langauge Basics:
1 | // Comments. At this time single lines only using the '//' |
1 | // |
1 | // |
1 | // |
1 | // |
1 | // |
1 | // |