# Building clang/llvm against musl and libc++
:::info
The latest version as of summer 2020 is `10.0.1`.
:::
We'll be doing heavy compilation.
It's best to create a tmpfs for the purpose.
```
sudo mkdir /tmp2
sudo mount -o size=16G -t tmpfs none /tmp2
```
This should make the permission of `/tmp2` 777.
Let's change into `/tmp2`.
```
cd /tmp2
```
Shallow clone the latest stable source (we only want the finalized files):
```
git clone \
--no-tags \
--shallow-submodules \
--depth 1 \
-b llvmorg-10.0.1 \
https://github.com/llvm/llvm-project.git
--separate-git-dir=/dev/null \
--no-remote-submodules \ # this options requires git version >= 2.23
```
Remove the git related files:
```
rm -fr llvm-project/.git*
```
[Fuschia clang tutorial](https://fuchsia.dev/fuchsia-src/development/build/toolchain)
[GCC requirements](https://llvm.org/docs/GettingStarted.html#requirements)
### Build 0
- Install a modern GCC toolchain, cmake, and ninja.
### Build 1
- Build clang/llvm against glibc and libstdc++ with *build 0*.
- Build 1 is full-featured, but its binary is not ideal.
### Build 2
- Build musl and libc++ with *build 1*.
- Build clang/llvm against musl and libc++ with *build 1*.
- Build 2 is full-featured with ideal binary.
### Build 3
- Build musl, libc++, ninja, python, and llvm-binutils with *build 2*.
- Build clang/llvm against musl and libc++ with *build 2*.
- This fully tests build 2.
## Build 1
Currently, we have `~/llvm-project`.
Create the directories `~/llvm-build` and `~/llvm-prefix`:
```
mkdir ~/llvm-build-1 ~/llvm-install-1
cd ~/llvm-build-1
```
Set up build configs with cmake ([options](https://llvm.org/docs/CMake.html)):
```
cmake \
-G Ninja \
-DLLVM_ENABLE_PROJECTS=clang \
-DCMAKE_INSTALL_PREFIX=$HOME/llvm-install-2 \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_TARGETS_TO_BUILD=X86 \
-DLLVM_ENABLE_IDE=On \
~/llvm-project/llvm
screen
time cmake --build . -- -j 32
^A + D
```
## Build 2
```
mkdir ~/llvm-build-2 ~/llvm-install-2
cd ~/llvm-build-2
cmake \
-G Ninja \
-DLLVM_ENABLE_PROJECTS=clang \
-DCMAKE_INSTALL_PREFIX=$HOME/llvm-install-2 \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_TARGETS_TO_BUILD='X86;WebAssembly' \
-DLLVM_USE_LINKER=$HOME/llvm-build-1/bin/lld \
-DLLVM_ENABLE_IDE=Off \
~/llvm-project/llvm
```