From 105f9fc6487532253e155e1f46ebb593f2870377 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 9 Nov 2019 17:10:54 -0800 Subject: [PATCH] Add Example-Projects.md --- Example-Projects.md | 64 ++++++++++++++++++++++++++++++++++++++++ Project-Setup.md | 71 --------------------------------------------- _Sidebar.md | 1 + 3 files changed, 65 insertions(+), 71 deletions(-) create mode 100644 Example-Projects.md diff --git a/Example-Projects.md b/Example-Projects.md new file mode 100644 index 0000000..f32c1bc --- /dev/null +++ b/Example-Projects.md @@ -0,0 +1,64 @@ +## Linux kernel + +defconfig + +```sh +# Use clang 9 or newer. +make O=out.x86_64 CC=/path/to/clang defconfig +make O=out.x86_64 CC=/path/to/clang # generate ..cmd files +scripts/gen_compile_commands.py -d out.x86_64 +ln -s out.x86_64/compile_commands.json +``` + +2019-11-09: ARCH=x86_64 defconfig => 1.4G .ccls-cache + +Arch Linux: + +```sh +mkdir out +wget 'https://git.archlinux.org/svntogit/packages.git/plain/trunk/config?h=packages/linux' -O out/.config +yes '' | make O=out config +``` + +If CC=gcc, there may be some options that need filtering out: + +```zsh +ccls -index ~/Dev/Linux -init='{"clang":{"excludeArgs":[ +"-falign-jumps=1","-falign-loops=1","-fconserve-stack","-fmerge-constants","-fno-code-hoisting","-fno-schedule-insns","-fno-sched-pressure","-fno-var-tracking-assignments","-fsched-pressure", +"-mhard-float","-mindirect-branch-register","-mindirect-branch=thunk-inline","-mpreferred-stack-boundary=2","-mpreferred-stack-boundary=3","-mpreferred-stack-boundary=4","-mrecord-mcount","-mindirect-branch=thunk-extern","-mno-fp-ret-in-387","-mskip-rax-setup", +"--param=allow-store-data-races=0","-Wa,arch/x86/kernel/macros.s","-Wa,-" +], "extraArgs":["--gcc-toolchain=/usr"]}}' +``` + +### LLVM + +```sh +git clone https://github.com/llvm/llvm-project.git +cd llvm-project +cmake -Hllvm -BDebug -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;lld' +ln -s Debug/compile_commands.json +``` + +You can filter out some files to speed up indexing. Example initialization options: +```javascript +{"index":{"initialBlacklist":["/(clang|lld|llvm)/(test|unittests)/", "/llvm/(bindings|examples|utils)/", "/StaticAnalyzer/"]}} +``` + +### musl + +```zsh +mkdir Debug; cd Debug +../configure --enable-optimize=no --enable-debug --prefix=~/.local/stow/musl +bear make -j +cd ..; ln -s Debug/compile_commands.json +``` + +### ruby + +```zsh +autoreconf +mkdir Debug; cd Debug +../configure --prefix=/tmp/opt +bear make -j main +cd ..; ln -s Debug/compile_commands.json +``` diff --git a/Project-Setup.md b/Project-Setup.md index 098fc32..611a8d3 100644 --- a/Project-Setup.md +++ b/Project-Setup.md @@ -246,74 +246,3 @@ armv7-linux-gnueabi -U__clang__ -isystem../Config/exec/arm/inc/c ``` - -## `compile_commands.json` examples - -### Linux kernel - -```zsh -wget 'https://git.archlinux.org/svntogit/packages.git/plain/trunk/config?h=packages/linux' -O .config -yes '' | make config -bear make -j bzImage modules -``` - -```zsh -ccls -index ~/Dev/Linux -init='{"clang":{"excludeArgs":[ -"-falign-jumps=1","-falign-loops=1","-fconserve-stack","-fmerge-constants","-fno-code-hoisting","-fno-schedule-insns","-fno-sched-pressure","-fno-var-tracking-assignments","-fsched-pressure", -"-mhard-float","-mindirect-branch-register","-mindirect-branch=thunk-inline","-mpreferred-stack-boundary=2","-mpreferred-stack-boundary=3","-mpreferred-stack-boundary=4","-mrecord-mcount","-mindirect-branch=thunk-extern","-mno-fp-ret-in-387","-mskip-rax-setup", -"--param=allow-store-data-races=0","-Wa,arch/x86/kernel/macros.s","-Wa,-" -], "extraArgs":["--gcc-toolchain=/usr"]}}' -``` - -### LLVM multirepo - -```zsh -git clone https://git.llvm.org/git/llvm.git -cd llvm -git clone https://git.llvm.org/git/clang.git tools/clang -git clone https://git.llvm.org/git/lldb.git tools/lldb -git clone https://git.llvm.org/git/lld.git projects/lld -git clone https://git.llvm.org/git/compiler-rt.git projects/compiler-rt -git clone https://git.llvm.org/git/libcxx.git projects/libcxx -git clone https://git.llvm.org/git/libcxxabi.git projects/libcxxabi - -# cmake -H. -BDebug -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=On -ln -s Debug/compile_commands.json - -# Let clients know llvm/ is the project root, llvm/tools/clang etc are not. -# emacs-ccls knows this file but other clients may require manual configuration. -touch .ccls-root -``` - -You can filter out some files to speed up indexing. Example initialization options: -```javascript -{"index":{"initialBlacklist":["/(clang|lld|llvm)/(test|unittests)/", "/llvm/(bindings|examples|utils)/", "/StaticAnalyzer/"]}} -``` - -### LLVM monorepo - -```zsh -git clone git@github.com:llvm/llvm-project.git - -# cmake -Hllvm -BDebug -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_PROJECTS='llvm;clang' -ln -s llvm/compile_commands.json -``` - -### musl - -```zsh -mkdir Debug; cd Debug -../configure --enable-optimize=no --enable-debug --prefix=~/.local/stow/musl -bear make -j -cd ..; ln -s Debug/compile_commands.json -``` - -### ruby - -```zsh -autoreconf -mkdir Debug; cd Debug -../configure --prefix=/tmp/opt -bear make -j main -cd ..; ln -s Debug/compile_commands.json -``` diff --git a/_Sidebar.md b/_Sidebar.md index ada2d92..e54f545 100644 --- a/_Sidebar.md +++ b/_Sidebar.md @@ -17,6 +17,7 @@ - [[Visual Studio Code]] - [[Monaco Editor | https://github.com/MaskRay/ccls/wiki/Monaco-Editor]] * [[Project Setup]] + - [[Example Projects]] * [[Customization]] * [[Debugging]] * [[FAQ]]