Skip to content

Commit

Permalink
Enable shared libs compilation by compiling directly the lib
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed Feb 1, 2024
1 parent b6a0900 commit 24d3476
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
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;
}
41 changes: 41 additions & 0 deletions src/shared_lib_build.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 24d3476

Please sign in to comment.