Skip to content

ewaldhorn/c_with_zig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic C Template

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!

Zig

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

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.

Available tasks

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 tasks
  • task clean to remove build artifacts
  • task build To build the binaries to the 'bin' folder
  • task run To run the 'main.c' file using Zig
  • task test To run the C-based tests
  • task license To display the license
  • task readme To display the readme

Going further

If 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.

What about make

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.

About

Compiling C programs with Zig

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published