llvm-project/libc/docs/getting_started.rst
Nick Desaulniers 692c77f2af
[libc][docs] reorder docs to be more beginner friendly (#122376)
This commit does a few things, with the intent to make it more straightforward
to potential future users how to get started with llvm-libc. Answers to "What's
the status and how do I use it?" are front and center, "above the fold."

This commit does a few things:
* reorganize the landing page's toctree: start with implementation status, arch
* support, platform support, and
    compiler support.
  * Then a (new) simple getting started page using full host builds. Then more
  * Advanced topics such as host vs cross builds, overlay mode,
    gpu builds and additional configuration options.
* Remove c23 status, the old fullbuild_mode landing page, and
  usage_modes landing pages. c23 status isn't as interesting as I originally
  thought it might.

We should point people at full host builds to start, then link to more info on
cross compilation, or overlay mode as more advanced topics. I assert most users
starting out won't care about those.
2025-01-14 09:38:15 -08:00

59 lines
1.6 KiB
ReStructuredText

Getting Started
===============
Let's fetch the llvm-libc sources and build them.
Install dependencies first:
.. code-block:: sh
$ sudo apt update
$ sudo apt install git cmake ninja-build clang gcc-multilib
.. code-block:: sh
$ git clone --depth=1 git@github.com:llvm/llvm-project.git /tmp/llvm-project
$ mkdir /tmp/llvm-project/build
$ cd /tmp/llvm-project/build
$ cmake ../runtimes -GNinja \
-DLLVM_ENABLE_RUNTIMES="libc;compiler-rt" \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang \
-DLLVM_LIBC_FULL_BUILD=ON \
-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
$ ninja libc libm
This will produce the following artifacts:
.. code-block::
llvm-project/build/libc/lib/libc.a
llvm-project/build/libc/lib/libm.a
llvm-project/build/libc/startup/linux/crt1.o
llvm-project/build/libc/include/**.h
We can then compile and run hello world via:
.. code-block:: c++
// hello.c
#include <stdio.h>
int main () { puts("hello world"); }
.. code-block:: sh
$ clang -nostdinc -nostdlib hello.c -I libc/include \
-I $(clang -print-resource-dir)/include libc/startup/linux/crt1.o \
libc/lib/libc.a
$ ./a.out
hello world
This was what we call a "full build" of llvm-libc. From here, you can visit
:ref:`full_host_build` for more info, :ref:`full_cross_build` for cross
compiling, :ref:`overlay_mode` for mixing llvm-libc with another libc, or
:ref:`libc_gpu` for targeting GPUs.