File: full_cross_build.rst

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,634,792 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (64 lines) | stat: -rw-r--r-- 2,200 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
.. _full_cross_build:

================
Full Cross Build
================

.. contents:: Table of Contents
   :depth: 1
   :local:

In this document, we will present a recipe to cross build a full libc. When we
say *cross build* a full libc, we mean that we will build the libc for a target
system which is not the same as the system on which the libc is being built.
For example, you could be building for a bare metal aarch64 *target* on a Linux
x86_64 *host*.

Configure the full cross build of the libc
==========================================

Below is a simple recipe to configure the libc for a cross build.

.. code-block:: sh

  $> cd llvm-project  # The llvm-project checkout
  $> 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
     -DLIBC_TARGET_TRIPLE=<Your target triple>

We will go over the special options passed to the ``cmake`` command above.

* **Enabled Projects** - Since we want to build the libc project, we list
  ``libc`` as the enabled project.
* **The full build option** - Since we want to build the full libc, we pass
  ``-DLLVM_LIBC_FULL_BUILD=ON``.
* **The target triple** - This is the target triple of the target for which
  we are building the libc. For example, for a Linux 32-bit Arm target,
  one can specify it as ``arm-linux-eabi``.

Build and install
=================

After configuring the build with the above ``cmake`` command, one can build the
the libc for the target with the following command:

.. code-block:: sh
   
   $> ninja libc

The above ``ninja`` command will build the ``libc.a`` static archive for the
target specified with ``-DLIBC_TARGET_TRIPLE`` to the ``cmake`` command.

Building for bare metal
=======================

To build for bare metal, all one has to do is to specify the
`system <https://clang.llvm.org/docs/CrossCompilation.html#target-triple>`_
component of the target triple as ``none``. For example, to build for a
32-bit arm target on bare metal, one can use a target triple like
``arm-none-eabi``.