MaskRay / ccls

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Apache License 2.0
3.78k stars 260 forks source link

Minimizing the size for distribution #854

Open wisepotato opened 2 years ago

wisepotato commented 2 years ago

I'd like to distribute CCLS + Clang to my coworks in an RPM.

This RPM is currently around 500 MB because i have to bundle it with LLVM.

To minimize the size i've already taken out the build directory after i build llvm project, i take out clang-format, clang etc. Is there any writeup of the headers that you still need to have in ccls to keep it working?

Or a writeup of how to distribute it? It's already quite a pain that the location of clang is hardcoded, but i got around that

madscientist commented 2 years ago

The only thing you need to distribute is the ccls binary, plus the files in the resource directory. When I build ccls it's statically linked with the clang libraries and I don't think I did anything special to make that happen, but you can run ldd ccls (or whatever the equivalent is on MacOS if you're using MacOS... they have to be different).

You may not even need all of the resource files. The resource directory is something like lib/clang/<VER>/include after you've installed clang/llvm. I don't use CUDA and I don't need the sanitizer, xray, or ppc_wrappers, so I delete all those headers.

Regarding being relocatable, that is very annoying. Ideally a resource directory could be a relative path and, if it were, it would be looked up relative to the full path of the ccls binary. But since that's not the case, I use a shell script wrapper to get equivalent behavior. Something like this:

#!/bin/sh

CMD=${0##*/}
BIN=${0%$CMD}
UPPER=$(cd "$BIN".. && pwd)

exec "$UPPER/ccls/bin/ccls" -init "{\"clang\": {\"resourceDir\": \"$UPPER/ccls/clang\"}}" "$@"

then I put that script on my $PATH as .../bin/ccls, and I put the real ccls as .../ccls/bin/ccls and the resource files as .../ccls/clang/include.