From e35c56947f94aefa740412563bfd8760e62d52ca Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 4 Sep 2019 18:49:16 -0700 Subject: [PATCH] llvm monorepo & releases/prereleases --- Build.md | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/Build.md b/Build.md index a39777e..b81c934 100644 --- a/Build.md +++ b/Build.md @@ -237,11 +237,10 @@ these releases. You must either: #### Build clang+llvm by yourself ```sh -git clone https://git.llvm.org/git/llvm.git -git clone https://git.llvm.org/git/clang.git llvm/tools/clang +git clone https://github.com/llvm/llvm-project.git +cd llvm-project -cd llvm -cmake -H. -BRelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DLLVM_TARGETS_TO_BUILD=X86 +cmake -Hllvm -BRelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DLLVM_TARGETS_TO_BUILD=X86 ninja -C Release clangFormat clangFrontendTool clangIndex clangTooling clang # Download ccls @@ -262,26 +261,27 @@ ninja -C Release `-D__STDC_FORMAT_MACROS` is because otherwise `mingw-w64-headers/crt/inttypes.h` does not define `PRIu64`. -## Compiling Clang+LLVM from source - -MaskRay's config (building trunk LLVM at `~/llvm/Release/`): +## Build Clang+LLVM from the git monorepo ```sh -git clone https://git.llvm.org/git/llvm.git -git clone https://git.llvm.org/git/clang.git llvm/tools/clang -cd llvm -cmake -H. -BRelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DLLVM_ENABLE_LLD=ON -DLLVM_TARGETS_TO_BUILD=X86 -ninja -C Release clang clangFormat clangFrontendTool clangIndex clangTooling cxx +git clone https://github.com/llvm/llvm-project.git +cd llvm-project + +cmake -Hllvm -BRelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 +ninja -C Release clangFormat clangFrontendTool clangIndex clangTooling clang +# built Release/bin/clang ``` -* Remove `LLVM_ENABLE_LLD` if you don't have lld (a much faster linker than bfd/gold) installed -* Remove `BUILD_SHARED_LIBS` if you want to build static libraries (`libclangIndex.a`) instead +* `LLVM_TARGETS_TO_BUILD` defaults to `ALL`. We just use the frontend, don't generate code, so `X86` should be sufficient. `clang -target powerpc64le-linux -fsyntax-only` still works. +* Add `-DLLVM_ENABLE_LLD=on` if you have lld (a much faster linker than bfd/gold) installed +* Add `-DBUILD_SHARED_LIBS=on` if you want to build shared libraries (`libclangIndex.so`) Then build ccls with `-DCMAKE_PREFIX_PATH`: ```sh cd ~/ccls -cmake -H. -BRelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -DCMAKE_PREFIX_PATH="$HOME/llvm/Release;$HOME/llvm/Release/tools/clang;$HOME/llvm;$HOME/llvm/tools/clang" +LLVM=$HOME/llvm-project +cmake -H. -BRelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld -DCMAKE_PREFIX_PATH="$LLVM/Release;$LLVM/llvm;$LLVM/clang" ninja -C Release ``` @@ -307,3 +307,16 @@ The cmake build system is expected to find these files: ~/llvm/Release/lib/libLLVMSupport.so or libLLVMSupport.a ... ``` + +## Build Clang+LLVM from releases.llvm.org or prereleases.llvm.org + +Similar to the instructions to build Clang+LLVM from the git monorepo: + +```sh +# Download "LLVM source code" and rename the extracted directory to llvm +# Download "Clang source code" and rename the extracted directory to llvm/tools/clang +cd llvm +cmake -H. -BRelease -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 +ninja -C Release clangFormat clangFrontendTool clangIndex clangTooling clang +# built Release/bin/clang +```