[PATCH] D154903: clangd: Provide the resource dir via environment variable
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 16 01:13:38 PDT 2023
sammccall added a comment.
I'm a little nervous about this. On the one hand it's simple and I want to get you unblocked but:
- the more ways to initialize resource dir and the more places this needs to be propagated to, the more likely this is to get out of sync
- we might want to remove the need for resource-dir one day and embed the built-in-headers in the binary, it's not clear what this would do in such a world.
- I don't understand how the technique this enables can be robust. Using the built-in headers from one compiler with a different compiler may work sometimes but is going to break in mysterious ways. I don't want to stop you using this technique, but if we add a feature for this people will want support in using it correctly.
It seems like you can *almost* do this with no new support though - the driver will always be invoked by clangd, so you can ask the OS where the invoking binary is. This assumes:
- you're on an OS where this is reasonably possible
- you're not customizing the resource-dir path, so we can use the same heuristics clangd does to find it
Proof of concept (works on my machine!) to access the resource dir from the driver - this just sets it as an include path but you could do whatever:
#!/bin/bash
# /home/sammccall/qd/driver.sh
echo "Target: x86_64-linux-gnu" >&2
echo "#include \"...\" search starts here:" >&2
echo "#include <...> search starts here:" >&2
echo $(dirname $(dirname $(readlink /proc/$PPID/exe)))/lib/clang/*/include >&2
echo "End of search list." >&2
# /home/sammccall/qd/.clangd
CompileFlags:
Compiler: /home/sammccall/qd/driver.sh
$ env CLANGD_FLAGS=--query-driver="/home/sammccall/qd/driver.sh" clangd --check=/home/sammccall/qd/hello.cc -log=verbose
...
I[10:09:51.174] Failed to find compilation database for /home/sammccall/qd/hello.cc
V[10:09:51.177] System include extraction: target extracted: "x86_64-linux-gnu"
V[10:09:51.177] System include extraction: adding /usr/lib/clangd/lib/clang/16/include
I[10:09:51.177] System includes extractor: successfully executed /home/sammccall/qd/driver.sh
got includes: "/usr/lib/clangd/lib/clang/16/include"
got target: "x86_64-linux-gnu"
I[10:09:51.177] Generic fallback command is: [/home/sammccall/qd] /home/sammccall/qd/driver.sh -isystem /usr/lib/clangd/lib/clang/16/include --target=x86_64-linux-gnu -resource-dir=/usr/lib/clangd/lib/clang/16 -- /home/sammccall/qd/hello.cc
...
If this doesn't seem workable, can you explain a bit more about your setup?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154903/new/
https://reviews.llvm.org/D154903
More information about the cfe-commits
mailing list