Skip to content
Fangrui Song edited this page Nov 10, 2019 · 4 revisions

Linux kernel

defconfig

# 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 .<target>.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:

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:

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

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' <other options>
ln -s Debug/compile_commands.json

You can filter out some files to speed up indexing. Example initialization options:

{"index":{"initialBlacklist":["/(clang|lld|llvm)/(test|unittests)/", "/llvm/(bindings|examples|utils)/", "/StaticAnalyzer/"]}}

musl

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

autoreconf
mkdir Debug; cd Debug
../configure --prefix=/tmp/opt
bear make -j main
cd ..; ln -s Debug/compile_commands.json
Clone this wiki locally