From 18bf2f08ee86fd1ed0a663d256e1c7d3142827d7 Mon Sep 17 00:00:00 2001 From: Claudius 'keldu' Holeksa Date: Thu, 12 Sep 2024 17:30:21 +0200 Subject: lang module separating from tools --- modules/lang/.nix/derivation.nix | 45 +++++++++++++ modules/lang/SConstruct | 82 +++++++++++++++++++++++ modules/lang/c++/SConscript | 33 ++++++++++ modules/lang/c++/c_common.hpp | 7 ++ modules/lang/c++/c_rpc.hpp | 7 ++ modules/lang/c++/c_transfer.hpp | 8 +++ modules/lang/examples/SConscript | 31 +++++++++ modules/lang/tests/SConscript | 31 +++++++++ modules/lang/tests/c_transfer.cpp | 132 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 376 insertions(+) create mode 100644 modules/lang/.nix/derivation.nix create mode 100644 modules/lang/SConstruct create mode 100644 modules/lang/c++/SConscript create mode 100644 modules/lang/c++/c_common.hpp create mode 100644 modules/lang/c++/c_rpc.hpp create mode 100644 modules/lang/c++/c_transfer.hpp create mode 100644 modules/lang/examples/SConscript create mode 100644 modules/lang/tests/SConscript create mode 100644 modules/lang/tests/c_transfer.cpp diff --git a/modules/lang/.nix/derivation.nix b/modules/lang/.nix/derivation.nix new file mode 100644 index 0000000..54ebb5e --- /dev/null +++ b/modules/lang/.nix/derivation.nix @@ -0,0 +1,45 @@ +{ lib +, stdenv +, scons +, clang-tools +, version +, build_examples ? false +, forstio +}: + +stdenv.mkDerivation { + pname = "forstio-tools"; + inherit version; + src = ./..; + + enableParallelBuilding = true; + + nativeBuildInputs = [ + scons + clang-tools + ]; + + buildInputs = [ + forstio.core + forstio.async + forstio.io + forstio.codec + forstio.codec-json + ]; + + doCheck = true; + checkPhase = '' + scons test + ./bin/tests + ''; + + buildPhase = '' + scons build_examples=${build_examples} + ''; + + installPhase = '' + scons prefix=$out build_examples=${build_examples} install + ''; + + outputs = ["out" "dev"]; +} diff --git a/modules/lang/SConstruct b/modules/lang/SConstruct new file mode 100644 index 0000000..fa67084 --- /dev/null +++ b/modules/lang/SConstruct @@ -0,0 +1,82 @@ +#!/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_vars.Add( + BoolVariable('build_examples', + help='Build examples', + default=False + ) +); + +env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], + CXX=['c++'], + CPPDEFINES=['SAW_UNIX'], + CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'], + LIBS=[ + 'forstio-core', + 'forstio-async', + 'forstio-codec', + 'forstio-codec-json' + ] +); +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') +SConscript('examples/SConscript') + +env.Alias('cdb', env.cdb); +env.Alias('all', [env.targets]); +env.Default('all'); + +env.Alias('install', '$prefix') diff --git a/modules/lang/c++/SConscript b/modules/lang/c++/SConscript new file mode 100644 index 0000000..9ff46d0 --- /dev/null +++ b/modules/lang/c++/SConscript @@ -0,0 +1,33 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +tools_env = env.Clone(); + +tools_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +tools_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += tools_env.sources; +env.headers += tools_env.headers; + +## Static lib +objects_static = [] +tools_env.add_source_files(objects_static, tools_env.sources, shared=False); +env.library_static = tools_env.StaticLibrary('#build/forstio-tools', [objects_static]); + +# Set Alias +env.Alias('library_tools', [env.library_static]); + +env.targets += ['library_tools']; + +# Install +env.Install('$prefix/lib/', [env.library_static]); +env.Install('$prefix/include/forstio/tools/', [tools_env.headers]); diff --git a/modules/lang/c++/c_common.hpp b/modules/lang/c++/c_common.hpp new file mode 100644 index 0000000..6999126 --- /dev/null +++ b/modules/lang/c++/c_common.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace saw { +namespace lang { +struct RemoteC {}; +} +} diff --git a/modules/lang/c++/c_rpc.hpp b/modules/lang/c++/c_rpc.hpp new file mode 100644 index 0000000..75c2f7c --- /dev/null +++ b/modules/lang/c++/c_rpc.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "c_rpc_types.hpp" + +namespace saw { + +} diff --git a/modules/lang/c++/c_transfer.hpp b/modules/lang/c++/c_transfer.hpp new file mode 100644 index 0000000..6c2061b --- /dev/null +++ b/modules/lang/c++/c_transfer.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include "c_common.hpp" + +namespace saw { +template +struct language {}; +} diff --git a/modules/lang/examples/SConscript b/modules/lang/examples/SConscript new file mode 100644 index 0000000..99561e7 --- /dev/null +++ b/modules/lang/examples/SConscript @@ -0,0 +1,31 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +examples_env = env.Clone(); + +examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += examples_env.sources; +env.headers += examples_env.headers; + +objects_static = [] +examples_env.cli_mod = examples_env.Program('#bin/cli_mod_example', ['cli_mod.cpp', env.library_static]); + +# Set Alias +env.examples = [examples_env.cli_mod]; +env.Alias('examples', env.examples); + +if env["build_examples"]: + env.targets += ['examples']; + env.Install('$prefix/bin/', env.examples); +#endif diff --git a/modules/lang/tests/SConscript b/modules/lang/tests/SConscript new file mode 100644 index 0000000..f8ffc92 --- /dev/null +++ b/modules/lang/tests/SConscript @@ -0,0 +1,31 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +test_cases_env = env.Clone(); + +test_cases_env.Append(LIBS=['forstio-test']); + +test_cases_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +test_cases_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += test_cases_env.sources; +env.headers += test_cases_env.headers; + +objects_static = [] +test_cases_env.add_source_files(objects_static, test_cases_env.sources, shared=False); +test_cases_env.program = test_cases_env.Program('#bin/tests', [objects_static, env.library_static]); + +# Set Alias +env.Alias('test', test_cases_env.program); +env.Alias('check', test_cases_env.program); + +env.targets += ['test','check']; diff --git a/modules/lang/tests/c_transfer.cpp b/modules/lang/tests/c_transfer.cpp new file mode 100644 index 0000000..43c4a3e --- /dev/null +++ b/modules/lang/tests/c_transfer.cpp @@ -0,0 +1,132 @@ +#include +#include + +#include "../c++/c_transfer.hpp" + +#include + +namespace { +namespace schema { +using namespace saw::schema; + +using TestStruct = Struct< + Member, + Member +>; + +using TestArray = Array< + Int64, 1 +>; + +using TestStructArray = Struct< + Member, + Member +>; + +using TestStructMore = Struct< + Member, + Member, + Member, + Member +>; + +/* +using TestEmptyInterface = Interface<>; + +using TestOneFunctionInterface = Interface< + Member, "one"> +>; + +using TestStructFunctionInterface = Interface< + Member, "two"> +>; + +using TestArrayFunctionInterface = Interface< + Member, "three"> +>; + +using TestStructArrayFunctionInterface = Interface< + Member, "three"> +>; + +using TestMultiFunctionInterface = Interface< + Member, "foo">, + Member, "bar">, + Member, "baz">, + Member, "banana">, + Member, "struct"> +>; +*/ +} + +/* +template +void test_generate(std::string& res, std::string& src){ + using namespace saw; + + ring_buffer r_buff{4u * 1024u * 1024u}; + ring_buffer r_src_buff{4u * 1024u * 1024u}; + + { + auto eov = language_binding::generate(r_buff, r_src_buff, {"prefix"}); + SAW_EXPECT(eov.is_value(), std::string{"Couldn't generate interface info: "} + std::string{eov.get_error().get_message()}); + } + + res = convert_to_string(r_buff); + src = convert_to_string(r_src_buff); +} +*/ + +/* +SAW_TEST("CIface Empty Interface"){ + using namespace saw; + + std::string res; + std::string src; + test_generate(res,src); + + std::cout<<"\n"<(res, src); + std::cout<<"\n"<(res, src); + std::cout<<"\n"<(res, src); + std::cout<<"\n"<(res, src); + std::cout<<"\n"<