From 86e1eeffb2c14c59e744f7773fb8e9f477986195 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Mon, 4 Apr 2016 15:07:16 -0700 Subject: [PATCH] Statically link in lpeg lua library --- CMakeLists.txt | 3 ++- scripts/build-lpeg.sh | 9 ++++++++- userspace/digwatch/CMakeLists.txt | 3 +++ userspace/digwatch/digwatch.cpp | 2 ++ userspace/digwatch/lpeg.h | 6 ++++++ 5 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 userspace/digwatch/lpeg.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ec39d3fb..3eb5d19b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,6 +129,7 @@ ExternalProject_Add(luajit BUILD_IN_SOURCE 1 INSTALL_COMMAND "") +set (LPEG_SRC "${PROJECT_BINARY_DIR}/lpeg-prefix/src/lpeg") ExternalProject_Add(lpeg DEPENDS luajit URL "https://s3.amazonaws.com/download.draios.com/dependencies/lpeg-1.0.0.tar.gz" @@ -136,7 +137,7 @@ ExternalProject_Add(lpeg BUILD_COMMAND LUA_INCLUDE=${LUAJIT_INCLUDE} ${PROJECT_SOURCE_DIR}/scripts/build-lpeg.sh BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "" - INSTALL_COMMAND cp lpeg.so re.lua ${PROJECT_SOURCE_DIR}/userspace/digwatch/lua) + INSTALL_COMMAND "") diff --git a/scripts/build-lpeg.sh b/scripts/build-lpeg.sh index 8d2037a6..b0c990c0 100755 --- a/scripts/build-lpeg.sh +++ b/scripts/build-lpeg.sh @@ -5,6 +5,13 @@ gcc -O2 -fPIC -I$LUA_INCLUDE -c lpcode.c -o lpcode.o gcc -O2 -fPIC -I$LUA_INCLUDE -c lpprint.c -o lpprint.o gcc -O2 -fPIC -I$LUA_INCLUDE -c lptree.c -o lptree.o gcc -O2 -fPIC -I$LUA_INCLUDE -c lpvm.c -o lpvm.o -gcc -shared -o lpeg.so -L/usr/local/lib lpcap.o lpcode.o lpprint.o lptree.o lpvm.o + + +# For building lpeg.so, which we don't need now that we're statically linking lpeg.a into digwatch +#gcc -shared -o lpeg.so -L/usr/local/lib lpcap.o lpcode.o lpprint.o lptree.o lpvm.o +#gcc -shared -o lpeg.so -L/usr/local/lib lpcap.o lpcode.o lpprint.o lptree.o lpvm.o + +/usr/bin/ar cr lpeg.a lpcap.o lpcode.o lpprint.o lptree.o lpvm.o +/usr/bin/ranlib lpeg.a chmod ug+w re.lua diff --git a/userspace/digwatch/CMakeLists.txt b/userspace/digwatch/CMakeLists.txt index 08bc7298..387bdad2 100644 --- a/userspace/digwatch/CMakeLists.txt +++ b/userspace/digwatch/CMakeLists.txt @@ -5,10 +5,13 @@ include_directories(${PROJECT_SOURCE_DIR}/../sysdig/userspace/libscap) include_directories(${PROJECT_SOURCE_DIR}/../sysdig/userspace/libsinsp) include_directories("${PROJECT_BINARY_DIR}/userspace/digwatch") include_directories("${CURL_INCLUDE_DIR}") +include_directories("${LPEG_SRC}") add_executable(digwatch formats.cpp fields.cpp rules.cpp digwatch.cpp) target_link_libraries(digwatch sinsp) +target_link_libraries(digwatch "${LPEG_SRC}/lpeg.a") + set(DIGWATCH_LUA_MAIN "rule_loader.lua") configure_file(config_digwatch.h.in config_digwatch.h) diff --git a/userspace/digwatch/digwatch.cpp b/userspace/digwatch/digwatch.cpp index b25e4748..a84ee7d2 100644 --- a/userspace/digwatch/digwatch.cpp +++ b/userspace/digwatch/digwatch.cpp @@ -14,6 +14,7 @@ extern "C" { #include "lua.h" #include "lualib.h" #include "lauxlib.h" +#include "lpeg.h" } #include @@ -279,6 +280,7 @@ int digwatch_init(int argc, char **argv) // Initialize Lua interpreter ls = lua_open(); luaL_openlibs(ls); + luaopen_lpeg(ls); add_lua_path(ls, lua_dir); rules = new digwatch_rules(inspector, ls, lua_main_filename); diff --git a/userspace/digwatch/lpeg.h b/userspace/digwatch/lpeg.h new file mode 100644 index 00000000..2a166a94 --- /dev/null +++ b/userspace/digwatch/lpeg.h @@ -0,0 +1,6 @@ +#pragma once + +#include "lua.h" + +int luaopen_lpeg (lua_State *L); +