From dfc45729d342f6f4d4d9ea39649c49b49fa178c6 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 29 Oct 2025 16:39:14 +0100 Subject: Initial commit --- kel_cpp_boilerplate/.nix/derivation.nix | 23 +++++++ kel_cpp_boilerplate/SConstruct | 70 +++++++++++++++++++ kel_cpp_boilerplate/c++/SConscript | 32 +++++++++ kel_cpp_boilerplate/c++/blueprints/default_nix.hpp | 24 +++++++ .../c++/blueprints/derivation_nix.hpp | 29 ++++++++ kel_cpp_boilerplate/c++/blueprints/gitignore.hpp | 8 +++ kel_cpp_boilerplate/c++/blueprints/main_cpp.hpp | 36 ++++++++++ kel_cpp_boilerplate/c++/blueprints/sconscript.hpp | 41 +++++++++++ kel_cpp_boilerplate/c++/blueprints/sconstruct.hpp | 79 ++++++++++++++++++++++ kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp | 28 ++++++++ 10 files changed, 370 insertions(+) create mode 100644 kel_cpp_boilerplate/.nix/derivation.nix create mode 100644 kel_cpp_boilerplate/SConstruct create mode 100644 kel_cpp_boilerplate/c++/SConscript create mode 100644 kel_cpp_boilerplate/c++/blueprints/default_nix.hpp create mode 100644 kel_cpp_boilerplate/c++/blueprints/derivation_nix.hpp create mode 100644 kel_cpp_boilerplate/c++/blueprints/gitignore.hpp create mode 100644 kel_cpp_boilerplate/c++/blueprints/main_cpp.hpp create mode 100644 kel_cpp_boilerplate/c++/blueprints/sconscript.hpp create mode 100644 kel_cpp_boilerplate/c++/blueprints/sconstruct.hpp create mode 100644 kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp (limited to 'kel_cpp_boilerplate') diff --git a/kel_cpp_boilerplate/.nix/derivation.nix b/kel_cpp_boilerplate/.nix/derivation.nix new file mode 100644 index 0000000..7b2fd2d --- /dev/null +++ b/kel_cpp_boilerplate/.nix/derivation.nix @@ -0,0 +1,23 @@ +{ stdenv +, scons +, clang-tools +, forstio +}: + +stdenv.mkDerivation { + pname = "kel_cpp_boilerplate"; + version = "0.0.0"; + + nativeBuildInputs = [ + clang-tools + scons + ]; + + buildInputs = [ + forstio.core + forstio.codec + forstio.codec-json + ]; + + src = ./..; +} diff --git a/kel_cpp_boilerplate/SConstruct b/kel_cpp_boilerplate/SConstruct new file mode 100644 index 0000000..eeb0737 --- /dev/null +++ b/kel_cpp_boilerplate/SConstruct @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 + +import sys +import os +import os.path +import glob +import re + +if sys.version_info < (3,): + def isbasestring(s): + return isinstance(s,basestring) +else: + def isbasestring(s): + return isinstance(s, (str,bytes)) + +def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""): + + if isbasestring(filetype): + dir_path = self.Dir('.').abspath + filetype = sorted(glob.glob(dir_path+"/"+filetype)) + + for path in filetype: + target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path ) + if shared: + target_name+='.os' + sources.append( self.SharedObject( target=target_name, source=path ) ) + else: + target_name+='.o' + sources.append( self.StaticObject( target=target_name, source=path ) ) + pass + +def isAbsolutePath(key, dirname, env): + assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,) + +env_vars = Variables( + args=ARGUMENTS +) + +env_vars.Add('prefix', + help='Installation target location of build results and headers', + default='/usr/local/', + validator=isAbsolutePath +); + +env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], + CXX=['c++'], + CPPDEFINES=['SAW_UNIX'], + CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'], + LIBS=[ + 'forstio-core' + ] +) +env.__class__.add_source_files = add_kel_source_files +env.Tool('compilation_db'); +env.cdb = env.CompilationDatabase('compile_commands.json'); + +env.objects = []; +env.sources = []; +env.headers = []; +env.targets = []; + +Export('env') +SConscript('c++/SConscript') +#SConscript('tests/SConscript') + +env.Alias('cdb', env.cdb); +env.Alias('all', [env.targets]); +env.Default('all'); + +env.Alias('install', '$prefix') diff --git a/kel_cpp_boilerplate/c++/SConscript b/kel_cpp_boilerplate/c++/SConscript new file mode 100644 index 0000000..573dda6 --- /dev/null +++ b/kel_cpp_boilerplate/c++/SConscript @@ -0,0 +1,32 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +program_env = env.Clone(); + +program_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +program_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += program_env.sources; +env.headers += program_env.headers; + +## Static lib +objects_static = [] +program_env.add_source_files(objects_static, program_env.sources, shared=False); +env.binary = program_env.Program('#build/kel_cpp_boilerplate', [objects_static]); + +# Set Alias +env.Alias('binary', [env.binary]); + +env.targets += ['binary']; + +# Install +env.Install('$prefix/bin/', [env.binary]); diff --git a/kel_cpp_boilerplate/c++/blueprints/default_nix.hpp b/kel_cpp_boilerplate/c++/blueprints/default_nix.hpp new file mode 100644 index 0000000..312ad7f --- /dev/null +++ b/kel_cpp_boilerplate/c++/blueprints/default_nix.hpp @@ -0,0 +1,24 @@ +#pragma once +#include + +constexpr std::string_view default_nix_file_name = "default.nix"; + +constexpr std::string_view default_nix_file_content = R"( +{ pkgs ? import {} +, stdenv ? pkgs.llvmPackages_19.stdenv +, clang-tools ? pkgs.clang-tools_19 +}: + +let + forstio = (import ((builtins.fetchGit { + url = "git@git.keldu.de:forstio/forstio"; + ref = "dev"; + }).outPath + "/default.nix"){ + inherit stdenv; + }).forstio; +in { + app = pkgs.callPackage ./app/.nix/derivation.nix { + inherit stdenv clang-tools forstio; + }; +} +)"; diff --git a/kel_cpp_boilerplate/c++/blueprints/derivation_nix.hpp b/kel_cpp_boilerplate/c++/blueprints/derivation_nix.hpp new file mode 100644 index 0000000..9715769 --- /dev/null +++ b/kel_cpp_boilerplate/c++/blueprints/derivation_nix.hpp @@ -0,0 +1,29 @@ +#pragma once +#include + +constexpr std::string_view derivation_nix_dir_name = "app/.nix"; +constexpr std::string_view derivation_nix_file_name = "derivation.nix"; + +constexpr std::string_view derivation_nix_file_content = R"( +{ stdenv +, scons +, clang-tools +, forstio +}: + +stdenv.mkDerivation { + // pname = ""; // Actually add a name + version = "0.0.0"; + + nativeBuildInputs = [ + clang-tools + scons + ]; + + buildInputs = [ + forstio.core + ]; + + src = ./..; +} +)"; diff --git a/kel_cpp_boilerplate/c++/blueprints/gitignore.hpp b/kel_cpp_boilerplate/c++/blueprints/gitignore.hpp new file mode 100644 index 0000000..b09b153 --- /dev/null +++ b/kel_cpp_boilerplate/c++/blueprints/gitignore.hpp @@ -0,0 +1,8 @@ +#pragma once +#include + +constexpr std::string_view gitignore_file_name = ".gitignore"; + +constexpr std::string_view gitignore_file_content = R"( +result* +)"; diff --git a/kel_cpp_boilerplate/c++/blueprints/main_cpp.hpp b/kel_cpp_boilerplate/c++/blueprints/main_cpp.hpp new file mode 100644 index 0000000..353a045 --- /dev/null +++ b/kel_cpp_boilerplate/c++/blueprints/main_cpp.hpp @@ -0,0 +1,36 @@ +#pragma once +#include + +constexpr std::string_view main_cpp_dir_name = "app/c++"; +constexpr std::string_view main_cpp_file_name = "main.cpp"; + +constexpr std::string_view main_cpp_file_content = R"( +#include +#include + +namespace kel { +saw::error_or kel_main(int argc, char** argv){ + (void) argc; + (void) argv; + return saw::make_void(); +} +} + +int main(int argc, char** argv){ + auto eov = kel::kel_main(argc, argv); + if(eov.is_error()){ + auto& err = eov.get_error(); + auto err_msg = err.get_message(); + std::cerr<<"[Error]: "< + +constexpr std::string_view sconscript_dir_name = "app/c++"; +constexpr std::string_view sconscript_file_name = "SConscript"; + +constexpr std::string_view sconscript_file_content = R"( +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +program_env = env.Clone(); + +program_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +program_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += program_env.sources; +env.headers += program_env.headers; + +## Static lib +objects_static = [] +program_env.add_source_files(objects_static, program_env.sources, shared=False); +env.binary = program_env.Program('#build/kel_cpp_boilerplate', [objects_static]); + +# Set Alias +env.Alias('binary', [env.binary]); + +env.targets += ['binary']; + +# Install +env.Install('$prefix/bin/', [env.binary]); +)"; diff --git a/kel_cpp_boilerplate/c++/blueprints/sconstruct.hpp b/kel_cpp_boilerplate/c++/blueprints/sconstruct.hpp new file mode 100644 index 0000000..cd47e83 --- /dev/null +++ b/kel_cpp_boilerplate/c++/blueprints/sconstruct.hpp @@ -0,0 +1,79 @@ +#pragma once + +#include + +constexpr std::string_view sconstruct_dir_name = "app"; +constexpr std::string_view sconstruct_file_name = "SConstruct"; + +constexpr std::string_view sconstruct_file_content = R"( +#!/usr/bin/env python3 + +import sys +import os +import os.path +import glob +import re + +if sys.version_info < (3,): + def isbasestring(s): + return isinstance(s,basestring) +else: + def isbasestring(s): + return isinstance(s, (str,bytes)) + +def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""): + + if isbasestring(filetype): + dir_path = self.Dir('.').abspath + filetype = sorted(glob.glob(dir_path+"/"+filetype)) + + for path in filetype: + target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path ) + if shared: + target_name+='.os' + sources.append( self.SharedObject( target=target_name, source=path ) ) + else: + target_name+='.o' + sources.append( self.StaticObject( target=target_name, source=path ) ) + pass + +def isAbsolutePath(key, dirname, env): + assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,) + +env_vars = Variables( + args=ARGUMENTS +) + +env_vars.Add('prefix', + help='Installation target location of build results and headers', + default='/usr/local/', + validator=isAbsolutePath +); + +env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], + CXX=['c++'], + CPPDEFINES=['SAW_UNIX'], + CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'], + LIBS=[ + 'forstio-core' + ] +) +env.__class__.add_source_files = add_kel_source_files +env.Tool('compilation_db'); +env.cdb = env.CompilationDatabase('compile_commands.json'); + +env.objects = []; +env.sources = []; +env.headers = []; +env.targets = []; + +Export('env') +SConscript('c++/SConscript') +#SConscript('tests/SConscript') + +env.Alias('cdb', env.cdb); +env.Alias('all', [env.targets]); +env.Default('all'); + +env.Alias('install', '$prefix') +)"; diff --git a/kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp b/kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp new file mode 100644 index 0000000..972feb7 --- /dev/null +++ b/kel_cpp_boilerplate/c++/kel_cpp_boilerplate.cpp @@ -0,0 +1,28 @@ +#include +#include + +namespace kel { +saw::error_or kel_main(int argc, char** argv){ + (void) argc; + (void) argv; + return saw::make_void(); +} +} + +int main(int argc, char** argv){ + auto eov = kel::kel_main(argc, argv); + if(eov.is_error()){ + auto& err = eov.get_error(); + auto err_msg = err.get_message(); + std::cerr<<"[Error]: "<