Skip to content

Commit 0a94ee6

Browse files
[libc] update host build docs (#120147)
Update the host build docs to better reflect the current recommended process.
1 parent c2830b2 commit 0a94ee6

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

libc/docs/dev/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Developer Guides
77
Navigate to the links below for information on the respective topics:
88

99
.. toctree::
10+
:maxdepth: 1
1011

1112
code_style
1213
source_tree_layout

libc/docs/full_host_build.rst

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Full Host Build
88
:depth: 1
99
:local:
1010

11-
.. note::
11+
.. note::
1212
Fullbuild requires running headergen, which is a python program that depends on
1313
pyyaml. The minimum versions are listed on the :ref:`header_generation`
1414
page, as well as additional information.
@@ -99,11 +99,16 @@ a C++ standard library (like libc++). Hence, we do not include
9999
`libc++ <https://libcxx.llvm.org/>`_, libcxx-abi and libunwind in the
100100
LLVM only toolchain and use them to build and link C++ applications.
101101

102-
Below is the list of commands for a simple recipe to build and install the
103-
libc components along with other components of an LLVM only toolchain. In this
104-
we've set the Ninja generator, enabled a full compiler suite, set the build
105-
type to "Debug", and enabled the Scudo allocator. The build also tells clang
106-
to use the freshly built lld and compiler-rt.
102+
Below is the cmake command for a bootstrapping build of LLVM. This will build
103+
clang and lld with the current system's toolchain, then build compiler-rt and
104+
LLVM-libc with that freshly built clang. This ensures that LLVM-libc can take
105+
advantage of the latest clang features and optimizations.
106+
107+
This build also uses Ninja as cmake's generator, and sets lld and compiler-rt as
108+
the default for the fresh clang. Those settings are recommended, but the build
109+
should still work without them. The compiler-rt options are required for
110+
building `Scudo <https://llvm.org/docs/ScudoHardenedAllocator.html>`_ as the
111+
allocator for LLVM-libc.
107112

108113
.. note::
109114
if your build fails with an error saying the compiler can't find
@@ -113,7 +118,6 @@ to use the freshly built lld and compiler-rt.
113118
this command:
114119
``sudo ln -s /usr/include/<TARGET TRIPLE>/asm /usr/include/asm``
115120

116-
.. TODO: Move from projects to runtimes for libc, compiler-rt
117121
.. code-block:: sh
118122
119123
$> cd llvm-project # The llvm-project checkout
@@ -122,8 +126,9 @@ to use the freshly built lld and compiler-rt.
122126
$> SYSROOT=/path/to/sysroot # Remember to set this!
123127
$> cmake ../llvm \
124128
-G Ninja \
125-
-DLLVM_ENABLE_PROJECTS="clang;lld;libc;compiler-rt" \
126-
-DCMAKE_BUILD_TYPE=Debug \
129+
-DLLVM_ENABLE_PROJECTS="clang;lld" \
130+
-DLLVM_ENABLE_RUNTIMES="libc;compiler-rt" \
131+
-DCMAKE_BUILD_TYPE=Release \
127132
-DCMAKE_C_COMPILER=clang \
128133
-DCMAKE_CXX_COMPILER=clang++ \
129134
-DLLVM_LIBC_FULL_BUILD=ON \
@@ -133,25 +138,8 @@ to use the freshly built lld and compiler-rt.
133138
-DCOMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED=OFF \
134139
-DCLANG_DEFAULT_LINKER=lld \
135140
-DCLANG_DEFAULT_RTLIB=compiler-rt \
136-
-DDEFAULT_SYSROOT=$SYSROOT \
137141
-DCMAKE_INSTALL_PREFIX=$SYSROOT
138142
139-
We will go over some of the special options passed to the ``cmake`` command
140-
above.
141-
142-
* **Enabled Projects** - Since we want to build and install clang, lld
143-
and compiler-rt along with the libc, we specify
144-
``clang;libc;lld;compiler-rt`` as the list of enabled projects.
145-
* **The full build option** - Since we want to do build the full libc, we pass
146-
``-DLLVM_LIBC_FULL_BUILD=ON``.
147-
* **Scudo related options** - LLVM's libc uses
148-
`Scudo <https://llvm.org/docs/ScudoHardenedAllocator.html>`_ as its allocator.
149-
So, when building the full libc, we should specify that we want to include
150-
Scudo in the libc. Since the libc currently only supports static linking, we
151-
also specify that we do not want to build the Scudo shared library.
152-
* **Default sysroot and install prefix** - This is the path to the tool chain
153-
install directory. This is the directory where you intend to set up the sysroot.
154-
155143
Build and install
156144
=================
157145

@@ -164,14 +152,19 @@ Build and install
164152
you may need to delete them from ``/usr/local/include``.
165153

166154
After configuring the build with the above ``cmake`` command, one can build and
167-
install the libc, clang (and its support libraries and builtins), lld and
168-
compiler-rt, with the following command:
155+
install the toolchain with
169156

170157
.. code-block:: sh
171158
172159
$> ninja install-clang install-builtins install-compiler-rt \
173160
install-core-resource-headers install-libc install-lld
174161
162+
or
163+
164+
.. code-block:: sh
165+
166+
$> ninja install
167+
175168
Once the above command completes successfully, the ``$SYSROOT`` directory you
176169
have specified with the CMake configure step above will contain a full LLVM-only
177170
toolchain with which you can build practical/real-world C applications. See
@@ -190,9 +183,9 @@ These instructions should work on a Debian-based x86_64 system:
190183
191184
$> apt download linux-libc-dev
192185
$> dpkg -x linux-libc-dev*deb .
193-
$> mv usr/include/* /path/to/sysroot/include
194-
$> rm -rf usr linux-libc-dev*deb
195-
$> ln -s x86_64-linux-gnu/asm ~/Programming/sysroot/include/asm
186+
$> cp -r usr/* /path/to/sysroot/
187+
$> rm -r usr linux-libc-dev*deb
188+
$> ln -s /path/to/sysroot/include/x86_64-linux-gnu/asm /path/to/sysroot/include/asm
196189
197190
Using your newly built libc
198191
===========================
@@ -208,3 +201,20 @@ invocation:
208201
Because the libc does not yet support dynamic linking, the -static parameter
209202
must be added to all clang invocations.
210203

204+
205+
You can make sure you're using the newly built toolchain by trying out features
206+
that aren't yet supported by the system toolchain, such as fixed point. The
207+
following is an example program that demonstrates the difference:
208+
209+
.. code-block:: C
210+
211+
// $ $SYSROOT/bin/clang example.c -static -ffixed-point --sysroot=$SYSROOT
212+
213+
#include <stdio.h>
214+
int main() {
215+
printf("Hello, World!\n%.9f\n%.9lK\n",
216+
4294967295.000000001,
217+
4294967295.000000001ulK);
218+
return 0;
219+
}
220+

0 commit comments

Comments
 (0)