1
0
Fork
You've already forked cbuild
0
CBuild is a small command line C build utility.
  • C++ 96.4%
  • Nix 2.5%
  • Shell 1.1%
2026年04月22日 19:12:58 +01:00
logo Added logos 2026年03月28日 22:04:31 +00:00
src Changed OPT_UseNix back to true 2026年04月22日 11:44:48 +01:00
.gitignore Added a specific commit for default.nix to use 2026年04月14日 00:37:56 +01:00
build.sh Changed defaults to use the more common gcc instead of clang 2026年04月16日 09:56:37 +01:00
cbuild.toml Finished adding and testing new toml parser 2026年04月20日 01:32:17 +01:00
default.nix Updated default.nix 2026年04月22日 11:46:19 +01:00
LICENSE Initial commit 2026年01月08日 21:41:04 +00:00
README.md Updated README.md and added a shell.nix 2026年04月22日 19:12:58 +01:00
shell.nix Updated README.md and added a shell.nix 2026年04月22日 19:12:58 +01:00

CBuild

logo

NOTICE

I will eventually change the name and licensing of CBuild in the near future as/if the project grows.

What is it?

CBuild is a small command-line build utility I made for myself as a small and portable alternative to make and cmake. Keep in mind that this is not being pitched as a competitior in the slightest.

Originally this was written in C but my original code was not the best when it came to scalability, plus I want to get more into writing C++ code, so I thought I might as well do a full rewrite and language change.

What chenges came from the rewrite?

With the rewrite I also added a couple QoL changes, main big ones include:

  • Better config file structure, along with a better and more expandable parser.
  • Better source directory includes. Now you just specify a source directory and CBuild will recursivley search it.
  • More options to set, mainly adding seperate flags and test cases for debug and release builds.
  • Better info printing, CBuild now displays a full command that it'll use for building.
  • Better code (I think), although it can always be improved. Most of it is making the Builder a class (fancy).

Usage and building

To build the project you can use CBuild, but obviously to build it for the first time building it, so I included a build.sh script. Run:

bash build.sh

and it'll create a cbuild binary in the current directory.

I have tried to keep decent compatibility with the old CBuild (apart from the config file), so for the 0 people that use it in scripts, its not gonna be broken.

Running CBuild is pretty straightforward:

cbuild -<options> @<standard> %<git_branch> <name>

When CBuild checks the arguments passed to it, it checks what type of argument it is with the leading character:

  • - means its an options argument.
  • @ means its a standard (C/C++ standard) argument.
  • % means its a git branch argument (name to use for the "main" branch)
  • Default means its a name argument that sets the projects name.

The options you can have (and string together in one argument):

  • i initialises a project.
  • o overwrites a project file (cbuild.toml) and makes a new one. Has to be used alongside i. Good for making old CBuild projects into modern ones.
  • p purge everything in the current directory. Has to be used alongside i.
  • c make the new project be a C project instead of C++.
  • g initiate git in the current directory and create a branch with a select name (git support needs to be compiled in).
  • n create a basic shell.nix file (nix support needs to be compiled in).
  • r build a release build of the project.
  • d do a dry run (print the build command but DONT run it).
  • t perform a test run on the newly built program.

The standard argument is preceeded with an @, and then the standard you want the project to be afterwards.

A few usage examples:

  • cbuild -cip @c99 test makes a C project called test with the C99 standard. It also purges everything in the current directory.
  • cbuild -io test overwrites the project file in the current directory, and makes the new project file use the name test.
  • cbuild -rt builds a release build of the project and runs it afterwards.
  • cbuild @c++20 builds a debug build using the C++20 standard.

Intitialising will make a project tree of:

.
|-- cbuild.toml
|-- src/
| \-- main.cpp (or main.c)
\-- target/
 |-- debug/
 \-- release/

To the keen-eyed individual, it is blatantly obvious I ripped off the cargo project tree. The main.cpp file will have whatever extension is set to default for C++, and if its a C project it will just be main.c instead. The main project file has a small Hello World program already written inside, ripping cargo off even more. The release builds will go into target/release/ and debug builds wil go into target/debug/, obviously.

The default project file is:

[project]
name = "a.out"
source = "src"
compiler = "g++"
standard = "default"
defenitions = []
[flags]
debug = "-Wall -g"
release = "-O2 -Wall"
global = none
[file]
extension = "cpp"
[test]
debug = none
release = none

All the options I believe to be pretty self explanatory. In the future I'll add being able to change these with environment variables, but it is not added yet.

Future of this project?

Im currently still studying in college, so there wont be any frequent updates, although I do have a lot in mind for this, some stuff ambitious other stuff not as much.

Stuff I do wanna add though will include:

  • Other language support, maybe.
  • Certain C/C++ project types, such as ncurses or sdl2 and whatnot, which will add all the needed flags for that library.
  • Reading environment variables and using that to assign certain internal variables, kinda like how make and cmake do it.

Some notes

  • If this project grows to be big enough I might change the license to be GPLv3+, although right now I'm not bothered enough.
  • Will take name suggestions, if its even worth changing the name. CBuild is a bit generic.