annotate libc/docs/full_cross_build.rst @ 259:011663b4a808

remove duplicate setjmp in return continuation
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 12 Oct 2023 15:52:37 +0900
parents 1f2b6ac9f198
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 .. _full_cross_build:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 ================
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 Full Cross Build
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 ================
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 .. contents:: Table of Contents
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 :depth: 1
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 :local:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 In this document, we will present recipes to cross build the full libc. When we
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 say *cross build* a full libc, we mean that we will build the full libc for a
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 target system which is not the same as the system on which the libc is being
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 built. For example, you could be building for a bare metal aarch64 *target* on a
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 Linux x86_64 *host*.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 There are three main recipes to cross build the full libc. Each one serves a
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 different use case. Below is a short description of these recipes to help users
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 pick the recipe that best suites their needs and contexts.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 * **Standalone cross build** - Using this recipe one can build the libc using a
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 compiler of their choice. One should use this recipe if their compiler can
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 build for the host as well as the target.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 * **Runtimes cross build** - In this recipe, one will have to first build the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 libc build tools for the host separately and then use those build tools to
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 build the libc. Users can use the compiler of their choice to build the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 libc build tools as well as the libc. One should use this recipe if they
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 have to use a host compiler to build the build tools for the host and then
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 use a target compiler (which is different from the host compiler) to build
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 the libc.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 * **Bootstrap cross build** - In this recipe, one will build the ``clang``
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 compiler and the libc build tools for the host first, and then use them to
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 build the libc for the target. Unlike with the runtimes build recipe, the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 user does not have explicitly build ``clang`` and other libc build tools.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 They get built automatically before building the libc. One should use this
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 recipe if they intend use the built ``clang`` and the libc as part of their
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 toolchain for the target.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 The following sections present the three recipes in detail.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 Standalone cross build
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 ======================
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 In the *standalone crossbuild* recipe, the system compiler or a custom compiler
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 of user's choice is used to build the libc. The necessary build tools for the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 host are built first, and those build tools are then used to build the libc for
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 the target. Both these steps happen automatically, as in, the user does not have
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 to explicitly build the build tools first and then build the libc. A point to
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 keep in mind is that the compiler used should be capable of building for the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 host as well as the target.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 CMake configure step
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 --------------------
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 Below is the CMake command to configure the standalone crossbuild of the libc.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 .. code-block:: sh
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 $> cd llvm-project # The llvm-project checkout
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 $> mkdir build
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 $> cd build
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 $> C_COMPILER=<C compiler> # For example "clang"
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 $> CXX_COMPILER=<C++ compiler> # For example "clang++"
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 $> cmake ../llvm \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 -G Ninja \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 -DLLVM_ENABLE_PROJECTS=libc \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 -DCMAKE_C_COMPILER=$C_COMPILER \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 -DCMAKE_CXX_COMPILER=$CXX_COMPILER \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 -DLLVM_LIBC_FULL_BUILD=ON \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 -DLIBC_TARGET_TRIPLE=<Your target triple> \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 -DCMAKE_BUILD_TYPE=<Release|Debug>
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 We will go over the special options passed to the ``cmake`` command above.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 * **Enabled Projects** - Since we want to build the libc project, we list
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 ``libc`` as the enabled project.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 * **The full build option** - Since we want to build the full libc, we pass
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 ``-DLLVM_LIBC_FULL_BUILD=ON``.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 * **The target triple** - This is the target triple of the target for which
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 we are building the libc. For example, for a Linux 32-bit Arm target,
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 one can specify it as ``arm-linux-eabi``.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 Build step
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 ----------
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 After configuring the build with the above ``cmake`` command, one can build the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 the libc for the target with the following command:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 .. code-block:: sh
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 $> ninja libc libm
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 The above ``ninja`` command will build the libc static archives ``libc.a`` and
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 ``libm.a`` for the target specified with ``-DLIBC_TARGET_TRIPLE`` in the CMake
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 configure step.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 Runtimes cross build
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 ====================
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 The *runtimes cross build* is very similar to the standalone crossbuild but the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 user will have to first build the libc build tools for the host separately. One
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 should use this recipe if they want to use a different host and target compiler.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 Note that the libc build tools MUST be in sync with the libc. That is, the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 libc build tools and the libc, both should be built from the same source
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 revision. At the time of this writing, there is only one libc build tool that
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 has to be built separately. It is done as follows:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 .. code-block:: sh
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 $> cd llvm-project # The llvm-project checkout
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 $> mkdir build-libc-tools # A different build directory for the build tools
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 $> cd build-libc-tools
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 $> HOST_C_COMPILER=<C compiler for the host> # For example "clang"
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 $> HOST_CXX_COMPILER=<C++ compiler for the host> # For example "clang++"
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 $> cmake ../llvm \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 -G Ninja \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 -DLLVM_ENABLE_PROJECTS=libc \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 -DCMAKE_C_COMPILER=$HOST_C_COMPILER \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 -DCMAKE_CXX_COMPILER=$HOST_CXX_COMPILER \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 -DLLVM_LIBC_FULL_BUILD=ON \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 -DCMAKE_BUILD_TYPE=Debug # User can choose to use "Release" build type
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 $> ninja libc-hdrgen
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 The above commands should build a binary named ``libc-hdrgen``. Copy this binary
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 to a directory of your choice.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 CMake configure step
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 --------------------
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 After copying the ``libc-hdrgen`` binary to say ``/path/to/libc-hdrgen``,
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 configure the libc build using the following command:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 .. code-block:: sh
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 $> cd llvm-project # The llvm-project checkout
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 $> mkdir build
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 $> cd build
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 $> TARGET_C_COMPILER=<C compiler for the target>
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 $> TARGET_CXX_COMPILER=<C++ compiler for the target>
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 $> HDRGEN=</path/to/libc-hdrgen>
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 $> TARGET_TRIPLE=<Your target triple>
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 $> cmake ../runtimes \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 -G Ninja \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 -DLLVM_ENABLE_RUNTIMES=libc \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 -DCMAKE_C_COMPILER=$TARGET_C_COMPILER \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 -DCMAKE_CXX_COMPILER=$TARGET_CXX_COMPILER \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 -DLLVM_LIBC_FULL_BUILD=ON \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 -DLIBC_HDRGEN_EXE=$HDRGEN \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 -DLIBC_TARGET_TRIPLE=$TARGET_TRIPLE \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 -DCMAKE_BUILD_TYPE=Debug # User can choose to use "Release" build type
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 Note the differences in the above cmake command versus the one used in the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 CMake configure step of the standalone build recipe:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 * Instead of listing ``libc`` in ``LLVM_ENABLED_PROJECTS``, we list it in
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 ``LLVM_ENABLED_RUNTIMES``.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 * Instead of using ``llvm-project/llvm`` as the root CMake source directory,
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 we use ``llvm-project/runtimes`` as the root CMake source directory.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 * The path to the ``libc-hdrgen`` binary built earlier is specified with
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 ``-DLIBC_HDRGEN_EXE=/path/to/libc-hdrgen``.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 Build step
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 ----------
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 The build step in the runtimes build recipe is exactly the same as that of
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 the standalone build recipe:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 .. code-block:: sh
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 $> ninja libc libm
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 As with the standalone build recipe, the above ninja command will build the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 libc static archives for the target specified with ``-DLIBC_TARGET_TRIPLE`` in
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 the CMake configure step.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 Bootstrap cross build
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 =====================
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 In this recipe, the clang compiler and the ``libc-hdrgen`` binary, both are
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 built automatically before building the libc for the target.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 CMake configure step
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 --------------------
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 .. code-block:: sh
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 $> cd llvm-project # The llvm-project checkout
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 $> mkdir build
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 $> cd build
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 $> C_COMPILER=<C compiler> # For example "clang"
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 $> CXX_COMPILER=<C++ compiler> # For example "clang++"
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 $> TARGET_TRIPLE=<Your target triple>
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 $> cmake ../llvm \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 -G Ninja \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 -DCMAKE_C_COMPILER=$C_COMPILER \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 -DCMAKE_CXX_COMPILER=$CXX_COMPILER \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 -DLLVM_ENABLE_PROJECTS=clang \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 -DLLVM_ENABLE_RUNTIMES=libc \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 -DLLVM_LIBC_FULL_BUILD=ON \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 -DLLVM_RUNTIME_TARGETS=$TARGET_TRIPLE \
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 -DCMAKE_BUILD_TYPE=Debug
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 Note how the above cmake command differs from the one used in the other two
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 recipes:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 * ``clang`` is listed in ``-DLLVM_ENABLE_PROJECTS`` and ``libc`` is
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 listed in ``-DLLVM_ENABLE_RUNTIMES``.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 * The CMake root source directory is ``llvm-project/llvm``.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 * The target triple is specified with ``-DLLVM_RUNTIME_TARGETS``.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 Build step
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 ----------
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 The build step is similar to the other two recipes:
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 .. code-block:: sh
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 $> ninja libc
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 The above ninja command should build the libc static archives for the target
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 specified with ``-DLLVM_RUNTIME_TARGETS``.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 Building for bare metal
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 =======================
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 To build for bare metal, all one has to do is to specify the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 `system <https://clang.llvm.org/docs/CrossCompilation.html#target-triple>`_
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 component of the target triple as ``none``. For example, to build for a
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 32-bit arm target on bare metal, one can use a target triple like
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 ``arm-none-eabi``. Other than that, the libc for a bare metal target can be
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 built using any of the three recipes described above.