![]() |
bob.hpp
|
A C++ header only library used for defining build recipes without external dependencies. It provides a collection of classes and functions for executing shell commands, managing dependencies, running tasks in parallel, and building simple CLIs to run project tasks.
Check out the theme song!
Documentation is found here.
This idea is directly stolen from nob.h by mr. tsoding which is a very similar project, but for C.
A simple project using bob.hpp
may look like this:
bob.hpp
is downloaded directly from this repo and added to the project. The bob.cpp
file defines the steps required to build and do other tasks within the project.
To get started, simply include the bob.hpp
file in your main source file and use the GO_REBUILD_YOURSELF
macro. This macro checks if the executable is out of date and rebuilds and re-runs it if necessary, creating a self-rebuilding executable (coined "GO_REBUILD_YOURSELF technology" by mr. tsoding).
A very simple build script could look like this:
To run the build script do
After the initial compilation, the bob
executable will check if its source code has changed and rebuild itself before running if needed. There is therefore no need to rebuild the executable manually after the initial bootstrapping.
This build script simply runs the following command:
bob.hpp
relies solely on C and C++ standard headers.bob::Cmd
class provides a simple way to execute system commands synchronously (run()
) or asynchronously (run_async()
) and to capture their output.bob::CmdRunner
class enables you to run multiple commands concurrently, utilizing multiple processor cores to speed up build processes.bob::Recipe
class helps manage build dependencies by checking file timestamps to determine if a build step is needed. This is useful for compiling source files only when they are newer than their corresponding object files.bob::Cli
and bob::CliCommand
classes make it easy to create structured command-line tools with subcommands, flags, and help messages, providing a user-friendly interface to your build tool.mkdirs
), finding binaries in the system's $PATH
(search_path
), and locating the root of a Git repository (git_root
).bob::term
namespace offers a set of constants for adding colors and styling to your terminal output, making your build logs more readable.You can customize the rebuild command used by GO_REBUILD_YOURSELF
by defining BOB_REBUILD_CMD
. The command is a C++ initializer list of strings, with _PROGRAM_
and _SOURCE_
placeholders for the executable and source file names, respectively.
Alternatively, you can provide a custom RebuildConfig
object directly to the go_rebuild_yourself
function instead of using the GO_REBUILD_YOURSELF
macro: