Open alexrp opened 3 years ago
For anyone else running into this and looking for a workaround, -gen-cdb-fragment-path cdb
will cause Clang to output JSON fragment files to the cdb
directory that you can then stitch together to form a complete compilation database. This comes with the caveat that you have to clear both that directory and the Zig cache directory completely when compiler flags change or .c
/.cxx
files are added/removed.
+1 for this feature. That would be very helpful to integrate zig with other parts of the C ecosystem. For example, using clang-tidy.
+1
+1
I would add that this LSP integration issue is the main reason keeping me from integrating into my existing C projects
It would really be nice to have clangd or some other LSP work with zig built C projects
I have builds produce a working compile_commands.json for my zig-built-cpp projects. I do this:
"-gen-cdb-fragment-path", ".cache/cdb"
to my addCSourceFiles flags (make sure you don't have -MJ
too)(echo \[ ; cat .cache/cdb/* ; echo {}\]) | perl -0777 -pe 's/,\n\{\}//igs' | jq . | grep -v 'no-default-config' > compile_commands.json
(or something similar) after each buildI guess this could be better integrated into Zig's build system, but it works just fine for me without any special support from zig.
Recently a user made a compile_commands.json
generator which may help this issue.
https://github.com/the-argus/raylib-chipmunk-crossplatform-template/blob/main/build/compile_commands.zig
@kassane i have no clue how you found and noticed my little repo but thank you :)
I have refined and packaged that functionality for easy use with zig v0.11.0 now: https://github.com/the-argus/zig-compile-commands
It doesn't know anything about what zig cc
commands actually get executed, so it's more of a mimicry of what the zig compiler is actually doing in order to put enough into compile_commands to satisfy clangd specifically for my project. Currently it doesn't support config headers and I'm sure there will be other holes to patch.
+1
Hey, please check out my PR for this feature: #18391. We can continue the discussion there.
Update: @alexrp pointed out in a comment that #18391 doesn't actually address this particular issue. #18391 covers the zig build
use case while this issue is focused on zig cc
which has to do with the Clang driver.
Note how only one file entry is emitted by Zig.