diff --git a/CMakeLists.txt b/CMakeLists.txt index 233a1ff86..2c7e31f0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ include_directories( add_subdirectory(src) add_subdirectory(plugins) +add_subdirectory(python) if (BUILD_EXAMPLES) add_subdirectory(examples) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt new file mode 100644 index 000000000..3532426f9 --- /dev/null +++ b/python/CMakeLists.txt @@ -0,0 +1,23 @@ +file(GLOB_RECURSE sources *.c) + +# core runtime headers +file(GLOB_RECURSE headers *.h) + +add_library(vaccel-python SHARED ${headers} ${sources}) +target_compile_options(vaccel-python PUBLIC -Wall -Wextra -Werror -pthread) +target_include_directories(vaccel-python PRIVATE ${CMAKE_SOURCE_DIR}/src) +target_include_directories(vaccel-python PRIVATE ${CMAKE_SOURCE_DIR}/src/include) +set_property(TARGET vaccel-python PROPERTY LINK_FLAGS "-pthread") +set_property(TARGET vaccel-python PROPERTY C_STANDARD 11) +target_link_libraries(vaccel-python) + +# Setup make install +install(TARGETS vaccel-python DESTINATION ${CMAKE_INSTALL_LIBDIR}) +#install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +# Create the pkg-config file +set(DEST_DIR "${CMAKE_INSTALL_PREFIX}") +CONFIGURE_FILE("vaccel-python.pc.in" "vaccel-python.pc" @ONLY) + +# Install the vaccel.pc file +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/vaccel-python.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}) diff --git a/python/helper.c b/python/helper.c new file mode 100644 index 000000000..2f3da8025 --- /dev/null +++ b/python/helper.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include + +__attribute__((constructor)) +void load_vaccel(void) +{ + printf("Loading libvaccel\n"); + void *dl = dlopen("libvaccel.so", RTLD_LAZY | RTLD_GLOBAL); + if (!dl) { + fprintf(stderr, "Could not open libvaccel\n"); + exit(1); + } + + char *pname = getenv("PYTHON_VACCEL_PLUGIN"); + printf("Loading plugin %s\n", pname); + void *plugin = dlopen(pname, RTLD_NOW); + if (!plugin) { + fprintf(stderr, "Failed to load plugin: %s\n", dlerror()); + exit(1); + } + + struct vaccel_plugin **p; + + int (*register_plugin)(struct vaccel_plugin *) = + dlsym(dl, "register_plugin"); + assert(register_plugin); + + p = dlsym(plugin, "vaccel_plugin"); + if (p == NULL) { + fprintf(stderr, "Cannot find vaccel_plugin symbol\n"); + return; + } + assert(p); + + int ret = register_plugin(*p); + assert(!ret); + if (ret) { + fprintf(stderr, "Failed to register plugin\n"); + return; + } + + ret = (*p)->info->init(); + assert(!ret); + if (ret) { + fprintf(stderr, "Failed to initialize plugin\n"); + return; + } +} diff --git a/python/vaccel-python.pc.in b/python/vaccel-python.pc.in new file mode 100644 index 000000000..1e1661a3d --- /dev/null +++ b/python/vaccel-python.pc.in @@ -0,0 +1,11 @@ +prefix=@DEST_DIR@ +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: libvaccel-python +Description: Transparent acceleration for edge and cloud computing hack +Version: 0.4.0 + +Libs: -L${libdir} -lvaccel-python +Cflags: -I${includedir}