Hello, I wanted to check out zig to build my c projects so that I can avoid CMake.
My only problem was that I couldn't find anything from the standard that talks about this, only this cool link:
https://github.com/the-argus/raylib-chipmunk-crossplatform-template/blob/main/build/compile_commands.zig
So does zig support generating compile_commands.json out of the box or shall I use this script?
p.s. looking forward for the package manager so that I can get rid of vcpkg!
#Zig build C project with compile_commands.json
1 messages · Page 1 of 1 (latest)
I dont think there an option for that yet. I looked through the source code and didn't find any reference to that and there is no issue created on the zig github for that
what's compile_commands.json?
you can try using something like Bear https://github.com/rizsotto/Bear
oh thats neat. heres a super rough alternative that i did. ive since significantly improved things, but its sitting unpushed on a packed up pc
https://github.com/We-the-People-civ4col-mod/Mod/blob/zig/build.zig#L105-L139
i dont know if that template's supports caching, but mine does through a pretty hacky mechanism tbh
https://github.com/ziglang/zig/issues/9323 I think the solution might be here
it is used by clangd LSP
thanks!
i dont think bear will help here
idk, im currently on windows, im using a super convoluted setup
cmake, visual studio, msbuild, clang power tools, batch
ill try to move it to zig...
Yeah, just checked and there is an issue opened. It doesn't work with Zig
I'll see if it's easy to add to zig. I need it myself as well (when mixing c and zig in one project)
it'll help me get rid of cmake and msbuild lol 😆
i use a VS plugin to generate them
i think u need to zig cc -MJ
to generate
here's my convoluted setup lol
hmm I took at look at it and it's not that hard to just add the files, include flags and linker flags to create a compile_commands.json file from a build.zig file. However if you want the zig added defines to be included then it's harder. Zig adds NDEBUG and you can choose which c compiler to use and all that, but that part is linked to the caching system. So if you run zig build once then it will no longer output that data. You can see that if you do zig build --verbose-cc
thanks so much! I'll have a look soon!
https://codeberg.org/john-nanney/zig_writecc
is this how you'd do it?
this uses vcpkg