ewaldhorn/c_with_zig
Compiling C programs with Zig
This is a simple C template I use for new projects. It assumes Zig and Task are installed.
Zig is used as the compiler / runner of the C code while Task is used instead of the traditional Make file. Why? Because I like Task, that's why!
I'm using Zig 0.13.0 as the C compiler in this project on a Mac, but it should work on just about any platform.
Task is a brilliant tool written in Go that allows you to execute tasks defined in a simple YAML file. I put all the commands I use in there, since it just makes life easier.
Use task by itself in the terminal to get a list of available tasks. Some of the tasks are:
task To see the list of taskstask clean to remove build artifactstask build To build the binaries to the 'bin' foldertask run To run the 'main.c' file using Zigtask test To run the C-based teststask license To display the licensetask readme To display the readmeIf you are interested, you also look at using the Zig build system as a really nice replacement for traditional make files. Zig is a great toolchain and programming language, but you don't need to use Zig for your C projects if you don't want to. Instead, you can leverage the power of the toolchain with this project and keep using C as your favourite language.
I have included a sample build.zig file that handles basic build tasks for this C project.
Use zig build to build the hello_from_zig_build binary in the zig-out/bin directory. I have not yet been able to get Zig to place binaries anywhere else.
Of course, make is not going anywhere, so I've included an example Makefile as well, for those that prefer to keep using it, it is a well-known and powerful tool after all.