summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/.nix/derivation.nix39
-rw-r--r--tools/SConscript30
-rw-r--r--tools/SConstruct82
-rw-r--r--tools/c_lang_bind.cpp49
4 files changed, 200 insertions, 0 deletions
diff --git a/tools/.nix/derivation.nix b/tools/.nix/derivation.nix
new file mode 100644
index 0000000..561e9d6
--- /dev/null
+++ b/tools/.nix/derivation.nix
@@ -0,0 +1,39 @@
+{ lib
+, stdenv
+, scons
+, clang-tools
+, version
+, forstio
+}:
+
+stdenv.mkDerivation {
+ pname = "forstio-examples-tools";
+ inherit version;
+ src = ./..;
+
+ enableParallelBuilding = true;
+
+ nativeBuildInputs = [
+ scons
+ clang-tools
+ forstio.tools
+ ];
+
+ buildInputs = [
+ forstio.core
+ forstio.codec
+ ];
+
+ buildPhase = ''
+ scons all
+ ls
+ build/forstio_examples_c_lang_bindings
+ '';
+
+ installPhase = ''
+ mkdir -p $out
+ cp forstio_example* $out/
+ '';
+
+ outputs = ["out"];
+}
diff --git a/tools/SConscript b/tools/SConscript
new file mode 100644
index 0000000..6b9473c
--- /dev/null
+++ b/tools/SConscript
@@ -0,0 +1,30 @@
+#!/bin/false
+
+import os
+import os.path
+import glob
+
+
+Import('env')
+
+dir_path = Dir('.').abspath
+
+# Environment for base library
+core_env = env.Clone();
+
+core_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
+core_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
+
+env.sources += core_env.sources;
+env.headers += core_env.headers;
+
+objects_static = []
+env.tools = core_env.Program('#build/forstio_examples_c_lang_bindings', ['c_lang_bind.cpp']);
+
+# Set Alias
+env.Alias('tools', [env.tools]);
+
+env.targets += ['tools'];
+
+# Install
+env.Install('$prefix/bin/', [env.tools]);
diff --git a/tools/SConstruct b/tools/SConstruct
new file mode 100644
index 0000000..3ce306b
--- /dev/null
+++ b/tools/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, value, env):
+ assert os.path.isabs(value), "%r must have absolute path syntax" % (key,)
+
+env_vars = Variables(
+ args=ARGUMENTS
+)
+
+env_vars.Add('platform',
+ help='Specifies which platform to target',
+ default='unix'
+)
+
+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=[],
+ CPPDEFINES=[],
+ CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'],
+ LIBS=[
+ 'forstio-core',
+ 'forstio-codec'
+ ]
+)
+env.__class__.add_source_files = add_kel_source_files
+env.Tool('compilation_db');
+env.cdb = env.CompilationDatabase('compile_commands.json');
+
+if env['platform'] == 'unix':
+ env.Append(CPPDEFINES = ['SAW_UNIX'])
+#endif
+
+env.objects = [];
+env.sources = [];
+env.headers = [];
+env.targets = [];
+
+Export('env')
+SConscript('SConscript')
+
+# Aliasing
+env.Alias('cdb', env.cdb);
+env.Alias('all', [env.targets]);
+env.Default('all');
+
+env.Alias('install', '$prefix')
diff --git a/tools/c_lang_bind.cpp b/tools/c_lang_bind.cpp
new file mode 100644
index 0000000..f0ecf0d
--- /dev/null
+++ b/tools/c_lang_bind.cpp
@@ -0,0 +1,49 @@
+#include <forstio/buffer.hpp>
+#include <forstio/codec/schema.hpp>
+#include <forstio/tools/c_gen_iface.hpp>
+
+#include <iostream>
+#include <fstream>
+
+namespace sch {
+using namespace saw::schema;
+
+using ExStruct = Struct<
+ Member<Float64, "dob">,
+ Member<Int16, "int24">
+>;
+
+using ExInterface = Interface<
+ Member<Function<Int32, ExStruct>, "foo">,
+ Member<Function<UInt64, Float32>, "bar">
+>;
+}
+
+int main(){
+ using namespace saw;
+
+ ring_buffer src{4096*1024};
+ ring_buffer hdr{4096*1024};
+ language_binding_config cfg;
+ cfg.prefix = "forstio_example";
+ auto eov = language_binding<sch::ExInterface, binding::SyncC>::generate(hdr, src,cfg);
+ if(eov.is_error()){
+ auto& err = eov.get_error();
+ std::cerr<<"Error: "<<err.get_category();
+ auto msg = err.get_message();
+ if(msg.size() > 0){
+ std::cerr<<" - "<<msg;
+ }
+ std::cerr<<std::endl;
+ return err.get_id();
+ }
+
+ std::ofstream src_file{cfg.prefix + ".cpp"};
+ src_file << convert_to_string(src);
+ src_file.close();
+ std::ofstream hdr_file{cfg.prefix + ".hpp"};
+ hdr_file << convert_to_string(hdr);
+ hdr_file.close();
+
+ return 0;
+}