From ff066b06a82f0ab330dab3ceb2d4b7132727f861 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 10 Jul 2024 14:15:40 +0200 Subject: Initial commit --- .gitignore | 27 ++++++++++++++++ default.nix | 32 ++++++++++++++++++ tools/.nix/derivation.nix | 39 ++++++++++++++++++++++ tools/SConscript | 30 +++++++++++++++++ tools/SConstruct | 82 +++++++++++++++++++++++++++++++++++++++++++++++ tools/c_lang_bind.cpp | 49 ++++++++++++++++++++++++++++ 6 files changed, 259 insertions(+) create mode 100644 .gitignore create mode 100644 default.nix create mode 100644 tools/.nix/derivation.nix create mode 100644 tools/SConscript create mode 100644 tools/SConstruct create mode 100644 tools/c_lang_bind.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..808aaa5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# obj +*.so +*.o +*.a +*.os + +# scons +.sconsign.dblite + +# nix +result* + +# regular target which is not really used +build +bin + +# compile commands +.cache +compile_commands.json + +# default log dumps +log + +# Doc ignores +docs/html +docs/latex +docs/xml diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..0f97734 --- /dev/null +++ b/default.nix @@ -0,0 +1,32 @@ +{ pkgs ? import {} +, stdenv ? pkgs.llvmPackages_16.stdenv +, clang-tools ? pkgs.clang-tools_16 +, forstio ? (import ((builtins.fetchGit { + url = "git@git.keldu.de:forstio/forstio"; + ref = "dev"; + }).outPath + "/default.nix"){ + inherit stdenv; + inherit clang-tools; + }).forstio +}: + +let + version = "0.0.0"; +in +rec { + forstio-examples = { + tools = pkgs.callPackage ./tools/.nix/derivation.nix { + inherit stdenv; + inherit clang-tools; + inherit version; + inherit forstio; + }; + }; + + all = pkgs.symlinkJoin { + name = "forstio_examples-${version}"; + paths = [ + forstio-examples.tools + ]; + }; +} 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 +#include +#include + +#include +#include + +namespace sch { +using namespace saw::schema; + +using ExStruct = Struct< + Member, + Member +>; + +using ExInterface = Interface< + Member, "foo">, + Member, "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::generate(hdr, src,cfg); + if(eov.is_error()){ + auto& err = eov.get_error(); + std::cerr<<"Error: "< 0){ + std::cerr<<" - "<