[libc-commits] [libc] ea471e2 - [libc] Update cross-compilation instructions

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Mon Mar 13 22:31:25 PDT 2023


Author: Jeff Bailey
Date: 2023-03-14T05:31:20Z
New Revision: ea471e2aa8fe07e0506c69a434b856f79e163068

URL: https://github.com/llvm/llvm-project/commit/ea471e2aa8fe07e0506c69a434b856f79e163068
DIFF: https://github.com/llvm/llvm-project/commit/ea471e2aa8fe07e0506c69a434b856f79e163068.diff

LOG: [libc] Update cross-compilation instructions

 * Add various options so that it uses the build lld and compiler-rt
 * Add instructions on how to use the newly built libc
 * Remove trailing comments in code-block for cut and pastability

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145878

Added: 
    

Modified: 
    libc/docs/full_cross_build.rst
    libc/docs/full_host_build.rst

Removed: 
    


################################################################################
diff  --git a/libc/docs/full_cross_build.rst b/libc/docs/full_cross_build.rst
index 2f95f5b4e8d31..431edb6e9b112 100644
--- a/libc/docs/full_cross_build.rst
+++ b/libc/docs/full_cross_build.rst
@@ -17,7 +17,8 @@ x86_64 *host*.
 Configure the full cross build of the libc
 ==========================================
 
-Below is a simple recipe to configure the libc for a cross build.
+Below is a simple recipe to configure the libc for a cross build.  In this,
+we've set Ninja as the generator, and are building the full libc.
 
 .. code-block:: sh
 
@@ -25,10 +26,11 @@ Below is a simple recipe to configure the libc for a cross build.
   $> mkdir build
   $> cd build
   $> cmake ../llvm  \
-     -G Ninja \ # Generator
-     -DLLVM_ENABLE_PROJECTS=libc  \ # Enable the libc project
-     -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++  \
-     -DLLVM_LIBC_FULL_BUILD=ON   \ # We are building the full libc
+     -G Ninja \
+     -DLLVM_ENABLE_PROJECTS=libc  \
+     -DCMAKE_C_COMPILER=clang \
+     -DCMAKE_CXX_COMPILER=clang++  \
+     -DLLVM_LIBC_FULL_BUILD=ON \
      -DLIBC_TARGET_TRIPLE=<Your target triple>
 
 We will go over the special options passed to the ``cmake`` command above.

diff  --git a/libc/docs/full_host_build.rst b/libc/docs/full_host_build.rst
index 835c009c59585..e5c5cc1e7e223 100644
--- a/libc/docs/full_host_build.rst
+++ b/libc/docs/full_host_build.rst
@@ -30,24 +30,32 @@ Configure the full libc build
 ===============================
 
 Below is the list of commands for a simple recipe to build and install the
-libc components along with other components of an LLVM only toolchain.
+libc components along with other components of an LLVM only toolchain.  In this
+we've set the Ninja generator, enabled a full compiler suite, set the build
+type to "Debug", and enabled the Scudo allocator.  The build also tells clang
+to use the freshly built lld and compiler-rt.
 
 .. code-block:: sh
 
    $> cd llvm-project  # The llvm-project checkout
    $> mkdir build
    $> cd build
+   $> SYSROOT=/path/to/sysroot # Remember to set this!
    $> cmake ../llvm  \
-      -G Ninja  \ # Generator
-      -DLLVM_ENABLE_PROJECTS="clang;libc;lld;compiler-rt"   \ # Enabled projects
-      -DCMAKE_BUILD_TYPE=<Debug|Release>  \ # Select build type
-      -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
-      -DLLVM_LIBC_FULL_BUILD=ON      \  # We want the full libc
-      -DLLVM_LIBC_INCLUDE_SCUDO=ON   \  # Include Scudo in the libc
+      -G Ninja  \
+      -DLLVM_ENABLE_PROJECTS="clang;libc;lld;compiler-rt"   \
+      -DCMAKE_BUILD_TYPE=Debug  \
+      -DCMAKE_C_COMPILER=clang \
+      -DCMAKE_CXX_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        \
-      -DCMAKE_INSTALL_PREFIX=<SYSROOT>  # Specify a sysroot directory
+      -DCLANG_DEFAULT_LINKER=lld \
+      -DCLANG_DEFAULT_RTLIB=compiler-rt \
+      -DDEFAULT_SYSROOT=$SYSROOT \
+      -DCMAKE_INSTALL_PREFIX=$SYSROOT
 
 We will go over some of the special options passed to the ``cmake`` command
 above.
@@ -62,8 +70,8 @@ above.
   So, when building the full libc, we should specify that we want to include
   Scudo in the libc. Since the libc currently only supports static linking, we
   also specify that we do not want to build the Scudo shared library.
-* **The install prefix** - This is the path to the tool chain install directory.
-  This is the directory where you intend to set up the sysroot.
+* **Default sysroot and install prefix** - This is the path to the tool chain
+  install directory.  This is the directory where you intend to set up the sysroot.
 
 Build and install
 =================
@@ -73,11 +81,11 @@ install the libc, clang (and its support libraries and builtins), lld and
 compiler-rt, with the following command:
 
 .. code-block:: sh
-   
+
    $> ninja install-clang install-builtins install-compiler-rt  \
       install-core-resource-headers install-libc install-lld
 
-Once the above command completes successfully, the ``<SYSROOT>`` directory you
+Once the above command completes successfully, the ``$SYSROOT`` directory you
 have specified with the CMake configure step above will contain a full LLVM-only
 toolchain with which you can build practical/real-world C applications. See
 `<https://github.com/llvm/llvm-project/tree/main/libc/examples>`_ for examples
@@ -89,3 +97,18 @@ Linux Headers
 If you are using the full libc on Linux, then you will also need to install
 Linux headers in your sysroot. It is left to the reader to figure out the best
 way to install Linux headers on the system they want to use the full libc on.
+
+Using your newly built libc
+===========================
+
+You can now use your newly built libc nearly like you would use any compiler
+invocation:
+
+.. code-block:: sh
+
+   $> /path/to/sysroot/bin/clang -static main.c
+
+.. warning::
+   Because the libc does not yet support dynamic linking, the -static parameter
+   must be added to all clang invocations.
+


        


More information about the libc-commits mailing list