Factory.ai

Open-Source Wikis

/

LLVM

/

LLVM project overview

/

Getting started

llvm/llvm-project

Getting started

This page is the fastest path from a fresh checkout to a working LLVM build. It is a condensed companion to the upstream guides at llvm.org/docs/GettingStarted.html and the per-subproject README files. Use this when you want a working clang/llvm-bolt/opt/etc. binary on your machine in the smallest number of steps.

Prerequisites

The official prerequisites are tracked in llvm/docs/GettingStarted.rst. At the time of writing the practical minimum is:

  • A C++17-capable host C++ compiler. GCC ≥ 7.4, Clang ≥ 5.0, or recent MSVC are typical. Building Clang from a recent host is fastest.
  • CMake ≥ 3.20.
  • Python ≥ 3.8 (used by build helpers, lit, and many tests).
  • Ninja is strongly recommended; it parallelizes builds far better than Make in this codebase.
  • A lot of RAM and disk. A full debug build of llvm + clang is in the tens of GB. Linking debug binaries can use 4–16 GB of RAM per ld invocation; using lld and -DLLVM_USE_LINKER=lld is highly recommended once you have a working lld.

Optional but commonly useful:

  • ccache or sccache for faster incremental builds (-DLLVM_CCACHE_BUILD=ON).
  • clang (rather than gcc) as the host compiler — it speeds up self-hosted builds.

One-shot build of clang + lld

The most common starter configuration:

git clone https://github.com/llvm/llvm-project.git
cd llvm-project
cmake -G Ninja -S llvm -B build \
    -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_ENABLE_PROJECTS="clang;lld" \
    -DLLVM_TARGETS_TO_BUILD="host" \
    -DLLVM_ENABLE_ASSERTIONS=ON
ninja -C build

The resulting build/bin/clang, build/bin/lld, build/bin/opt, and friends are runnable in place; no install is required.

To install:

cmake --install build --prefix /your/install/prefix

Selecting subprojects

LLVM_ENABLE_PROJECTS controls which compiler/tool subprojects are built. Typical values:

  • "clang" — the C/C++ front end
  • "clang;lld" — front end + linker
  • "clang;lld;lldb" — add the debugger
  • "clang;mlir" — for MLIR development
  • "clang;flang;mlir" — Fortran (Flang depends on MLIR)
  • "bolt;clang;lld" — to build BOLT
  • "all" — every in-tree project (slow)

Runtime libraries (compiler-rt, libcxx, libcxxabi, libunwind, openmp, libc, etc.) are configured via LLVM_ENABLE_RUNTIMES instead. Building runtimes typically requires a working in-tree clang first.

Selecting targets

LLVM_TARGETS_TO_BUILD is a semicolon-separated list. Common values:

  • "host" — only the host architecture
  • "X86;AArch64" — two specific targets
  • "all" — every supported target (much slower; large binary)

Available targets are listed in llvm/lib/Target/.

Building runtimes

A runtimes-only build using the just-built clang:

cmake -G Ninja -S runtimes -B build-runtimes \
    -DCMAKE_C_COMPILER=$PWD/build/bin/clang \
    -DCMAKE_CXX_COMPILER=$PWD/build/bin/clang++ \
    -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind"
ninja -C build-runtimes

The runtimes/ top-level directory (runtimes/CMakeLists.txt) is the entry point for runtime-only builds.

Running the test suite

Each subproject ships a check-<name> target that runs its lit regression suite:

ninja -C build check-llvm        # core LLVM tests
ninja -C build check-clang       # Clang tests
ninja -C build check-lld         # LLD tests
ninja -C build check-mlir        # MLIR tests
ninja -C build check-all         # everything that's enabled

Unit tests are built by their parent project; the check-* targets run them too.

To run a single regression test:

build/bin/llvm-lit -v llvm/test/CodeGen/X86/popcnt.ll

For more on the testing layers, see the testing page.

Quick sanity check

After the build succeeds, this round-trip exercises the major components:

echo 'int main(){return 41+1;}' | build/bin/clang -x c -O2 -emit-llvm -S -o - -
echo 'int main(){return 41+1;}' | build/bin/clang -x c -O2 -fuse-ld=lld -o /tmp/hello -
/tmp/hello; echo $?       # → 42

Where to go next

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Getting started – LLVM wiki | Factory