llvm-c166/libc/docs/getting_started.md
Pavel Labath 08c81127ba
[libc] Run tests in matching build configurations only (#215333)
This patch sets it up so that unit tests only run in overlay mode (this
is the new change), while hermetic tests only run in the full build mode
(this has always been the case). Running the unit tests in full build
mode was an inconsistent configuration because we were building code
that expects to be run with our own startup code, but then we did not
link that into the unit test.

With this change, it does not make much sense to distinguish between
unit and hermetic tests, as one can think of it just as a "test", which
runs using whatever is the current build configuration. As such, this
patch removes the use of the unit/hermetic test terminology from the
most obvious place -- the add_libc_test macro. UNIT_TEST_ONLY and
HERMETIC_TEST_ONLY are replaced by OVERLAY_BUILD_ONLY and
FULL_BUILD_ONLY, respectively. Since there will only ever be one kind of
a test in a given build, the tests also lose the __unit__ and
__hermetic__ suffixes.

This also means that tests depending on the MPFR library will not be run
in full build mode -- one has to use overylay mode for that. Apart from
that, this does not have impact on test coverage as we currently don't
have other UNIT_TEST_ONLY tests.
2026-08-11 18:18:40 +02:00

2.3 KiB

(getting_started)=

Getting Started

This guide provides a single, robust path for new users and contributors to build, test, and verify LLVM-libc. We use the runtimes build (see {ref}build_concepts for more information) because it is faster and sufficient for most development tasks.

1. Install Dependencies

To build LLVM-libc, you will need a recent version of Clang (v15+) and basic build tools. On a Debian/Ubuntu-based system, you can install these using apt-get:

sudo apt-get update
sudo apt-get install git cmake ninja-build clang gcc-multilib

2. Clone and Configure

The following command clones the complete LLVM project and configures the build for LLVM-libc. We include compiler-rt to enable the Scudo memory allocator.

git clone --depth=1 https://github.com/llvm/llvm-project.git
cd llvm-project
cmake -G Ninja -S runtimes -B build \
  -DLLVM_ENABLE_RUNTIMES="libc;compiler-rt" \
  -DLLVM_LIBC_FULL_BUILD=ON \
  -DCMAKE_BUILD_TYPE=Debug \
  -DCMAKE_C_COMPILER=clang \
  -DCMAKE_CXX_COMPILER=clang++ \
  -DLLVM_LIBC_INCLUDE_SCUDO=ON \
  -DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON \
  -DCOMPILER_RT_BUILD_GWP_ASAN=OFF \
  -DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF \
  -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

3. Build and Test

After configuring, you can build the library, the math library (libm), and run all unit tests:

ninja -C build libc libm check-libc

To run a specific test, such as isalpha in ctype.h:

ninja -C build libc.test.src.ctype.isalpha_test

4. Verify with Hello World

To verify your build, create a simple hello.c file:

#include <stdio.h>

int main() {
  printf("Hello world from LLVM-libc!\n");
  return 0;
}

Compile it using the build artifacts:

clang -nostdinc -nostdlib hello.c -o hello \
  -I build/libc/include \
  -I $(clang -print-resource-dir)/include \
  build/libc/startup/linux/crt1.o \
  build/libc/lib/libc.a \
  build/libc/lib/libm.a

Finally, run the executable:

./hello
# Output: Hello world from LLVM-libc!

This setup builds LLVM-libc as a standalone library using the recommended set of flags. From here, you can visit {ref}full_host_build for advanced sysroot setup, {ref}overlay_mode to learn about using LLVM-libc to augment your system's C library, or {ref}build_concepts to understand other build scenarios.