Skip to content
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

refactor libsinsp sub-components #14

Merged
merged 9 commits into from
Mar 29, 2021
153 changes: 64 additions & 89 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,72 +146,75 @@ include(ExternalProject)

option(USE_BUNDLED_DEPS "Enable bundled dependencies instead of using the system ones" ON)

#
# LuaJIT
#
option(USE_BUNDLED_LUAJIT "Enable building of the bundled LuaJIT" ${USE_BUNDLED_DEPS})
option(WITH_CHISEL "Include chisel implementation" OFF)
if(WITH_CHISEL)
#
# LuaJIT
#
option(USE_BUNDLED_LUAJIT "Enable building of the bundled LuaJIT" ${USE_BUNDLED_DEPS})

if(NOT USE_BUNDLED_LUAJIT)
find_path(LUAJIT_INCLUDE luajit.h PATH_SUFFIXES luajit-2.0 luajit)
find_library(LUAJIT_LIB NAMES luajit luajit-5.1)
if(LUAJIT_INCLUDE AND LUAJIT_LIB)
message(STATUS "Found LuaJIT: include: ${LUAJIT_INCLUDE}, lib: ${LUAJIT_LIB}")
else()
# alternatively try stock Lua
find_package(Lua51)
set(LUAJIT_LIB ${LUA_LIBRARY})
set(LUAJIT_INCLUDE ${LUA_INCLUDE_DIR})
if(NOT USE_BUNDLED_LUAJIT)
find_path(LUAJIT_INCLUDE luajit.h PATH_SUFFIXES luajit-2.0 luajit)
find_library(LUAJIT_LIB NAMES luajit luajit-5.1)
if(LUAJIT_INCLUDE AND LUAJIT_LIB)
message(STATUS "Found LuaJIT: include: ${LUAJIT_INCLUDE}, lib: ${LUAJIT_LIB}")
else()
# alternatively try stock Lua
find_package(Lua51)
set(LUAJIT_LIB ${LUA_LIBRARY})
set(LUAJIT_INCLUDE ${LUA_INCLUDE_DIR})

if(NOT ${LUA51_FOUND})
message(FATAL_ERROR "Couldn't find system LuaJIT or Lua")
if(NOT ${LUA51_FOUND})
message(FATAL_ERROR "Couldn't find system LuaJIT or Lua")
endif()
endif()
endif()
else()
set(LUAJIT_SRC "${PROJECT_BINARY_DIR}/luajit-prefix/src/luajit/src")
message(STATUS "Using bundled LuaJIT in '${LUAJIT_SRC}'")
set(LUAJIT_INCLUDE "${LUAJIT_SRC}")
if(NOT WIN32)
set(LUAJIT_LIB "${LUAJIT_SRC}/libluajit.a")
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
ExternalProject_Add(luajit
GIT_REPOSITORY "https://github.com/moonjit/moonjit"
GIT_TAG "2.1.2"
PATCH_COMMAND sed -i "s/luaL_reg/luaL_Reg/g" ${PROJECT_SOURCE_DIR}/userspace/libsinsp/chisel.cpp && sed -i "s/luaL_reg/luaL_Reg/g" ${PROJECT_SOURCE_DIR}/userspace/libsinsp/lua_parser.cpp && sed -i "s/luaL_getn/lua_objlen /g" ${PROJECT_SOURCE_DIR}/userspace/libsinsp/lua_parser_api.cpp
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMD_MAKE}
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${LUAJIT_LIB}
INSTALL_COMMAND "")
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
ExternalProject_Add(luajit
GIT_REPOSITORY "https://github.com/linux-on-ibm-z/LuaJIT.git"
GIT_TAG "v2.1"
PATCH_COMMAND sed -i "s/luaL_reg/luaL_Reg/g" ${PROJECT_SOURCE_DIR}/userspace/libsinsp/chisel.cpp && sed -i "s/luaL_reg/luaL_Reg/g" ${PROJECT_SOURCE_DIR}/userspace/libsinsp/lua_parser.cpp && sed -i "s/luaL_getn/lua_objlen /g" ${PROJECT_SOURCE_DIR}/userspace/libsinsp/lua_parser_api.cpp
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMD_MAKE}
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${LUAJIT_LIB}
INSTALL_COMMAND "")
else()
set(LUAJIT_SRC "${PROJECT_BINARY_DIR}/luajit-prefix/src/luajit/src")
message(STATUS "Using bundled LuaJIT in '${LUAJIT_SRC}'")
set(LUAJIT_INCLUDE "${LUAJIT_SRC}")
if(NOT WIN32)
set(LUAJIT_LIB "${LUAJIT_SRC}/libluajit.a")
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
ExternalProject_Add(luajit
GIT_REPOSITORY "https://github.com/moonjit/moonjit"
GIT_TAG "2.1.2"
PATCH_COMMAND sed -i "s/luaL_reg/luaL_Reg/g" ${PROJECT_SOURCE_DIR}/userspace/chisel/chisel.cpp && sed -i "s/luaL_reg/luaL_Reg/g" ${PROJECT_SOURCE_DIR}/userspace/chisel/lua_parser.cpp && sed -i "s/luaL_getn/lua_objlen /g" ${PROJECT_SOURCE_DIR}/userspace/chisel/lua_parser_api.cpp
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMD_MAKE}
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${LUAJIT_LIB}
INSTALL_COMMAND "")
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x")
ExternalProject_Add(luajit
GIT_REPOSITORY "https://github.com/linux-on-ibm-z/LuaJIT.git"
GIT_TAG "v2.1"
PATCH_COMMAND sed -i "s/luaL_reg/luaL_Reg/g" ${PROJECT_SOURCE_DIR}/userspace/chisel/chisel.cpp && sed -i "s/luaL_reg/luaL_Reg/g" ${PROJECT_SOURCE_DIR}/userspace/chisel/lua_parser.cpp && sed -i "s/luaL_getn/lua_objlen /g" ${PROJECT_SOURCE_DIR}/userspace/chisel/lua_parser_api.cpp
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMD_MAKE}
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${LUAJIT_LIB}
INSTALL_COMMAND "")
else()
ExternalProject_Add(luajit
URL "https://github.com/LuaJIT/LuaJIT/archive/v2.0.3.tar.gz"
URL_HASH "SHA256=8da3d984495a11ba1bce9a833ba60e18b532ca0641e7d90d97fafe85ff014baa"
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMD_MAKE}
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${LUAJIT_LIB}
INSTALL_COMMAND "")
endif()
else()
ExternalProject_Add(luajit
URL "https://github.com/LuaJIT/LuaJIT/archive/v2.0.3.tar.gz"
URL_HASH "SHA256=8da3d984495a11ba1bce9a833ba60e18b532ca0641e7d90d97fafe85ff014baa"
CONFIGURE_COMMAND ""
BUILD_COMMAND ${CMD_MAKE}
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${LUAJIT_LIB}
INSTALL_COMMAND "")
set(LUAJIT_LIB "${LUAJIT_SRC}/lua51.lib")
ExternalProject_Add(luajit
URL "https://github.com/LuaJIT/LuaJIT/archive/v2.0.3.tar.gz"
URL_HASH "SHA256=8da3d984495a11ba1bce9a833ba60e18b532ca0641e7d90d97fafe85ff014baa"
CONFIGURE_COMMAND ""
BUILD_COMMAND msvcbuild.bat
BUILD_BYPRODUCTS ${LUAJIT_LIB}
BINARY_DIR "${LUAJIT_SRC}"
INSTALL_COMMAND "")
endif()
else()
set(LUAJIT_LIB "${LUAJIT_SRC}/lua51.lib")
ExternalProject_Add(luajit
URL "https://github.com/LuaJIT/LuaJIT/archive/v2.0.3.tar.gz"
URL_HASH "SHA256=8da3d984495a11ba1bce9a833ba60e18b532ca0641e7d90d97fafe85ff014baa"
CONFIGURE_COMMAND ""
BUILD_COMMAND msvcbuild.bat
BUILD_BYPRODUCTS ${LUAJIT_LIB}
BINARY_DIR "${LUAJIT_SRC}"
INSTALL_COMMAND "")
endif()
endif()

Expand Down Expand Up @@ -359,34 +362,6 @@ if(NOT WIN32 AND NOT APPLE)
endif()
endif()

#
# ncurses, keep it simple for the moment
#
if(NOT WIN32)
option(USE_BUNDLED_NCURSES "Enable building of the bundled ncurses" ${USE_BUNDLED_DEPS})

if(NOT USE_BUNDLED_NCURSES)
set(CURSES_NEED_NCURSES TRUE)
find_package(Curses REQUIRED)
message(STATUS "Found ncurses: include: ${CURSES_INCLUDE_DIR}, lib: ${CURSES_LIBRARIES}")
else()
set(CURSES_BUNDLE_DIR "${PROJECT_BINARY_DIR}/ncurses-prefix/src/ncurses")
set(CURSES_INCLUDE_DIR "${CURSES_BUNDLE_DIR}/include/")
set(CURSES_LIBRARIES "${CURSES_BUNDLE_DIR}/lib/libncurses.a")

message(STATUS "Using bundled ncurses in '${CURSES_BUNDLE_DIR}'")

ExternalProject_Add(ncurses
URL "http://download.draios.com/dependencies/ncurses-6.0-20150725.tgz"
URL_MD5 "32b8913312e738d707ae68da439ca1f4"
CONFIGURE_COMMAND ./configure --without-cxx --without-cxx-binding --without-ada --without-manpages --without-progs --without-tests --with-terminfo-dirs=/etc/terminfo:/lib/terminfo:/usr/share/terminfo
BUILD_COMMAND ${CMD_MAKE}
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${CURSES_LIBRARIES}
INSTALL_COMMAND "")
endif()
endif()

if(NOT WIN32 AND NOT APPLE)
#
# libb64
Expand Down
2 changes: 1 addition & 1 deletion driver/ppm_events_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ or GPL2.txt for full copies of the license.
#ifdef __KERNEL__
#include <linux/types.h>
#else
#include "../userspace/common/sysdig_types.h"
#include "../userspace/common/types.h"
#endif

/*
Expand Down
3 changes: 0 additions & 3 deletions userspace/libsinsp/chisel.cpp → userspace/chisel/chisel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ limitations under the License.
#include "filterchecks.h"
#include "table.h"

#ifdef HAS_CHISELS
#define HAS_LUA_CHISELS

#ifdef HAS_LUA_CHISELS
Expand Down Expand Up @@ -1795,5 +1794,3 @@ bool sinsp_chisel::get_nextrun_args(OUT string* args)
*args = m_lua_cinfo->m_nextrun_args;
return m_lua_cinfo->m_has_nextrun_args;
}

#endif // HAS_CHISELS
12 changes: 9 additions & 3 deletions userspace/libsinsp/chisel.h → userspace/chisel/chisel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ limitations under the License.

#pragma once

#ifdef HAS_CHISELS
/*!
\brief Add a new directory containing chisels.

\parame front_add if true, the chisel directory is added at the front of
the search list and therefore gets priority.

\note This function is not reentrant.
*/
void chisel_add_dir(string dirname, bool front_add);

class sinsp_filter_check;
class sinsp_evt_formatter;
Expand Down Expand Up @@ -164,5 +172,3 @@ class SINSP_PUBLIC sinsp_chisel

/*@}*/

#endif // HAS_CHISELS

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ limitations under the License.
#include "analyzer.h"
#endif

#ifdef HAS_CHISELS
#define HAS_LUA_CHISELS

#ifdef HAS_LUA_CHISELS
Expand Down Expand Up @@ -1592,4 +1591,3 @@ int lua_cbacks::push_metric(lua_State *ls)

#endif // HAS_ANALYZER
#endif // HAS_LUA_CHISELS
#endif // HAS_CHISELS
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ limitations under the License.

#pragma once

#ifdef HAS_CHISELS

class lua_cbacks
{
public:
Expand Down Expand Up @@ -73,5 +71,3 @@ class lua_cbacks
static int get_thread_table_int(lua_State *ls, bool include_fds, bool barebone);
};

#endif // HAS_CHISELS

Loading