Skip to content

Simplify luos_engine compilation as a shared lib #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: rc_3.1.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
8 changes: 8 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -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;
}
42 changes: 42 additions & 0 deletions src/shared_lib_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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 -shared -fPIC -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 -shared -fPIC -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 -v -shared -fPIC -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)
env.Append(LINKFLAGS=["-fPIC"])
env.Append(BUILD_FLAGS=["-fPIC"])