summaryrefslogtreecommitdiff
path: root/modules/lang
diff options
context:
space:
mode:
authorClaudius 'keldu' Holeksa <mail@keldu.de>2024-09-12 17:30:21 +0200
committerClaudius 'keldu' Holeksa <mail@keldu.de>2024-09-12 17:30:21 +0200
commit18bf2f08ee86fd1ed0a663d256e1c7d3142827d7 (patch)
treea8c0aca4dc1439ccfc6b746cafbb087f84a3e9bd /modules/lang
parent2e3efd182c00eb12305644d855a2f19594a0627d (diff)
lang module separating from tools
Diffstat (limited to 'modules/lang')
-rw-r--r--modules/lang/.nix/derivation.nix45
-rw-r--r--modules/lang/SConstruct82
-rw-r--r--modules/lang/c++/SConscript33
-rw-r--r--modules/lang/c++/c_common.hpp7
-rw-r--r--modules/lang/c++/c_rpc.hpp7
-rw-r--r--modules/lang/c++/c_transfer.hpp8
-rw-r--r--modules/lang/examples/SConscript31
-rw-r--r--modules/lang/tests/SConscript31
-rw-r--r--modules/lang/tests/c_transfer.cpp132
9 files changed, 376 insertions, 0 deletions
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<typename Interface, typename T>
+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 <forstio/test/suite.hpp>
+#include <forstio/codec/json/json.hpp>
+
+#include "../c++/c_transfer.hpp"
+
+#include <iostream>
+
+namespace {
+namespace schema {
+using namespace saw::schema;
+
+using TestStruct = Struct<
+ Member<Int32, "a">,
+ Member<Float64, "b">
+>;
+
+using TestArray = Array<
+ Int64, 1
+>;
+
+using TestStructArray = Struct<
+ Member<TestArray, "array">,
+ Member<UInt64, "un_int_num">
+>;
+
+using TestStructMore = Struct<
+ Member<Int64, "int">,
+ Member<UInt16, "uint">,
+ Member<Float32, "float">,
+ Member<Float64, "double">
+>;
+
+/*
+using TestEmptyInterface = Interface<>;
+
+using TestOneFunctionInterface = Interface<
+ Member<Function<Int32, Int32>, "one">
+>;
+
+using TestStructFunctionInterface = Interface<
+ Member<Function<TestStruct, Int32>, "two">
+>;
+
+using TestArrayFunctionInterface = Interface<
+ Member<Function<TestArray, Int32>, "three">
+>;
+
+using TestStructArrayFunctionInterface = Interface<
+ Member<Function<TestStructArray, Int32>, "three">
+>;
+
+using TestMultiFunctionInterface = Interface<
+ Member<Function<TestArray, Float32>, "foo">,
+ Member<Function<Float64, Int8>, "bar">,
+ Member<Function<UInt32, TestArray>, "baz">,
+ Member<Function<UInt32, Float64>, "banana">,
+ Member<Function<TestStructMore, Float32>, "struct">
+>;
+*/
+}
+
+/*
+template<typename Schema>
+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<Schema, encode::NativeRaw, binding::SyncC>::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<schema::TestEmptyInterface>(res,src);
+
+ std::cout<<"\n"<<res<<"\n"<<std::endl;
+ std::cout<<"\nSource\n"<<src<<"\n"<<std::endl;
+}
+
+SAW_TEST("CIface One Function Interface"){
+ using namespace saw;
+
+ std::string res;
+ std::string src;
+ test_generate<schema::TestOneFunctionInterface>(res, src);
+ std::cout<<"\n"<<res<<"\n"<<std::endl;
+ std::cout<<"\nSource\n"<<src<<"\n"<<std::endl;
+}
+
+SAW_TEST("CIface Multi Function Interface"){
+ using namespace saw;
+
+ std::string res;
+ std::string src;
+ test_generate<schema::TestMultiFunctionInterface>(res, src);
+ std::cout<<"\n"<<res<<"\n"<<std::endl;
+ std::cout<<"\nSource\n"<<src<<"\n"<<std::endl;
+}
+
+SAW_TEST("CIface Array Function Interface"){
+ using namespace saw;
+
+ std::string res;
+ std::string src;
+ test_generate<schema::TestArrayFunctionInterface>(res, src);
+ std::cout<<"\n"<<res<<"\n"<<std::endl;
+ std::cout<<"\nSource\n"<<src<<"\n"<<std::endl;
+}
+
+SAW_TEST("CIface Struct Array Function Interface"){
+ using namespace saw;
+
+ std::string res;
+ std::string src;
+ test_generate<schema::TestStructArrayFunctionInterface>(res, src);
+ std::cout<<"\n"<<res<<"\n"<<std::endl;
+ std::cout<<"\nSource\n"<<src<<"\n"<<std::endl;
+}
+*/
+}