`RUNTIMES_USE_LIBC` CMake flag is now responsible for defining which libc is used to build compiler-rt runtime libraries. In particular, it provides `runtimes-libc-headers` interface library, which achieves three important goals when we're using `llvm-libc`: * sets up proper include directories to use LLVM-libc headers; * ensures that LLVM-libc generated headers will be produced; * Adds `-nostdlibinc` and propagates Linux kernel headers inclusion paths so that they match what LLVM-libc itself is using. Instead of using ad-hoc flag `COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC` just rely on the value of `RUNTIMES_USE_LIBC=llvm-libc` when we're building Scudo allocator for use with LLVM-libc. Importantly, this fixes the cross-build of Scudo allocator, since it will now pick up the correct headers from `-DLIBC_KERNEL_HEADERS` instead of using host system's kernel headers. All users of `-DCOMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC=ON` would need to be switched to `-DRUNTIMES_USE_LIBC=llvm-libc`, but thankfully there are not too many of them. Update the Github workflow that needs it, as well as LLVM-libc docs (libc++ CI already has the correct `RUNTIMES_USE_LIBC` value). This change makes `COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC` flag a no-op, but I leave it as-is for now and delete it in a follow-up change. --------- Co-authored-by: Petr Hosek <phosek@google.com>
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 \
-DRUNTIMES_USE_LIBC=llvm-libc \
-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.