Skip to content
/ B_ldr Public

A build sytem written in C++ that just requires a Cpp Compiler and uses C++ as script.

Notifications You must be signed in to change notification settings

Rrrinav/B_ldr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Builder (bld)

A simple C++ build system that uses C++ as the scripting language thus doesn't need any new tools to be installed. Moreover, it is easier because well, it uses C++ as a scripting language.

Because Tsoding said you should write your own build system.

Features

  • Command Execution: Execute system commands and shell commands with ease.
  • Logging: Log messages with different severity levels (INFO, WARNING, ERROR).
  • Process Management: Wait for processes to complete and handle their exit statuses.
  • Output Handling: Capture and read the output of executed commands.
  • System Metadata: Print system metadata including OS, compiler, and architecture information.

Installation

To use bld in your project, include the bld.hpp header file and define B_LDR_IMPLEMENTATION in one of your source files to include the implementation.

#define B_LDR_IMPLEMENTATION
#include "bld.hpp"

Usage

Logging

Log messages with different severity levels:

bld::log(bld::Log_type::INFO, "This is an info message.");
bld::log(bld::Log_type::WARNING, "This is a warning message.");
bld::log(bld::Log_type::ERROR, "This is an error message.");

Command Execution

Create and execute commands:

bld::Command cmd("ls", "-la");
int result = bld::execute(cmd);

Execute shell commands:

std::string shell_cmd = "echo Hello, World!";
int result = bld::execute_shell(shell_cmd);

Process Output

Capture the output of a command:

std::string output;
bld::Command cmd("ls", "-la");
bool success = bld::read_process_output(cmd, output);

Capture the output of a shell command:

std::string output;
std::string shell_cmd = "echo Hello, World!";
bool success = bld::read_shell_output(shell_cmd, output);

incremental

int main(int argc, char *argv[])
{
  BLD_REBUILD_YOURSELF_ONCHANGE();

  bld::Dep_graph dg;

  dg.add_dep({"main",
             {"main.cpp", "./foo.o", "./bar.o"},
             {"g++", "main.cpp", "-o", "main", "foo.o", "bar.o"}});

  dg.add_dep({"./foo.o",
             {"foo.cpp"},
             {"g++", "-c", "foo.cpp", "-o", "foo.o"}});

  dg.add_dep({"./bar.o",
             {"bar.cpp"},
             {"g++", "-c", "bar.cpp", "-o", "bar.o"}});

  dg.build_all();

  return 0;
}
$ls
main.cpp foo.cpp foo.hpp bar.cpp bar.hpp

File System

Check if an executable is up-to-date with it's file: This specific example tracks it's own executable file.

 // Requires arguments for main function
int main(int argc, char *argv[])
{
  // Check if the executable needs to be rebuilt and restart if necessary
  BLD_REBUILD_YOURSELF_ONCHANGE();
}

System Metadata

Print system metadata:

bld::print_metadata();

TODO

  • Parallel incremental builds
  • Fully cross-platform functions

Author

Rinav (GitHub: rrrinav)

About

A build sytem written in C++ that just requires a Cpp Compiler and uses C++ as script.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages