Tarantool development patches archive
 help / color / mirror / Atom feed
From: Igor Munkin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>,
	Timur Safin <tsafin@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH 2/3] build: adjust LuaJIT build system
Date: Thu,  4 Feb 2021 02:22:16 +0300	[thread overview]
Message-ID: <9426dbd66c51aa466ab89272894ad33a7b22edec.1612390822.git.imun@tarantool.org> (raw)
In-Reply-To: <cover.1612390822.git.imun@tarantool.org>

LuaJIT submodule is bumped to introduce the following changes:
* test: run luacheck static analysis via CMake
* test: fix warnings found with luacheck in misclib*
* test: run LuaJIT tests via CMake
* build: replace GNU Make with CMake
* build: preserve the original build system

Since LuaJIT build system is ported to CMake in scope of the changeset
mentioned above, the module building the LuaJIT bundled in Tarantool is
completely reworked. There is no option to build Tarantool against
another prebuilt LuaJIT due to a91962c0df8f649f7ebee2fb2c90c0e3810acf5f
('Until Bug#962848 is fixed, don't try to compile with external
LuaJIT'), so all redundant options defining the libluajit to be used in
Tarantool are dropped with the related auxiliary files.

To run LuaJIT related tests or static analysis for Lua files within
LuaJIT repository, <LuaJIT-test> and <LuaJIT-luacheck> targets are used
respectively as a dependency of the corresponding Tarantool targets.

As an additional dependency to run LuaJIT tests, prove[1] utility is
required, so the necessary binary packages are added to the lists with
build requirements.

[1]: https://metacpan.org/pod/TAP::Harness#prove

Closes #4862
Closes #5470

Signed-off-by: Igor Munkin <imun@tarantool.org>
---
 .luacheckrc         |   1 -
 CMakeLists.txt      |   2 +-
 cmake/luajit.cmake  | 375 ++++++++++++--------------------------------
 cmake/luatest.cpp   |  80 ----------
 debian/control      |   2 +
 rpm/tarantool.spec  |   2 +
 src/CMakeLists.txt  |  28 ++--
 test/CMakeLists.txt |  18 +--
 third_party/luajit  |   2 +-
 9 files changed, 119 insertions(+), 391 deletions(-)
 delete mode 100644 cmake/luatest.cpp

diff --git a/.luacheckrc b/.luacheckrc
index b75d89a0c..4d5593a83 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -35,7 +35,6 @@ exclude_files = {
     "test/box/*.test.lua",
     "test/engine/*.test.lua",
     "test/engine_long/*.test.lua",
-    "test/luajit-tap/**/*.lua",
     "test/replication/*.test.lua",
     "test/sql/**/*.lua",
     "test/swim/*.test.lua",
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4fbd19558..b9f4ec465 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -159,7 +159,7 @@ add_custom_target(ctags DEPENDS tags)
 # Enable 'make luacheck' target.
 #
 
-add_custom_target(luacheck)
+add_custom_target(luacheck DEPENDS LuaJIT-luacheck)
 add_custom_command(TARGET luacheck
     COMMAND ${LUACHECK} --codes --config "${PROJECT_SOURCE_DIR}/.luacheckrc" "${PROJECT_SOURCE_DIR}"
     COMMENT "Perform static analysis of Lua code"
diff --git a/cmake/luajit.cmake b/cmake/luajit.cmake
index 1c7784e11..455b4967b 100644
--- a/cmake/luajit.cmake
+++ b/cmake/luajit.cmake
@@ -1,306 +1,125 @@
-
 #
 # LuaJIT configuration file.
 #
-# A copy of LuaJIT is maintained within Tarantool
-# source. It's located in third_party/luajit.
-#
-# Instead of this copy, Tarantool can be compiled
-# with a system-wide LuaJIT, or LuaJIT at a given
-# prefix. This is used when compiling Tarantool
-# as part of a distribution, e.g. Debian.
-#
-# To explicitly request use of the bundled LuaJIT,
-# add -DENABLE_BUNDLED_LUAJIT=True to CMake
-# configuration flags.
-# To explicitly request use of LuaJIT at a given
-# prefix, use -DLUAJIT_PREFIX=/path/to/LuaJIT.
-#
-# These two options are incompatible with each other.
-#
-# If neither of the two options is given, this script
-# first attempts to use the system-installed LuaJIT
-# and, in case it is not present or can not be used,
-# falls back to the bundled one.
+# A copy of LuaJIT is maintained within Tarantool source tree.
+# It's located in third_party/luajit.
 #
 # LUAJIT_FOUND
 # LUAJIT_LIBRARIES
 # LUAJIT_INCLUDE_DIRS
 #
+# This stuff is extremely fragile, proceed with caution.
 
-#
-# Bundled LuaJIT paths.
-#
-set (LUAJIT_BUNDLED_PREFIX "${PROJECT_BINARY_DIR}/third_party/luajit/src")
-set (LUAJIT_BUNDLED_LIB "${LUAJIT_BUNDLED_PREFIX}/libluajit.a")
-
-macro (luajit_use_bundled)
-    set (LUAJIT_PREFIX "${LUAJIT_BUNDLED_PREFIX}")
-    set (LUAJIT_INCLUDE "${PROJECT_SOURCE_DIR}/third_party/luajit/src")
-    set (LUAJIT_LIB "${LUAJIT_BUNDLED_LIB}")
-    set (ENABLE_BUNDLED_LUAJIT True)
-endmacro()
-
-#
-# LuaJIT testing routine
-# (see cmake/luatest.cpp for a description).
-#
-macro (luajit_test)
-    file (READ "${CMAKE_SOURCE_DIR}/cmake/luatest.cpp" LUAJIT_TEST)
-    set (CMAKE_REQUIRED_LIBRARIES "${LUAJIT_LIB}")
-    if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
-        set (CMAKE_REQUIRED_LIBRARIES "-ldl ${CMAKE_REQUIRED_LIBRARIES}")
-    endif()
-    set (CMAKE_REQUIRED_INCLUDES "${LUAJIT_INCLUDE}")
-    CHECK_CXX_SOURCE_RUNS ("${LUAJIT_TEST}" LUAJIT_RUNS)
-    unset (LUAJIT_TEST)
-    unset (CMAKE_REQUIRED_LIBRARIES)
-    unset (CMAKE_REQUIRED_INCLUDES)
-endmacro()
-
-#
-# Check if there is a system LuaJIT availaible and
-# usable with the server (determined by a compiled test).
-#
-macro (luajit_try_system)
-    find_path (LUAJIT_INCLUDE lj_obj.h PATH_SUFFIXES luajit-2.0 luajit)
-    find_library (LUAJIT_LIB NAMES luajit luajit-5.1 PATH_SUFFIXES x86_64-linux-gnu)
-    if (LUAJIT_INCLUDE AND LUAJIT_LIB)
-        message (STATUS "include: ${LUAJIT_INCLUDE}, lib: ${LUAJIT_LIB}")
-        message (STATUS "Found a system-wide LuaJIT.")
-        luajit_test()
-        if ("${LUAJIT_RUNS}" STREQUAL "1")
-            message (STATUS "System-wide LuaJIT at ${LUAJIT_LIB} is suitable for use.")
-        else()
-            message (WARNING "System-wide LuaJIT at ${LUAJIT_LIB} is NOT suitable for use, using the bundled one.")
-	        luajit_use_bundled()
-        endif()
-    else()
-        message (FATAL_ERROR "Not found a system LuaJIT")
-        #luajit_use_bundled()
-    endif()
-endmacro()
-
-#
-# Check if there is a usable LuaJIT at the given prefix path.
-#
-macro (luajit_try_prefix)
-    find_path (LUAJIT_INCLUDE "lua.h" ${LUAJIT_PREFIX} NO_DEFAULT_PATH)
-    find_library (LUAJIT_LIB "luajit" ${LUAJIT_PREFIX} NO_DEFAULT_PATH)
-    if (LUAJIT_INCLUDE AND LUAJIT_LIB)
-        include_directories("${LUAJIT_INCLUDE}")
-        luajit_test()
-        if (LUAJIT_RUNS)
-            message (STATUS "LuaJIT at ${LUAJIT_PREFIX} is suitable for use.")
-        else()
-            message (FATAL_ERROR "LuaJIT at ${LUAJIT_PREFIX} is NOT suitable for use.")
-        endif()
-    else()
-        message (FATAL_ERROR "Couldn't find LuaJIT in '${LUAJIT_PREFIX}'")
+macro(TestAndAppendFLag flags flag)
+    string(REGEX REPLACE "-" "_" TESTFLAG ${flag})
+    string(TOUPPER ${TESTFLAG} TESTFLAG)
+    # XXX: can't use string(PREPEND ...) on ancient versions.
+    set(TESTFLAG "CC_HAS${TESTFLAG}")
+    if(${${TESTFLAG}})
+        set(${flags} "${${flags}} ${flag}")
     endif()
 endmacro()
 
-#
-# LuaJIT options.
-#
-option(ENABLE_BUNDLED_LUAJIT "Enable building of the bundled LuaJIT" ON)
-option(LUAJIT_PREFIX "Build with LuaJIT at the given path" "")
+# Preserve the current CFLAGS and to not spoil the original ones with LuaJIT
+# specific flags and defines.
+set(CMAKE_C_FLAGS_BCKP ${CMAKE_C_FLAGS})
+
+TestAndAppendFLag(CMAKE_C_FLAGS -Wno-parentheses-equality)
+TestAndAppendFLag(CMAKE_C_FLAGS -Wno-tautological-compare)
+TestAndAppendFLag(CMAKE_C_FLAGS -Wno-misleading-indentation)
+TestAndAppendFLag(CMAKE_C_FLAGS -Wno-varargs)
+TestAndAppendFLag(CMAKE_C_FLAGS -Wno-implicit-fallthrough)
+
+set(BUILDMODE static CACHE STRING
+    "Build mode: build only static lib" FORCE)
+set(LUAJIT_ENABLE_GC64 ${LUAJIT_ENABLE_GC64} CACHE BOOL
+    "GC64 mode for x64" FORCE)
+set(LUAJIT_SMART_STRINGS ON CACHE BOOL
+    "Harder string hashing function" FORCE)
+set(LUAJIT_TEST_BINARY $<TARGET_FILE:tarantool> CACHE STRING
+    "Lua implementation to be used for tests (tarantool)" FORCE)
+set(LUAJIT_USE_TEST OFF CACHE BOOL
+    "Generate <test> target" FORCE)
+
+# Enable internal LuaJIT assertions for Tarantool Debug build.
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+    set(LUAJIT_USE_APICHECK ON CACHE BOOL
+        "Assertions for the Lua/C API" FORCE)
+    set(LUAJIT_USE_ASSERT ON CACHE BOOL
+        "Assertions for the whole LuaJIT VM" FORCE)
+endif()
 
-if (LUAJIT_PREFIX AND ENABLE_BUNDLED_LUAJIT)
-    message (FATAL_ERROR "Options LUAJIT_PREFIX and ENABLE_BUNDLED_LUAJIT "
-                         "are not compatible with each other.")
+# Valgrind can be used only with the system allocator. For more
+# info see LuaJIT root CMakeLists.txt.
+if(ENABLE_VALGRIND)
+    set(LUAJIT_USE_SYSMALLOC ON CACHE BOOL
+        "System provided memory allocator (realloc)" FORCE)
+    set(LUAJIT_USE_VALGRIND ON CACHE BOOL
+        "Valgrind support" FORCE)
 endif()
 
-if (LUAJIT_PREFIX)
-    # trying to build with specified LuaJIT.
-    luajit_try_prefix()
-elseif (NOT ENABLE_BUNDLED_LUAJIT)
-    # trying to build with system LuaJIT, macro can turn on
-    # building of LuaJIT bundled with the server source.
-    luajit_try_system()
-else()
-    luajit_use_bundled()
+# FIXME: ASAN support is badly implemented in LuaJIT and there is
+# not a specific build options for this. At the same time there
+# are several places wrapped with LUAJIT_USE_ASAN define.
+# Just enable it here if needed and patiently wait until ASAN
+# support is implemented properly in LuaJIT.
+if(ENABLE_ASAN)
+    add_definitions(-DLUAJIT_USE_ASAN=1)
 endif()
 
-unset (LUAJIT_RUNS)
-#include_directories("${LUAJIT_INCLUDE}")
+if(TARGET_OS_DARWIN)
+    # Necessary to make LuaJIT (and Tarantool) work on Darwin, see
+    # http://luajit.org/install.html.
+    set(CMAKE_EXE_LINKER_FLAGS
+        "${CMAKE_EXE_LINKER_FLAGS} -pagezero_size 10000 -image_base 100000000")
+endif()
 
-macro(luajit_build)
-    set (luajit_cc ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1})
-    set (luajit_hostcc ${CMAKE_HOST_C_COMPILER})
-    # Cmake rules concerning strings and lists of strings are weird.
-    #   set (foo "1 2 3") defines a string, while
-    #   set (foo 1 2 3) defines a list.
-    # Use separate_arguments() to turn a string into a list (splits at ws).
-    # It appears that variable expansion rules are context-dependent.
-    # With the current arrangement add_custom_command()
-    # does the right thing. We can even handle pathnames with
-    # spaces though a path with an embeded semicolon or a quotation mark
-    # will most certainly wreak havok.
-    #
-    # This stuff is extremely fragile, proceed with caution.
-    set (luajit_cflags ${CMAKE_C_FLAGS})
-    set (luajit_ldflags ${CMAKE_EXE_LINKER_FLAGS})
-    separate_arguments(luajit_cflags)
-    separate_arguments(luajit_ldflags)
-    if(CC_HAS_WNO_PARENTHESES_EQUALITY)
-        set(luajit_cflags ${luajit_cflags} -Wno-parentheses-equality)
-    endif()
-    if(CC_HAS_WNO_TAUTOLOGICAL_COMPARE)
-        set(luajit_cflags ${luajit_cflags} -Wno-tautological-compare)
-    endif()
-    if(CC_HAS_WNO_MISLEADING_INDENTATION)
-        set(luajit_cflags ${luajit_cflags} -Wno-misleading-indentation)
-    endif()
-    if(CC_HAS_WNO_VARARGS)
-        set(luajit_cflags ${luajit_cflags} -Wno-varargs)
-    endif()
-    if (CC_HAS_WNO_IMPLICIT_FALLTHROUGH)
-        set(luajit_cflags ${luajit_cflags} -Wno-implicit-fallthrough)
-    endif()
+# Define the locations for LuaJIT sources and artefacts.
+set(LUAJIT_SOURCE_ROOT ${PROJECT_SOURCE_DIR}/third_party/luajit)
+set(LUAJIT_BINARY_ROOT ${PROJECT_BINARY_DIR}/third_party/luajit)
 
-    if (LUAJIT_ENABLE_GC64)
-        add_definitions(-DLUAJIT_ENABLE_GC64=1)
-    elseif(TARGET_OS_DARWIN)
-        # Necessary to make LuaJIT work on Darwin, see
-        # http://luajit.org/install.html
-        set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}
-            "-pagezero_size 10000 -image_base 100000000")
-    endif()
+add_subdirectory(${LUAJIT_SOURCE_ROOT} ${LUAJIT_BINARY_ROOT} EXCLUDE_FROM_ALL)
 
-    # We are consciously ommiting debug info in RelWithDebInfo mode
-    if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
-        set (luajit_ccopt -O0)
-        if (CC_HAS_GGDB)
-            set (luajit_ccdebug -g -ggdb)
-        else ()
-            set (luajit_ccdebug -g)
-        endif ()
-        add_definitions(-DLUA_USE_APICHECK=1)
-        add_definitions(-DLUA_USE_ASSERT=1)
-    else ()
-        set (luajit_ccopt -O2)
-        set (luajit_ccdbebug "")
-    endif()
-    if (${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
-        # Pass sysroot - prepended in front of system header/lib dirs,
-        # i.e. <sysroot>/usr/include, <sysroot>/usr/lib.
-        # Needed for XCode users without command line tools installed,
-        # they have headers/libs deep inside /Applications/Xcode.app/...
-        if (NOT "${CMAKE_OSX_SYSROOT}" STREQUAL "")
-            set (luajit_cflags ${luajit_cflags} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT})
-            set (luajit_ldflags ${luajit_ldlags} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT})
-            set (luajit_hostcc ${luajit_hostcc} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT})
-        endif()
-        # Pass deployment target
-        if ("${CMAKE_OSX_DEPLOYMENT_TARGET}" STREQUAL "")
-            # Default to 10.6 since @rpath support is NOT available in
-            # earlier versions, needed by AddressSanitizer.
-            set (luajit_osx_deployment_target 10.6)
-        else()
-            set (luajit_osx_deployment_target ${CMAKE_OSX_DEPLOYMENT_TARGET})
-        endif()
-        set(luajit_ldflags
-            ${luajit_ldflags} -Wl,-macosx_version_min,${luajit_osx_deployment_target})
-    endif()
-    if (ENABLE_GCOV)
-        set (luajit_ccdebug ${luajit_ccdebug} -fprofile-arcs -ftest-coverage)
-    endif()
-    if (ENABLE_VALGRIND)
-        add_definitions(-DLUAJIT_USE_SYSMALLOC=1)
-        add_definitions(-DLUAJIT_USE_VALGRIND=1)
-        set (luajit_xcflags ${luajit_xcflags}
-            -I${PROJECT_SOURCE_DIR}/src/lib/small/third_party)
-    endif()
-    # AddressSanitizer - CFLAGS were set globaly
-    if (ENABLE_ASAN)
-        add_definitions(-DLUAJIT_USE_ASAN=1)
-        set (luajit_ldflags ${luajit_ldflags} -fsanitize=address)
-    endif()
-    add_definitions(-DLUAJIT_SMART_STRINGS=1)
-    # Add all COMPILE_DEFINITIONS to xcflags
-    get_property(defs DIRECTORY PROPERTY COMPILE_DEFINITIONS)
-    foreach(def ${defs})
-        set(luajit_xcflags ${luajit_xcflags} -D${def})
-    endforeach()
+set(LUAJIT_PREFIX ${LUAJIT_BINARY_ROOT}/src)
+set(LUAJIT_INCLUDE ${LUAJIT_PREFIX})
+set(LUAJIT_LIB ${LUAJIT_PREFIX}/libluajit.a)
 
-    # Pass the same toolchain that is used for building of
-    # tarantool itself, because tools from different toolchains
-    # can be incompatible. A compiler and a linker are already set
-    # above.
-    set (luajit_ld ${CMAKE_LINKER})
-    set (luajit_ar ${CMAKE_AR} rcus)
-    # Enablibg LTO for luajit if DENABLE_LTO set.
-    if (ENABLE_LTO)
-        message(STATUS "Enable LTO for luajit")
-        set (luajit_ldflags ${luajit_ldflags} ${LDFLAGS_LTO})
-        message(STATUS "ld: " ${luajit_ldflags})
-        set (luajit_cflags ${luajit_cflags} ${CFLAGS_LTO})
-        message(STATUS "cflags: " ${luajit_cflags})
-        set (luajit_ar  ${AR_LTO} rcus)
-        message(STATUS "ar: " ${luajit_ar})
-    endif()
-    set (luajit_strip ${CMAKE_STRIP})
+add_dependencies(build_bundled_libs libluajit)
 
-    set (luajit_buildoptions
-        BUILDMODE=static
-        HOST_CC="${luajit_hostcc}"
-        TARGET_CC="${luajit_cc}"
-        TARGET_CFLAGS="${luajit_cflags}"
-        TARGET_LD="${luajit_ld}"
-        TARGET_LDFLAGS="${luajit_ldflags}"
-        TARGET_AR="${luajit_ar}"
-        TARGET_STRIP="${luajit_strip}"
-        TARGET_SYS="${CMAKE_SYSTEM_NAME}"
-        CCOPT="${luajit_ccopt}"
-        CCDEBUG="${luajit_ccdebug}"
-        XCFLAGS="${luajit_xcflags}"
-        Q=''
-        # We need to set MACOSX_DEPLOYMENT_TARGET to at least 10.6,
-        # because 10.4 SDK (which is set by default in LuaJIT's
-        # Makefile) is not longer included in Mac OS X Mojave 10.14.
-        # See also https://github.com/LuaJIT/LuaJIT/issues/484
-        MACOSX_DEPLOYMENT_TARGET="${luajit_osx_deployment_target}")
-    if (${PROJECT_BINARY_DIR} STREQUAL ${PROJECT_SOURCE_DIR})
-        add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/third_party/luajit/src/libluajit.a
-            WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/third_party/luajit
-            COMMAND $(MAKE) ${luajit_buildoptions} clean
-            COMMAND $(MAKE) -C src ${luajit_buildoptions} jit/vmdef.lua libluajit.a
-            DEPENDS ${CMAKE_SOURCE_DIR}/CMakeCache.txt
-        )
-    else()
-        add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/third_party/luajit
-            COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/third_party/luajit"
-        )
-        add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/third_party/luajit/src/libluajit.a
-            WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/third_party/luajit
-            COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/third_party/luajit ${PROJECT_BINARY_DIR}/third_party/luajit
-            COMMAND $(MAKE) ${luajit_buildoptions} clean
-            COMMAND $(MAKE) -C src ${luajit_buildoptions} jit/vmdef.lua libluajit.a
-            DEPENDS ${PROJECT_BINARY_DIR}/CMakeCache.txt ${PROJECT_BINARY_DIR}/third_party/luajit
-        )
-    endif()
-    add_custom_target(libluajit
-        DEPENDS ${PROJECT_BINARY_DIR}/third_party/luajit/src/libluajit.a
-    )
-    add_dependencies(build_bundled_libs libluajit)
-    unset (luajit_buildoptions)
-    set (inc ${PROJECT_SOURCE_DIR}/third_party/luajit/src)
-    install (FILES ${inc}/lua.h ${inc}/lualib.h ${inc}/lauxlib.h
-        ${inc}/luaconf.h ${inc}/lua.hpp ${inc}/luajit.h ${inc}/lmisclib.h
-        DESTINATION ${MODULE_INCLUDEDIR})
-endmacro()
-
-#
-# Building shipped luajit only if there is no
-# usable system one (see cmake/luajit.cmake) or by demand.
-#
-if (ENABLE_BUNDLED_LUAJIT)
-    luajit_build()
-endif()
+install(
+    FILES
+        ${LUAJIT_SOURCE_ROOT}/src/lua.h
+        ${LUAJIT_SOURCE_ROOT}/src/lualib.h
+        ${LUAJIT_SOURCE_ROOT}/src/lauxlib.h
+        ${LUAJIT_SOURCE_ROOT}/src/luaconf.h
+        ${LUAJIT_SOURCE_ROOT}/src/lua.hpp
+        ${LUAJIT_SOURCE_ROOT}/src/luajit.h
+        ${LUAJIT_SOURCE_ROOT}/src/lmisclib.h
+    DESTINATION ${MODULE_INCLUDEDIR}
+)
 
 set(LuaJIT_FIND_REQUIRED TRUE)
 find_package_handle_standard_args(LuaJIT
     REQUIRED_VARS LUAJIT_INCLUDE LUAJIT_LIB)
 set(LUAJIT_INCLUDE_DIRS ${LUAJIT_INCLUDE})
 set(LUAJIT_LIBRARIES ${LUAJIT_LIB})
+
+# XXX: Since Tarantool use LuaJIT internals to implement all
+# required interfaces, several defines and flags need to be set
+# for Tarantool too.
+# FIXME: Hope everything below will have gone in a future.
+
+# Include LuaJIT source directory to use the internal headers.
+include_directories(${LUAJIT_SOURCE_ROOT}/src)
+
+# Since LUAJIT_SMART_STRINGS is enabled for LuaJIT bundle, it
+# should be unconditionally enabled for Tarantool too. Otherwise,
+# all modules using LuaJIT internal headers are misaligned.
+add_definitions(-DLUAJIT_SMART_STRINGS=1)
+# The same is done for LUAJIT_ENABLE_GC64 but under the condition.
+if(LUAJIT_ENABLE_GC64)
+    add_definitions(-DLUAJIT_ENABLE_GC64)
+endif()
+
+# Restore the preserved CFLAGS.
+set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_BCKP})
diff --git a/cmake/luatest.cpp b/cmake/luatest.cpp
deleted file mode 100644
index e9c951933..000000000
--- a/cmake/luatest.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2010-2015, Tarantool AUTHORS, please see AUTHORS file.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * 1. Redistributions of source code must retain the above
- *    copyright notice, this list of conditions and the
- *    following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- *    copyright notice, this list of conditions and the following
- *    disclaimer in the documentation and/or other materials
- *    provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Find out LuaJIT behavior on the current platform.
- *
- * LuaJIT uses different stack unwinding mechanisms on 32-bit x86
- * and 64-bit x86-64 hardware: on a  32-bit system it can use
- * its own * longjmp-style "internal stack unwinding".
- * Among other things, this mechanism doesn't support exception
- * propagation from Lua panic function (lua_atpanic()), and
- * this is exactly what Tarantool does: throws an exception
- * in lua_atpanic().
- *
- * Which mechanism to use is determined at library
- * compile time, by a set of flags
- * (-fexceptions -funwind-tables -DLUAJIT_UNWIND_EXTERNAL),
- * hence, when configuring, we can't just check the library file
- * to find out whether or not it will work.
- * Instead, we compile and run this test.
- *
- * http://lua-users.org/lists/lua-l/2010-04/msg00470.html
- */
-
-#include <cstdlib>
-#include <lua.hpp>
-
-static int panic = 0;
-
-static int lua_panic_cb(lua_State *L) {
-	if (!panic++)
-		throw 0;
-	abort();
-	return 0;
-}
-
-int
-main(int argc, char * argv[])
-{
-	lua_State *L = luaL_newstate();
-	if (L == NULL)
-		return 1;
-	lua_atpanic(L, lua_panic_cb);
-	try {
-		lua_pushstring(L, "uncallable");
-		lua_call(L, 0, LUA_MULTRET);
-	} catch (...) {
-		/* If we're lucky, we should get here. */
-	}
-	lua_close(L);
-	return 0;
-}
diff --git a/debian/control b/debian/control
index ce810ee67..d2390e95c 100644
--- a/debian/control
+++ b/debian/control
@@ -20,6 +20,8 @@ Build-Depends: cdbs (>= 0.4.100), debhelper (>= 9), dpkg-dev (>= 1.16.1~),
  libicu-dev,
 # libcurl build dependencies
  zlib1g-dev,
+# Install prove to run LuaJIT tests.
+ libtest-harness-perl,
 Section: database
 Standards-Version: 3.9.8
 Homepage: http://tarantool.org/
diff --git a/rpm/tarantool.spec b/rpm/tarantool.spec
index ffd161862..939442f10 100644
--- a/rpm/tarantool.spec
+++ b/rpm/tarantool.spec
@@ -108,6 +108,8 @@ BuildRequires: python-gevent >= 1.0
 BuildRequires: python-yaml >= 3.0.9
 %endif
 %endif
+# Install prove to run LuaJIT tests.
+BuildRequires: perl-Test-Harness
 
 Name: tarantool
 # ${major}.${major}.${minor}.${patch}, e.g. 1.6.8.175
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9a712bc29..b12bce58b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -52,21 +52,21 @@ lua_source(lua_sources lua/httpc.lua)
 lua_source(lua_sources lua/iconv.lua)
 lua_source(lua_sources lua/swim.lua)
 # LuaJIT jit.* library
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/bc.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/bcsave.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/dis_x86.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/dis_x64.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/dump.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/vmdef.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/v.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/p.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/src/jit/zone.lua")
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/bc.lua)
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/bcsave.lua)
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/dis_x86.lua)
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/dis_x64.lua)
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/dump.lua)
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/v.lua)
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/p.lua)
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/zone.lua)
+lua_source(lua_sources ${LUAJIT_BINARY_ROOT}/src/jit/vmdef.lua)
 # LuaJIT tools.* library
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/tools/memprof.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/tools/memprof/humanize.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/tools/memprof/parse.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/tools/utils/bufread.lua")
-lua_source(lua_sources "${CMAKE_BINARY_DIR}/third_party/luajit/tools/utils/symtab.lua")
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/tools/memprof.lua)
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/tools/memprof/humanize.lua)
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/tools/memprof/parse.lua)
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/tools/utils/bufread.lua)
+lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/tools/utils/symtab.lua)
 
 add_custom_target(generate_lua_sources
     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src/box
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index baa704037..d40b92237 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -12,14 +12,6 @@ function(build_module module files)
     endif(TARGET_OS_DARWIN)
 endfunction()
 
-function(build_lualib lib sources)
-    add_library(${lib} SHARED ${sources})
-    set_target_properties(${lib} PROPERTIES PREFIX "")
-    if(TARGET_OS_DARWIN)
-        set_target_properties(${lib} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
-    endif(TARGET_OS_DARWIN)
-endfunction()
-
 add_compile_flags("C;CXX"
     "-Wno-unused-parameter")
 
@@ -43,10 +35,6 @@ if(POLICY CMP0037)
     endif()
 endif(POLICY CMP0037)
 
-execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
-        ${PROJECT_SOURCE_DIR}/third_party/luajit/test
-        ${CMAKE_CURRENT_BINARY_DIR}/luajit-tap)
-
 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/small
     COMMAND ${CMAKE_COMMAND} -E create_symlink
         ${PROJECT_SOURCE_DIR}/src/lib/small/test/
@@ -57,14 +45,14 @@ add_custom_target(symlink_small_tests ALL
 
 add_custom_target(test
     DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/small
-            ${CMAKE_CURRENT_BINARY_DIR}/luajit-tap
+            LuaJIT-test
     COMMAND ${PROJECT_SOURCE_DIR}/test/test-run.py
         --builddir=${PROJECT_BINARY_DIR}
         --vardir=${PROJECT_BINARY_DIR}/test/var)
 
 add_custom_target(test-force
     DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/small
-            ${CMAKE_CURRENT_BINARY_DIR}/luajit-tap
+            LuaJIT-test
     COMMAND ${PROJECT_SOURCE_DIR}/test/test-run.py
         --builddir=${PROJECT_BINARY_DIR}
         --vardir=${PROJECT_BINARY_DIR}/test/var
@@ -78,8 +66,6 @@ if(ENABLE_FUZZER)
     add_subdirectory(fuzz)
 endif()
 add_subdirectory(unit)
-add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/luajit/test
-                 ${PROJECT_BINARY_DIR}/third_party/luajit/test)
 
 # Disable connector_c for 1.6
 #add_subdirectory(connector_c)
diff --git a/third_party/luajit b/third_party/luajit
index c0c2e62a5..2350dd7ed 160000
--- a/third_party/luajit
+++ b/third_party/luajit
@@ -1 +1 @@
-Subproject commit c0c2e62a5404b51ba740ed28762e65b2ef56bcf9
+Subproject commit 2350dd7ed112c2c7b2f96c6ef8701eeac62bf9d7
-- 
2.25.0


  parent reply	other threads:[~2021-02-03 23:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 23:22 [Tarantool-patches] [PATCH 0/3] Adjust " Igor Munkin via Tarantool-patches
2021-02-03 23:22 ` [Tarantool-patches] [PATCH 1/3] build: fix lua.c file generation Igor Munkin via Tarantool-patches
2021-02-15 13:12   ` Sergey Kaplun via Tarantool-patches
2021-02-19 21:17     ` Igor Munkin via Tarantool-patches
2021-02-03 23:22 ` Igor Munkin via Tarantool-patches [this message]
2021-02-15 16:13   ` [Tarantool-patches] [PATCH 2/3] build: adjust LuaJIT build system Sergey Kaplun via Tarantool-patches
2021-02-19 23:10     ` Igor Munkin via Tarantool-patches
2021-02-20  7:42       ` Timur Safin via Tarantool-patches
2021-02-03 23:22 ` [Tarantool-patches] [PATCH 3/3] ci: enable LuaJIT tests in CI Igor Munkin via Tarantool-patches
2021-02-15 16:29   ` Sergey Kaplun via Tarantool-patches
2021-02-19 21:29     ` Igor Munkin via Tarantool-patches
     [not found]       ` <0b6601d7075c$64329060$2c97b120$@tarantool.org>
2021-02-20 10:18         ` Igor Munkin via Tarantool-patches
2021-02-24  7:16   ` Timur Safin via Tarantool-patches
2021-02-25 22:08     ` Igor Munkin via Tarantool-patches
2021-02-26 19:04       ` Timur Safin via Tarantool-patches
2021-02-26 19:09 ` [Tarantool-patches] [PATCH 0/3] Adjust LuaJIT build system Timur Safin via Tarantool-patches
2021-02-26 21:06   ` Igor Munkin via Tarantool-patches
2021-02-27 13:56 ` Sergey Kaplun via Tarantool-patches
2021-02-28 22:05 ` Igor Munkin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9426dbd66c51aa466ab89272894ad33a7b22edec.1612390822.git.imun@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imun@tarantool.org \
    --cc=skaplun@tarantool.org \
    --cc=tsafin@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 2/3] build: adjust LuaJIT build system' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox