xref: /llvm-project/libc/config/windows/README.md (revision a48c4a45e0c517bf1508b3c55cf1d4d875a92353)
1# Building and Testing LLVM libc on Windows
2
3## Setting Up Environment
4
5To build LLVM libc on Windows, first build Clang using the following steps.
6
71. Open Command Prompt in Windows
82. Set TEMP and TMP to a directory. Creating this path is necessary for a
9   successful clang build.
10    1. Create tmp under your preferred directory or under `C:\src`:
11
12        ```
13        cd C:\src
14        mkdir tmp
15        ```
16
17    2. In the start menu, search for "environment variables for your account".
18       Set TEMP and TMP to `C:\src\tmp` or the corresponding path elsewhere.
193. Download [Visual Studio Community](https://visualstudio.microsoft.com/downloads/).
204. Install [CMake](https://cmake.org/download/) and
21   [Ninja](https://github.com/ninja-build/ninja/releases). (Optional, included
22   in Visual Studio).
235. Load the Visual Studio environment variables using this command. This is
24   crucial as it allows you to use build tools like CMake and Ninja:
25
26    ```
27    "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
28    ```
29
30    Note: **Rerun this command every time you open a new Command Prompt
31    window.**
32
336. If you have not used Git before, install
34   [Git](https://git-scm.com/download/win) for Windows. Check out the LLVM
35   source tree from Github using:
36
37    ```
38    git clone https://github.com/llvm/llvm-project.git
39    ```
40
417. Ensure you have access to Clang, either by downloading from
42   [LLVM Download](https://releases.llvm.org/download.html) or
43   [building it yourself](https://clang.llvm.org/get_started.html).
44
45## Building LLVM libc
46
47In this section, Clang will be used to compile LLVM
48libc, and finally, build and test the libc.
49
508. Create a empty build directory in `C:\src` or your preferred directory and
51    cd to it using:
52
53    ```
54    mkdir libc-build
55    cd libc-build
56    ```
57
589. Run the following CMake command to generate build files. LLVM libc must be built
59   by Clang, so ensure Clang is specified as the C and C++ compiler.
60
61    ```
62    cmake -G Ninja ../llvm-project/llvm -DCMAKE_C_COMPILER=C:/src/clang-build/bin/clang-cl.exe -DCMAKE_CXX_COMPILER=C:/src/clang-build/bin/clang-cl.exe  -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_FORCE_BUILD_RUNTIME=libc -DLLVM_ENABLE_PROJECTS=libc -DLLVM_NATIVE_ARCH=x86_64 -DLLVM_HOST_TRIPLE=x86_64-window-x86-gnu
63    ```
64
65    Some LLVM libc math unittests test correctness/accuracy against results from
66    the [GNU MPFR library](https://www.mpfr.org/). If you want to run math tests
67    which use MPFR, and if MPFR on your machine is not installed in the default
68    include and linker lookup directories, then you can specify the MPFR install
69    directory by passing an additional CMake option as follows:
70
71    -DLLVM_LIBC_MPFR_INSTALL_PATH=<path/mpfr/install/dir>
72
73    If the above option is specified, then `${LLVM_LIBC_MPFR_INSTALL_PATH}/include`
74    will be added to the include directories, and
75    `${LLVM_LIBC_MPFR_INSTALL_PATH}/lib` will be added to the linker lookup
76    directories.
77
78    NOTE: The GNU MPFR library depends on the
79    [GNU GMP library](https://gmplib.org/). If you specify the above option, then it
80    will be assumed that GMP is also installed in the same directory or availabe in
81    the default paths.
82
8310. Build LLVM libc using:
84
85    ```
86    ninja libc
87
88    ```
89
9011. Run tests using:
91
92    ```
93    ninja checklibc
94    ```
95