From 24d3476b6b807705ceafaf6192ab1482ac1aa929 Mon Sep 17 00:00:00 2001 From: Nicolas Rabault Date: Thu, 1 Feb 2024 12:22:07 +0100 Subject: [PATCH] Enable shared libs compilation by compiling directly the lib --- platformio.ini | 23 +++++++++++++++++++++-- src/README.md | 8 ++++++++ src/main.c | 9 +++++++++ src/shared_lib_build.py | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/README.md create mode 100644 src/main.c create mode 100644 src/shared_lib_build.py diff --git a/platformio.ini b/platformio.ini index a9c82b9a1..8cde18176 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,9 +10,28 @@ [common] -default_envs = native +default_envs = native_lib -[env:native] +[env:native_lib] +platform = native + +lib_deps= + serial_network + ws_network + robus_network + +lib_extra_dirs = + $PROJECT_DIR/network/ # include the folder hosting robus_network + $PROJECT_DIR/../ # include the folder hosting Luos_engine + +test_build_src = false + +build_flags = + -D LUOSHAL=NATIVE + +extra_scripts = src/shared_lib_build.py + +[env:tests_debug] platform = native lib_deps= diff --git a/src/README.md b/src/README.md new file mode 100644 index 000000000..f54e26660 --- /dev/null +++ b/src/README.md @@ -0,0 +1,8 @@ +This folder doesn't contain any Luos_engine code, you should have a look at: + +- [engine](../engine) folder if you are interested in the core code of Luos_engine. +- [network](../network) folder if you are interested in the network code of Luos_engine. +- [tool_services](../tool_services) folder if you are interested in the Gate or Pipe code of Luos_engine. +- [examples](../../examples) folder if you are interested in examples of Luos_engine usage. + +This folder only contain specific files allowing to compile Luos_engine as a shared lib. diff --git a/src/main.c b/src/main.c new file mode 100644 index 000000000..e01a0bb89 --- /dev/null +++ b/src/main.c @@ -0,0 +1,9 @@ +// This file only allow to compile the project. +#include "serial_network.h" +#include "ws_network.h" +#include "robus_network.h" + +int main(void) +{ + return 0; +} diff --git a/src/shared_lib_build.py b/src/shared_lib_build.py new file mode 100644 index 000000000..af2c92053 --- /dev/null +++ b/src/shared_lib_build.py @@ -0,0 +1,41 @@ +Import("env") +import os +import platform as pf +import click + +def shared_lib(source, target, env): + # Try to find the luos_engine.a somwhere on $BUILD_DIR/*/ archive and save it to a libPath variable + libPath = None + for root, dirs, files in os.walk(env.subst("$BUILD_DIR")): + for file in files: + if file.endswith("luos_engine.a"): + libPath = os.path.join(root, file) + break + if libPath is not None: + break + # Try to find all the network libs + networklibs = [] + for root, dirs, files in os.walk(env.subst("$BUILD_DIR")): + for file in files: + if file.endswith("network.a"): + networklibs.append(os.path.join(root, file)) + break + + if libPath is not None: + # Convert the luos_engine.a archive to a shared library + if (pf.system() == 'Windows'): + env.Execute("gcc -O2 -shared -o $BUILD_DIR/libluos_engine.dll " + libPath) + click.secho("* Luos engine shared library available in " + str(env.subst("$BUILD_DIR")) + "/libluos_engine.dll .", fg="green") + elif (pf.system() == 'Linux'): + env.Execute("gcc -O2 -shared -o $BUILD_DIR/libluos_engine.so " + libPath) + click.secho("* Luos engine shared library available in " + str(env.subst("$BUILD_DIR")) + "/libluos_engine.so .", fg="green") + elif (pf.system() == 'Darwin'): + for networklib in networklibs: + env.Execute("gcc -O2 -shared -o $BUILD_DIR/" + os.path.basename(networklib)[0:-10] + "_luos_engine.dylib " + libPath + " " + networklib) + + click.secho("\n") + click.secho("Luos engine shared libraries available in " + str(env.subst("$BUILD_DIR")) + "/ :", underline=True) + for networklib in networklibs: + click.secho("\t* " + os.path.basename(networklib)[0:-10] + "_luos_engine.dylib ", fg="green") + +env.AddPostAction("$PROGPATH", shared_lib)