Skip to content
/ c-project-template Public template

A minimal C project supporting make, unit testing and github workflows

Notifications You must be signed in to change notification settings

xyderos/c-project-template

Repository files navigation

A simple project template for testing libraries in C using the LLVM toolset, Make and valgrind

  • Have the LLVM toolchain installed eg clangd for IDE extensions, clang-format for formatting the document, lldb-vscode for spacemacs and lldb as well as clang-format extensions in vscode

Explanation by structure

  1. The pipeline
  • There is a simple CI/CD pipeline that initially sets a DEPLOYMENT flag to development so we can get a comprehensive list of warnings in the pipeline
  • We also use Valgrind for memory leaks or issues, as well as check for unit testing
  • We need to export the LD_LIBRARY_PATH in BOTH the local (your pc) and remote (the pipeline) enviroments (I am currently doing that manually per working directory)
  • Then we build with some production flags and finally deliver the library
  1. .vscode/
  • We need this folder in order to tell lldb-vscode how to act when debugging
  • We use the ./vscode/jaunch.json to hook a launch process by invoking the test recipe (which builds the test executable to run the tests) from the Makefile (more on that later)
  • We use the ./vscode/tasks.json to define the build task which builds a test executable with development flags
  1. The src directory
  • Each file shall have its correposnding header and a vice versa (I believe this logic gives a modern approach like C# or Java ehile it doesnt increase the actual complexity)
  • Go wild, the build recipe will take care of the whole building process (more on that later)
  1. the tests directory
  • Declare a START_TEST with a corresponding name within the arguments
  • Add the test case in the suite function by name
  1. The weird Makefile
  • Although the makefile is structured in a weird way eg traversing all the files upon each build, which makes it not suitable for big projects, it does remind of an abstration and thus making it easier to extend it
  • It can distinguish the production and development env variables
  • memory check with build the library, tests, run them and also generate a Valgrind report
  1. The LLVM part
  • There are a few solid configurations in order to boost your C++ knowledge by adding a lot of warnings and standards
  • Nice to use a formatter for the whole project

Feel free to open a PR if you want to extend the template!

About

A minimal C project supporting make, unit testing and github workflows

Topics

Resources

Stars

Watchers

Forks