diff --git a/CMakeLists.txt b/CMakeLists.txt index ddb4964..675d782 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,46 +2,58 @@ cmake_minimum_required(VERSION 2.8) project(effil) if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Release") + set(CMAKE_BUILD_TYPE "Release") endif(NOT CMAKE_BUILD_TYPE) -if (NOT LUA_INCLUDE_DIR OR NOT LUA_LIBRARY) +if (NOT (LUA_INCLUDE_DIR AND LUA_LIBRARY OR BUILD_ROCK)) find_package(Lua REQUIRED) endif() +# Supress warning CMP0042 +if(APPLE) + set(CMAKE_MACOSX_RPATH 1) +endif() + +# libeffil not directly linked with liblua +if (APPLE AND BUILD_ROCK) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup") +endif() + include_directories(src/cpp libs/sol/single/sol ${LUA_INCLUDE_DIR}) FILE(GLOB SOURCES src/cpp/*.cpp src/cpp/*.h) FILE(GLOB LUA_SOURCES src/lua/*.lua) -if(APPLE) - # Supress warning CMP0042 - set(CMAKE_MACOSX_RPATH 1) -endif() - add_library(effil SHARED ${SOURCES}) target_link_libraries(effil -lpthread ${LUA_LIBRARY} -ldl) +set_target_properties(effil PROPERTIES SUFFIX .so) set(GENERAL "-std=c++14 -DSOL_EXCEPTIONS_SAFE_PROPAGATION") set(ENABLE_WARNINGS "-Wall -Wextra -pedantic") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GENERAL} ${ENABLE_WARNINGS}") +set(CMAKE_CXX_FLAGS "${EXTRA_FLAGS} ${CMAKE_CXX_FLAGS} ${GENERAL} ${ENABLE_WARNINGS}") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Werror -O0 -g -UNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g0 -DNDEBUG") #---------- # TESTS --- #---------- -FILE(GLOB TEST_SOURCES tests/cpp/*.cpp tests/cpp/*.h) -set(GTEST_DIR libs/gtest/googletest) -set(LUA_TESTS tests/lua/tests.lua) +if (NOT BUILD_ROCK) + FILE(GLOB TEST_SOURCES tests/cpp/*.cpp tests/cpp/*.h) + set(GTEST_DIR libs/gtest/googletest) + set(LUA_TESTS tests/lua/tests.lua) -include_directories(${GTEST_DIR}/include ${GTEST_DIR}) -add_executable(tests ${TEST_SOURCES} ${GTEST_DIR}/src/gtest-all.cc) -target_link_libraries(tests effil ${LUA_LIBRARY}) + include_directories(${GTEST_DIR}/include ${GTEST_DIR}) + add_executable(tests ${TEST_SOURCES} ${GTEST_DIR}/src/gtest-all.cc) + target_link_libraries(tests effil ${LUA_LIBRARY}) +endif() #---------- # INSTALL - #---------- -install(FILES ${LUA_TESTS} - DESTINATION ${CMAKE_BINARY_DIR} - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ) +install(FILES src/lua/effil.lua + DESTINATION ${CMAKE_INSTALL_PREFIX} + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + +install(TARGETS effil + DESTINATION ${CMAKE_INSTALL_PREFIX} + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) diff --git a/ci/test_all.sh b/ci/test_all.sh index 9b5d1a7..ad5de3e 100755 --- a/ci/test_all.sh +++ b/ci/test_all.sh @@ -6,8 +6,8 @@ if [ -z "$LUA_BIN" ]; then fi for build_type in debug release; do - mkdir -p $build_type - (cd $build_type && cmake -DCMAKE_BUILD_TYPE=$build_type $@ .. && make -j4 install) + cmake -H. -B$build_type -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=$build_type $@ + cmake --build $build_type --config Release # FIXME: creation of sol::state with luajit in c++ tests # leads to memory corruption segmentation fault @@ -18,5 +18,5 @@ for build_type in debug release; do echo "C++ tests skipped!" fi - (cd $build_type && $LUA_BIN tests.lua) + (cd $build_type && STRESS=1 $LUA_BIN ../tests/lua/run_tests) done diff --git a/rockspecs/effil-1.0-0.rockspec b/rockspecs/effil-1.0-0.rockspec new file mode 100644 index 0000000..8cbb07b --- /dev/null +++ b/rockspecs/effil-1.0-0.rockspec @@ -0,0 +1,46 @@ +package = "effil" +version = "1.0-0" + +source = { + url = "gitrec+http://github.com/effil/effil", + branch = "master" +} + +description = { + summary = "Multithreading library for Lua.", + detailed = [[ + Effil is a lua module for multithreading support. It allows to spawn native threads and provides safe data exchange. + ]], + homepage = "https://github.com/effil/effil", + license = "MIT" +} + +dependencies = { + "lua >= 5.1", "luarocks-fetch-gitrec" +} + +local function get_unix_build() + local install_dir = "rockspeck-content" + return { + type = "cmake", + variables = { + CMAKE_BUILD_TYPE = "Release", + CMAKE_PREFIX_PATH = "$(LUA_BINDIR)/..", + CMAKE_INSTALL_PREFIX = install_dir, + CMAKE_LIBRARY_PATH = "$(LUA_LIBDIR)", + LUA_INCLUDE_DIR = "$(LUA_INCDIR)", + BUILD_ROCK = "yes" + }, + install = { + lua = { install_dir .. "/effil.lua" }, + lib = { install_dir .. "/libeffil.so" } + } + } +end + +build = { + platforms = { + linux = get_unix_build(), + macosx = get_unix_build() + } +} diff --git a/src/lua/effil.lua b/src/lua/effil.lua index 0d466fe..addf9cd 100644 --- a/src/lua/effil.lua +++ b/src/lua/effil.lua @@ -1,16 +1,5 @@ -local function detect_native_lib_ext() - local home = os.getenv("HOME") - if not home then return "dll" end - if string.find(home, "/Users/") then return "dylib" end - if string.find(home, "/home/") then return "so" end - -- TODO: unable to detect os - -- Unix, is it you? - return "so" -end - -package.cpath = package.cpath .. ";./?." .. detect_native_lib_ext() - local capi = require 'libeffil' + local api = { version = "0.1.0", table = capi.table, diff --git a/tests/lua/run_tests b/tests/lua/run_tests new file mode 100755 index 0000000..c9c8122 --- /dev/null +++ b/tests/lua/run_tests @@ -0,0 +1,22 @@ +#!/usr/bin/env lua + +local scripts_path = arg[0]:gsub("/run_tests", "") +local src_path = scripts_path .. "/../.." +package.path = ";" .. scripts_path .. "/?.lua;" + .. src_path .. "/src/lua/?.lua;" + .. src_path .. "/libs/u-test/?.lua" + +require "type" +require "gc" +require "channel" +require "thread" +require "shared-table" +require "metatable" + +if os.getenv("STRESS") then + require "channel-stress" + require "thread-stress" + require "gc-stress" +end + +test.summary() \ No newline at end of file