From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id E99886C7D4; Tue, 2 Feb 2021 23:58:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E99886C7D4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1612299533; bh=2mveEc1ablNATmuDcI2ozZRGh+HDi/PU0wI3E+eezS0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=IO8KF8PALDNOs/VCm+ZCZkFhViSdb8P1/cDi6k1lADXPU8ZjMCSnyEGREn5qOAWj6 mRfkhjySCPQ4qcTWuZcNpEXGHCyaNqkDP7QmGEG8WHKxMP/iKOR4TEDuk+HhJ9q4S5 lS23N+lJ2mmDxj4SibL4+m1Yg+jXN2qdhofpJc8E= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id E9FF8686FA for ; Tue, 2 Feb 2021 23:57:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E9FF8686FA Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1l72kA-0005mg-JK; Tue, 02 Feb 2021 23:57:51 +0300 To: Sergey Kaplun , Timur Safin Date: Tue, 2 Feb 2021 23:57:42 +0300 Message-Id: <7cd42be38d86c832ecd4ba0f3edd7ae83aead7ad.1612291495.git.imun@tarantool.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD953AC099BC0052A9CD7A046B9B594DE544EF4829CAF723B1F182A05F53808504092BDDEF02668A66DF671E8C835E01CA553696274F96554F9808184FCD689F06A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE728A881FD0F09D355EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637CAA352D56883AEE98638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FCDAFBC183B389AD44A0E21BD08DDDD3F65AB6FA766E5C856A389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0D9442B0B5983000E8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6957A4DEDD2346B42CC7F00164DA146DA6F5DAA56C3B73B23C77107234E2CFBA567F23339F89546C55F5C1EE8F4F765FC426E46268278306375ECD9A6C639B01BBD4B6F7A4D31EC0BC0CAF46E325F83A522CA9DD8327EE4931B544F03EFBC4D5789424AA0EF8DE9BAC4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F05F538519369F3743B503F486389A921A5CC5B56E945C8DA X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C4C7A0BC55FA0FE5FCDAFBC183B389AD44A0E21BD08DDDD3F69C2DA6DD9C302B16B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDB791E6C230873D55CDC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346F8291983715AC6697354FD8EDFC7F2E9FA9923E89785DF6E22AAAB75C3F3CA9C343446BEEB4D2221D7E09C32AA3244C512DA11A6202BE66B1D642EF942E4F1E55E75C8D0ED9F6EE927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojCSo1BV1mVLZyxuR7xRkOUA== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638224FAD20A9B7F85A5E908370DE7B245C21A7C8D0F45F857DBFE9F1EFEE2F478337FB559BB5D741EB964C8C2C849690F8E70A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 2/5] build: replace GNU Make with CMake X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Igor Munkin via Tarantool-patches Reply-To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" In scope of this patch the LuaJIT build system is partially ported from GNU Make to CMake. These changes provides CMake build system only for the following OS: GNU/Linux, OSX, FreeBSD. For other platrforms use the old build system (see the recipe in the previous commit). Several components of the new build system such as automatic version detection, source files list generation and some recipes for CMakeLists.txt are taken verbatim or adapted from LuaVela repository. Part of tarantool/tarantool#4862 Signed-off-by: Igor Munkin --- .gitignore | 12 +- CMakeLists.txt | 261 +++++++++++++++++++++++++ cmake/LuaJITUtils.cmake | 31 +++ cmake/MakeSourceList.cmake | 47 +++++ cmake/SetDynASMFlags.cmake | 130 ++++++++++++ cmake/SetTargetFlags.cmake | 42 ++++ cmake/SetVersion.cmake | 45 +++++ etc/CMakeLists.txt | 32 +++ src/CMakeLists.txt | 391 +++++++++++++++++++++++++++++++++++++ src/host/CMakeLists.txt | 61 ++++++ tools/CMakeLists.txt | 77 ++++++++ 11 files changed, 1128 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/LuaJITUtils.cmake create mode 100644 cmake/MakeSourceList.cmake create mode 100644 cmake/SetDynASMFlags.cmake create mode 100644 cmake/SetTargetFlags.cmake create mode 100644 cmake/SetVersion.cmake create mode 100644 etc/CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 src/host/CMakeLists.txt create mode 100644 tools/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 1a07bf7..a21ee1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.[oa] -*.so +*.so* *.obj *.lib *.exp @@ -9,3 +9,13 @@ *.dmp *.swp .tags + +# CMake generated artefacts +CMakeCache.txt +CMakeFiles +Makefile +cmake_install.cmake +compile_commands.json +install_manifest.txt +luajit-parse-memprof +luajit.pc diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0dba5d8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,261 @@ +# LuaJIT -- interpreter and JIT compiler for Lua language. +# This is the main entry point for building, testing and +# packaging the project. +# Major portions taken verbatim or adapted from the uJIT. +# Copyright (C) 2015-2019 IPONWEB Ltd. + +# --- Initial setup ------------------------------------------------------------ + +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) +project(LuaJIT C) + +# +# XXX: Originally CMake machinery is introduced to make LuaJIT +# testing self-sufficient. Since there are only few systems +# covered with the tests in our CI, there is no need to support +# others for now and the original build system can be used. +# + +if(NOT( + CMAKE_SYSTEM_NAME STREQUAL "Linux" OR + CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR + CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" +)) + message(FATAL_ERROR + "Please use the old build system:\n\tmake -f Makefile.original " + ) +endif() + +# --- Fine-tuning cmake environment -------------------------------------------- + +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +include(LuaJITUtils) +include(SetVersion) + +# --- Variables to be exported to child scopes --------------------------------- + +SetVersion( + LUAJIT_VERSION + LUAJIT_VERSION_MAJOR + LUAJIT_VERSION_MINOR + LUAJIT_VERSION_PATCH + LUAJIT_VERSION_TWEAK + LUAJIT_PRERELEASE +) + +set(LUAJIT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src") +set(LUAJIT_BINARY_DIR "${PROJECT_BINARY_DIR}/src") + +# Names of the CLI binaries. +set(LUAJIT_CLI_NAME "luajit") +set(LUAJIT_LIB_NAME "luajit") + +# Specialized install paths. +set(LUAJIT_DATAROOTDIR + share/luajit-${LUAJIT_VERSION_MAJOR}.${LUAJIT_VERSION_MINOR}.${LUAJIT_VERSION_PATCH}${LUAJIT_PRERELEASE} +) +set(LUAJIT_INCLUDEDIR + include/luajit-${LUAJIT_VERSION_MAJOR}.${LUAJIT_VERSION_MINOR} +) + +set(BUILDMODE_VALUES mixed static dynamic) +list(GET BUILDMODE_VALUES 0 BUILDMODE_DEFAULT) +set(BUILDMODE ${BUILDMODE_DEFAULT} CACHE STRING + "Build mode. Choose one of the following: ${BUILDMODE_VALUES}." +) +set_property(CACHE BUILDMODE PROPERTY STRINGS ${BUILDMODE_VALUES}) + +# Check that BUILDMODE value is correct. +# FIXME: In CMake 3.5 we'll be able to use IN_LIST here. +list(FIND BUILDMODE_VALUES ${BUILDMODE} BUILDMODE_INDEX) +if(BUILDMODE_INDEX EQUAL -1) + message(FATAL_ERROR "BUILDMODE must be one of the following: ${BUILDMODE_VALUES}.") +endif() + +# --- Compilation flags setup -------------------------------------------------- + +if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local") + AppendFlags(TARGET_C_FLAGS -DLUA_ROOT='"${CMAKE_INSTALL_PREFIX}"') +endif() + +if(CMAKE_LIBRARY_ARCHITECTURE) + AppendFlags(TARGET_C_FLAGS -DLUA_MULTILIB='"lib/${CMAKE_LIBRARY_ARCHITECTURE}"') +endif() + +# Since the assembler part does NOT maintain a frame pointer, it's +# pointless to slow down the C part by not omitting it. Debugging, +# tracebacks and unwinding are not affected -- the assembler part +# has frame unwind information and GCC emits it where needed (x64) +# or with -g. +AppendFlags(CMAKE_C_FLAGS -fomit-frame-pointer -fno-stack-protector) + +# Re-defined to benefit from expanding macros in gdb. +set(CMAKE_C_FLAGS_DEBUG "-g -ggdb3") +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -DNDEBUG -g -ggdb3") +# Re-defined since default cmake release optimization level is O3. +set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") + +AppendFlags(CMAKE_C_FLAGS -Wall) +option(LUAJIT_ENABLE_WARNINGS "Build LuaJIT with warnings enabled" OFF) +if(LUAJIT_ENABLE_WARNINGS) + AppendFlags(CMAKE_C_FLAGS + -Wextra + -Wdeclaration-after-statement + -Wpointer-arith + -Wredundant-decls + -Wshadow + ) +endif() + +# Auxilary flags for main targets (libraries, binaries). +AppendFlags(TARGET_C_FLAGS + -D_FILE_OFFSET_BITS=64 + -D_LARGEFILE_SOURCE + -U_FORTIFY_SOURCE +) + +# Permanently disable the FFI extension to reduce the size of the +# LuaJIT executable. But please consider that the FFI library is +# compiled-in, but NOT loaded by default. It only allocates any +# memory, if you actually make use of it. +option(LUAJIT_DISABLE_FFI "FFI support" OFF) +if(LUAJIT_DISABLE_FFI) + AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_FFI) +endif() +set(LUAJIT_HAS_FFI NOT LUAJIT_DISABLE_FFI) + +# Features from Lua 5.2 that are unlikely to break existing code +# are enabled by default. Some other features that *might* break +# some existing code (e.g. __pairs or os.execute() return values) +# can be enabled here. +# XXX: this does not provide full compatibility with Lua 5.2 at +# this time. +option(LUAJIT_LUA52COMPAT "Compatibility with Lua 5.2" OFF) +if(LUAJIT_LUA52COMPAT) + AppendFlags(TARGET_C_FLAGS -DLUAJIT_ENABLE_LUA52COMPAT) +endif() + +# Disable the JIT compiler, i.e. turn LuaJIT into a pure +# interpreter. +option(LUAJIT_DISABLE_JIT "JIT support" OFF) +if(LUAJIT_DISABLE_JIT) + AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_JIT) +endif() +set(LUAJIT_HAS_JIT NOT LUAJIT_DISABLE_JIT) + +# Some architectures (e.g. PPC) can use either single-number (1) +# or dual-number (2) mode. Uncomment one of these lines to +# override the default mode. Please see LJ_ARCH_NUMMODE in +# lj_arch.h for details. +set(LUAJIT_NUMMODE_VALUES 1 2) +set(LUAJIT_NUMMODE_DEFAULT "") +set(LUAJIT_NUMMODE ${LUAJIT_NUMMODE_DEFAULT} CACHE STRING + "Switch to single-number or dual-number mode." +) +# XXX: explicitly added empty string allows to disable this flag +# in GUI. +set_property(CACHE LUAJIT_NUMMODE PROPERTY STRINGS + ${LUAJIT_NUMMODE_DEFAULT} ${LUAJIT_NUMMODE_VALUES} +) + +if(NOT LUAJIT_NUMMODE STREQUAL LUAJIT_NUMMODE_DEFAULT) + # Check that LUAJIT_NUMMODE value is correct. + # FIXME: In CMake 3.5 we'll be able to use IN_LIST here. + list(FIND LUAJIT_NUMMODE_VALUES ${LUAJIT_NUMMODE} LUAJIT_NUMMODE_INDEX) + if(LUAJIT_NUMMODE_INDEX EQUAL -1) + message(FATAL_ERROR "LUAJIT_NUMMODE must be '1' for single-number mode or '2' for dual-number mode.") + endif() + AppendFlags(TARGET_C_FLAGS -DLUAJIT_NUMMODE=${LUAJIT_NUMMODE}) +endif() + +# Enable GC64 mode for x64. +option(LUAJIT_ENABLE_GC64 "GC64 mode for x64" OFF) +if(LUAJIT_ENABLE_GC64) + AppendFlags(TARGET_C_FLAGS -DLUAJIT_ENABLE_GC64) +endif() + +# Disable memory profiler. +option(LUAJIT_DISABLE_MEMPROF "LuaJIT memory profiler support" OFF) +if(LUAJIT_DISABLE_MEMPROF) + AppendFlags(TARGET_C_FLAGS -DLUAJIT_DISABLE_MEMPROF) +endif() + +# Switch to harder (and slower) hash function when a collision +# chain in the string hash table exceeds certain length. +option(LUAJIT_SMART_STRINGS "Harder string hashing function" ON) +if(LUAJIT_SMART_STRINGS) + AppendFlags(TARGET_C_FLAGS -DLUAJIT_SMART_STRINGS=1) +endif() + +# XXX: Note that most of the options below are NOT suitable for +# benchmarking or release mode! + +# Use the system provided memory allocator (realloc) instead of +# the bundled memory allocator. This is slower, but sometimes +# helpful for debugging. This option cannot be enabled on x64 +# without GC64, since realloc usually doesn't return addresses in +# the right address range. OTOH this option is mandatory for +# Valgrind's memcheck tool on x64 and the only way to get useful +# results from it for all other architectures. +option(LUAJIT_USE_SYSMALLOC "System provided memory allocator (realloc)" OFF) +if(LUAJIT_USE_SYSMALLOC) + AppendFlags(TARGET_C_FLAGS -DLUAJIT_USE_SYSMALLOC) +endif() + +# This define is required to run LuaJIT under Valgrind. The +# Valgrind header files must be installed. You should enable debug +# information, too. Use --suppressions=lj.supp to avoid some false +# positives. +option(LUAJIT_USE_VALGRIND "Valgrind support" OFF) +if(LUAJIT_USE_VALGRIND) + AppendFlags(TARGET_C_FLAGS -DLUAJIT_USE_VALGRIND) +endif() + +# This is the client for the GDB JIT API. GDB 7.0 or higher is +# required to make use of it. See lj_gdbjit.c for details. +# Enabling this causes a non-negligible overhead, even when not +# running under GDB. +option(LUAJIT_USE_GDBJIT "GDB JIT support" OFF) +if(LUAJIT_USE_GDBJIT) + AppendFlags(TARGET_C_FLAGS -DLUAJIT_USE_GDBJIT) +endif() + +# Turn on assertions for the Lua/C API to debug problems with +# lua_* calls. This is rather slow -- use only while developing C +# libraries/embeddings. +option(LUAJIT_USE_APICHECK "Assertions for the Lua/C API" OFF) +if(LUAJIT_USE_APICHECK) + AppendFlags(TARGET_C_FLAGS -DLUA_USE_APICHECK) +endif() + +# Turn on assertions for the whole LuaJIT VM. This significantly +# slows down everything. Use only if you suspect a problem with +# LuaJIT itself. +option(LUAJIT_USE_ASSERT "Assertions for the whole LuaJIT VM" OFF) +if(LUAJIT_USE_ASSERT) + AppendFlags(TARGET_C_FLAGS -DLUA_USE_ASSERT) +endif() + +# TODO: Implement a configuration option to enable ASAN. +# There are two entries of LUAJIT_USE_ASAN define: +# $ grep -rnF 'LUAJIT_USE_ASAN' . +# ./src/lj_str.c:15:#if LUAJIT_USE_ASAN +# ./src/host/buildvm.c:36:#if LUAJIT_USE_ASAN +# At the same time this flag is not provided by LuaJIT original +# build system (i.e. src/Makefile.original) so there are no +# related compiler and linker flags passed. This should be done +# the right way later. + +# --- Main source tree --------------------------------------------------------- + +add_subdirectory(src) + +# --- Auxiliary files ---------------------------------------------------------- + +add_subdirectory(etc) + +# --- Tools -------------------------------------------------------------------- + +add_subdirectory(tools) diff --git a/cmake/LuaJITUtils.cmake b/cmake/LuaJITUtils.cmake new file mode 100644 index 0000000..faaef6b --- /dev/null +++ b/cmake/LuaJITUtils.cmake @@ -0,0 +1,31 @@ +function(LuaJITTestArch outvar strflags) + # XXX: simply splits the COMMAND argument by + # spaces with no further parsing. At the same time GCC is bad in + # argument handling, so let's help it a bit. + separate_arguments(TEST_C_FLAGS UNIX_COMMAND ${strflags}) + execute_process( + COMMAND ${CMAKE_C_COMPILER} ${TEST_C_FLAGS} -E lj_arch.h -dM + WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR} + OUTPUT_VARIABLE TESTARCH + ) + set(${outvar} ${TESTARCH} PARENT_SCOPE) +endfunction() + +function(LuaJITArch outvar testarch) + foreach(TRYARCH X64 X86 ARM ARM64 PPC MIPS64 MIPS) + string(FIND "${testarch}" "LJ_TARGET_${TRYARCH}" FOUND) + if(FOUND EQUAL -1) + continue() + endif() + string(TOLOWER ${TRYARCH} LUAJIT_ARCH) + set(${outvar} ${LUAJIT_ARCH} PARENT_SCOPE) + return() + endforeach() + message(FATAL_ERROR "[LuaJITArch] Unsupported target architecture") +endfunction() + +macro(AppendFlags flags) + foreach(flag ${ARGN}) + set(${flags} "${${flags}} ${flag}") + endforeach() +endmacro() diff --git a/cmake/MakeSourceList.cmake b/cmake/MakeSourceList.cmake new file mode 100644 index 0000000..fa455bb --- /dev/null +++ b/cmake/MakeSourceList.cmake @@ -0,0 +1,47 @@ +# Major portions taken verbatim or adapted from the uJIT. +# Copyright (C) 2015-2019 IPONWEB Ltd. +# +# make_source_list provides a convenient way to define a list of sources +# and get a list of absolute paths. +# +# Example usage: +# +# make_source_list(SOURCES_CORE +# SOURCES +# main.c +# test.c +# subdir/test2.c +# ) +# +# This will give you the list: +# "<...>/main.c;<...>/test.c;<...>/subdir/test2.c" +# (where `<...>` is ${CMAKE_CURRENT_SOURCE_DIR}). +# +# Absolute paths in `SOURCES` list don't get ${CMAKE_CURRENT_SOURCE_DIR} +# prepended to them. + +function(make_source_list list) + set(prefix ARG) + set(noValues) + set(singleValues) + set(multiValues SOURCES) + + include(CMakeParseArguments) # if we update to CMake >= 3.5, can remove this line + cmake_parse_arguments(${prefix} + "${noValues}" + "${singleValues}" + "${multiValues}" + ${ARGN}) + + set(result_list "") + + foreach(fn ${ARG_SOURCES}) + if (IS_ABSOLUTE ${fn}) + list(APPEND result_list "${fn}") + else() + list(APPEND result_list "${CMAKE_CURRENT_SOURCE_DIR}/${fn}") + endif() + endforeach() + + set(${list} "${result_list}" PARENT_SCOPE) +endfunction() diff --git a/cmake/SetDynASMFlags.cmake b/cmake/SetDynASMFlags.cmake new file mode 100644 index 0000000..9a920c3 --- /dev/null +++ b/cmake/SetDynASMFlags.cmake @@ -0,0 +1,130 @@ +# This module exposes following variables to the project: +# * HOST_C_FLAGS +# * DYNASM_ARCH +# * DYNASM_FLAGS + +# XXX: buildvm includes core headers and thus has to be built +# with the same flags and defines as the LuaJIT core itself. +set(HOST_C_FLAGS) +set(DYNASM_ARCH) +set(DYNASM_FLAGS) + +LuaJITTestArch(TESTARCH "${TARGET_C_FLAGS} ${HOST_CFLAGS}") +LuaJITArch(LUAJIT_ARCH "${TESTARCH}") +AppendFlags(HOST_C_FLAGS -DLUAJIT_TARGET=LUAJIT_ARCH_${LUAJIT_ARCH}) + +# XXX: LUAJIT_ARCH equals to DYNASM_ARCH for the most case but +# there are few exceptions to the rule. +if(LUAJIT_ARCH STREQUAL "x64") + string(FIND "${TESTARCH}" "LJ_FR2 1" FOUND) + if(FOUND EQUAL -1) + set(DYNASM_ARCH x86) + else() + set(DYNASM_ARCH x64) + endif() +elseif(LUAJIT_ARCH STREQUAL "ppc") + string(FIND "${TESTARCH}" "LJ_ARCH_PPC64" FOUND) + if(FOUND EQUAL -1) + set(DYNASM_ARCH ppc) + else() + set(DYNASM_ARCH ppc64) + endif() +else() + set(DYNASM_ARCH ${LUAJIT_ARCH}) +endif() + +if(LUAJIT_ARCH STREQUAL "arm64") + string(FIND "${TESTARCH}" "__AARCH64EB__" FOUND) + if(NOT FOUND EQUAL -1) + AppendFlags(HOST_C_FLAGS -D__AARCH64EB__=1) + endif() +elseif(LUAJIT_ARCH STREQUAL "ppc") + string(FIND "${TESTARCH}" "LJ_LE 1" FOUND) + if(NOT FOUND EQUAL -1) + AppendFlags(HOST_C_FLAGS -DLJ_ARCH_ENDIAN=LUAJIT_LE) + else() + AppendFlags(HOST_C_FLAGS -DLJ_ARCH_ENDIAN=LUAJIT_BE) + endif() + string(FIND "${TESTARCH}" "LJ_ARCH_SQRT 1" FOUND) + if(NOT FOUND EQUAL -1) + list(APPEND DYNASM_FLAGS -D SQRT) + endif() + string(FIND "${TESTARCH}" "LJ_ARCH_ROUND 1" FOUND) + if(NOT FOUND EQUAL -1) + list(APPEND DYNASM_FLAGS -D ROUND) + endif() + string(FIND "${TESTARCH}" "LJ_ARCH_PPC32ON64 1" FOUND) + if(NOT FOUND EQUAL -1) + list(APPEND DYNASM_FLAGS -D GPR64) + endif() +elseif(LUAJIT_ARCH STREQUAL "mips") + string(FIND "${TESTARCH}" "MIPSEL" FOUND) + if(NOT FOUND EQUAL -1) + AppendFlags(HOST_C_FLAGS -D__MIPSEL__=1) + endif() +endif() + +string(FIND "${TESTARCH}" "LJ_LE 1" FOUND) +if(NOT FOUND EQUAL -1) + list(APPEND DYNASM_FLAGS -D ENDIAN_LE) +else() + list(APPEND DYNASM_FLAGS -D ENDIAN_BE) +endif() + +string(FIND "${TESTARCH}" "LJ_ARCH_BITS 64" FOUND) +if(NOT FOUND EQUAL -1) + list(APPEND DYNASM_FLAGS -D P64) +endif() + +string(FIND "${TESTARCH}" "LJ_HASJIT 1" FOUND) +if(NOT FOUND EQUAL -1) + list(APPEND DYNASM_FLAGS -D JIT) +endif() + +string(FIND "${TESTARCH}" "LJ_HASFFI 1" FOUND) +if(NOT FOUND EQUAL -1) + list(APPEND DYNASM_FLAGS -D FFI) +endif() + +string(FIND "${TESTARCH}" "LJ_DUALNUM 1" FOUND) +if(NOT FOUND EQUAL -1) + list(APPEND DYNASM_FLAGS -D DUALNUM) +endif() + +string(FIND "${TESTARCH}" "LJ_ARCH_HASFPU 1" FOUND) +if(NOT FOUND EQUAL -1) + list(APPEND DYNASM_FLAGS -D FPU) + AppendFlags(HOST_C_FLAGS -DLJ_ARCH_HASFPU=1) +else() + AppendFlags(HOST_C_FLAGS -DLJ_ARCH_HASFPU=0) +endif() + +string(FIND "${TESTARCH}" "LJ_ABI_SOFTFP 1" FOUND) +if(NOT FOUND EQUAL -1) + AppendFlags(HOST_C_FLAGS -DLJ_ABI_SOFTFP=1) +else() + list(APPEND DYNASM_FLAGS -D HFABI) + AppendFlags(HOST_C_FLAGS -DLJ_ABI_SOFTFP=0) +endif() + +string(FIND "${TESTARCH}" "LJ_NO_UNWIND 1" FOUND) +if(NOT FOUND EQUAL -1) + list(APPEND DYNASM_FLAGS -D NO_UNWIND) + AppendFlags(HOST_C_FLAGS -DLUAJIT_NO_UNWIND) +endif() + +string(REGEX MATCH "LJ_ARCH_VERSION ([0-9]+)" LUAJIT_ARCH_VERSION ${TESTARCH}) +list(APPEND DYNASM_FLAGS -D VER=${CMAKE_MATCH_1}) + +if(NOT CMAKE_SYSTEM_NAME STREQUAL ${CMAKE_HOST_SYSTEM_NAME}) + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + AppendFlags(HOST_C_FLAGS -DLUAJIT_OS=LUAJIT_OS_OSX) + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") + AppendFlags(HOST_C_FLAGS -DLUAJIT_OS=LUAJIT_OS_LINUX) + else() # FreeBSD. + AppendFlags(HOST_C_FLAGS -DLUAJIT_OS=LUAJIT_OS_OTHER) + endif() +endif() + +unset(LUAJIT_ARCH) +unset(TESTARCH) diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake new file mode 100644 index 0000000..260fc6b --- /dev/null +++ b/cmake/SetTargetFlags.cmake @@ -0,0 +1,42 @@ +# This module exposes following variables to the project: +# * BUILDVM_MODE +# * TARGET_C_FLAGS +# * TARGET_VM_FLAGS +# * TARGET_BIN_FLAGS +# * TARGET_SHARED_FLAGS +# * TARGET_LIBS + +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(BUILDVM_MODE machasm) +else() # Linux and FreeBSD. + set(BUILDVM_MODE elfasm) +endif() + +LuaJITTestArch(TESTARCH "${TARGET_C_FLAGS}") +LuaJITArch(LUAJIT_ARCH "${TESTARCH}") + +# Target-specific compiler options. +# +# x86/x64 only: For GCC 4.2 or higher and if you don't intend to +# distribute the binaries to a different machine you could also +# use: -march=native. +if(LUAJIT_ARCH STREQUAL "x86") + AppendFlags(TARGET_C_FLAGS -march=i686 -msse -msse2 -mfpmath=sse) +endif() + +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + if(LUAJIT_ARCH STREQUAL "x64") + AppendFlags(TARGET_BIN_FLAGS -pagezero_size 10000 -image_base 100000000) + AppendFlags(TARGET_SHARED_FLAGS -image_base 7fff04c4a000) + endif() + AppendFlags(TARGET_SHARED_FLAGS -single_module -undefined dynamic_lookup) +else() # Linux and FreeBSD. + AppendFlags(TARGET_BIN_FLAGS -Wl,-E) + list(APPEND TARGET_LIBS dl) +endif() + +# Auxilary flags for the VM core. +# XXX: ASAN-related build flags are stored in CMAKE_C_FLAGS. +set(TARGET_VM_FLAGS "${CMAKE_C_FLAGS} ${TARGET_C_FLAGS}") + +unset(TESTARCH) diff --git a/cmake/SetVersion.cmake b/cmake/SetVersion.cmake new file mode 100644 index 0000000..3f0247c --- /dev/null +++ b/cmake/SetVersion.cmake @@ -0,0 +1,45 @@ +# Find, check and set LuaJIT's version from a VCS tag. +# Major portions taken verbatim or adapted from the uJIT. +# Copyright (C) 2015-2019 IPONWEB Ltd. + +function(SetVersion version majver minver patchver tweakver prerel) + find_package(Git QUIET REQUIRED) + if(EXISTS ${CMAKE_SOURCE_DIR}/.git AND Git_FOUND) + # Read version from the project's VCS and store the result + # into version. + execute_process( + COMMAND ${GIT_EXECUTABLE} describe + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE vcs_tag) + string(STRIP "${vcs_tag}" vcs_tag) + message(STATUS "[SetVersion] Reading version from VCS: ${vcs_tag}") + else() + # Use default version since no git is found in the system or + # VCS directory is not found in repo root directory. + set(vcs_tag "v2.1.0-beta3-0-g0000000") + message(STATUS "[SetVersion] No VCS found, use default version: ${vcs_tag}") + endif() + + set(${version} ${vcs_tag} PARENT_SCOPE) + + # Match version_string against the version regex. + # Throw an error if it does not match. Otherwise populates + # variables: + # * majver: First version number. + # * minver: Second version number. + # * patchver: Third version number. + # * prerel: Optional prerelease suffix. + # * tweakver: Fourth version number. + # Valid version examples: + # * v2.0.4-48-gfcc8244 + # * v2.1.0-beta3-57-g2973518 + if(vcs_tag MATCHES "^v([0-9]+)\\.([0-9]+)\\.([0-9]+)(-(rc|beta)[0-9]+)?-([0-9]+)-g[0-9a-z]+$") + set(${majver} ${CMAKE_MATCH_1} PARENT_SCOPE) + set(${minver} ${CMAKE_MATCH_2} PARENT_SCOPE) + set(${patchver} ${CMAKE_MATCH_3} PARENT_SCOPE) + set(${tweakver} ${CMAKE_MATCH_6} PARENT_SCOPE) + set(${prerel} ${CMAKE_MATCH_4} PARENT_SCOPE) + else() + message(FATAL_ERROR "[SetVersion] Malformed version string '${vcs_tag}'") + endif() +endfunction() diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt new file mode 100644 index 0000000..4a4c3cd --- /dev/null +++ b/etc/CMakeLists.txt @@ -0,0 +1,32 @@ +# Building supplementary materials for LuaJIT. + +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) + +set(LUAJIT_PC_PREFIX ${CMAKE_INSTALL_PREFIX}) +if(CMAKE_LIBRARY_ARCHITECTURE) + set(LUAJIT_PC_MULTILIB "lib/${CMAKE_LIBRARY_ARCHITECTURE}") +else() + set(LUAJIT_PC_MULTILIB "lib") +endif() + +configure_file(luajit.pc.in luajit.pc @ONLY ESCAPE_QUOTES) + +install(FILES + luajit.1 + DESTINATION share/man/man1 + PERMISSIONS + OWNER_READ OWNER_WRITE + GROUP_READ + WORLD_READ + COMPONENT luajit +) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/luajit.pc + DESTINATION lib/pkgconfig + PERMISSIONS + OWNER_READ OWNER_WRITE + GROUP_READ + WORLD_READ + COMPONENT luajit +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..8ada1a4 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,391 @@ +# Building LuaJIT core: bootstrapping, VM, runtime, JIT compiler. +# Major portions taken verbatim or adapted from the uJIT. +# Copyright (C) 2015-2019 IPONWEB Ltd. + +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) + +enable_language(ASM) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +include(MakeSourceList) + +# --- Define source tree ------------------------------------------------------- + +# Core runtime. +make_source_list(SOURCES_RUNTIME + SOURCES + lj_api.c + lj_bc.c + lj_buf.c + lj_debug.c + lj_dispatch.c + lj_err.c + lj_func.c + lj_gc.c + lj_lib.c + lj_load.c + lj_mapi.c + lj_meta.c + lj_obj.c + lj_state.c + lj_str.c + lj_strfmt.c + lj_strfmt_num.c + lj_strscan.c + lj_tab.c + lj_udata.c + lj_vmevent.c + lib_aux.c + lib_init.c +) + +# Lua frontend. +make_source_list(SOURCES_FRONTEND + SOURCES + lj_bcread.c + lj_bcwrite.c + lj_lex.c + lj_parse.c +) + +make_source_list(SOURCES_UTILS + SOURCES + lj_alloc.c + lj_char.c + lj_utils_leb128.c + lj_vmmath.c + lj_wbuf.c +) + +make_source_list(SOURCES_PROFILER + SOURCES + lj_memprof.c + lj_profile.c +) + +# Lua standard library + extensions by LuaJIT. +make_source_list(SOURCES_LUA_LIB + # XXX: Please do not changes the order of the libraries + # (required by buildvm). + SOURCES + lib_base.c + lib_math.c + lib_bit.c + lib_string.c + lib_table.c + lib_io.c + lib_os.c + lib_package.c + lib_debug.c + lib_jit.c + lib_ffi.c + lib_misc.c +) + +# JIT compiler, core part. +make_source_list(SOURCES_JIT_CORE + SOURCES + lj_asm.c + lj_ffrecord.c + lj_ir.c + lj_mcode.c + lj_record.c + lj_snap.c + lj_trace.c +) + +# JIT compiler, machine-independent optimisations. +make_source_list(SOURCES_JIT_OPT + SOURCES + lj_opt_dce.c + lj_opt_fold.c + lj_opt_loop.c + lj_opt_mem.c + lj_opt_narrow.c + lj_opt_sink.c + lj_opt_split.c +) + +make_source_list(SOURCES_FFI + SOURCES + lj_carith.c + lj_ccallback.c + lj_ccall.c + lj_cconv.c + lj_cdata.c + lj_clib.c + lj_cparse.c + lj_crecord.c + lj_ctype.c +) + +make_source_list(SOURCES_JIT + SOURCES + ${SOURCES_JIT_CORE} + ${SOURCES_JIT_OPT} +) + +# Everything except FFI and JIT. +make_source_list(SOURCES_CORE_NO_JIT_FFI + SOURCES + ${SOURCES_RUNTIME} + ${SOURCES_LUA_LIB} + ${SOURCES_FRONTEND} + ${SOURCES_PROFILER} + ${SOURCES_UTILS} +) + +set(SOURCES_CORE ${SOURCES_CORE_NO_JIT_FFI}) + +if(LUAJIT_HAS_JIT) + list(APPEND SOURCES_CORE ${SOURCES_JIT}) + if(LUAJIT_ENABLE_GDBJIT) + list(APPEND SOURCES_CORE ${CMAKE_CURRENT_SOURCE_DIR}/lj_gdbjit.c) + endif() +endif() + +if(LUAJIT_HAS_FFI) + list(APPEND SOURCES_CORE ${SOURCES_FFI}) + if(NOT LUAJIT_HAS_JIT) + # Needed for lj_mcode_sync. + list(APPEND SOURCES_CORE ${CMAKE_CURRENT_SOURCE_DIR}/lj_mcode.c) + endif() +endif() + +make_source_list(CLI_SOURCES + SOURCES + luajit.c +) + +# --- Set OS and arch specific flags ------------------------------------------- + +include(SetTargetFlags) +list(APPEND TARGET_LIBS m) + +# --- Prepare files generated by buildvm --------------------------------------- + +add_subdirectory(host) + +# VM assembly. +add_custom_command( + OUTPUT lj_vm.S + COMMAND $ -m ${BUILDVM_MODE} -o lj_vm.S + DEPENDS buildvm + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +# Bytecode definitions. +add_custom_command( + OUTPUT lj_bcdef.h + COMMAND $ -m bcdef -o lj_bcdef.h ${SOURCES_LUA_LIB} + DEPENDS buildvm ${SOURCES_LUA_LIB} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +# Fast function definitions. +add_custom_command( + OUTPUT lj_ffdef.h + COMMAND $ -m ffdef -o lj_ffdef.h ${SOURCES_LUA_LIB} + DEPENDS buildvm ${SOURCES_LUA_LIB} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +# Library definitions. +add_custom_command( + OUTPUT lj_libdef.h + COMMAND $ -m libdef -o lj_libdef.h ${SOURCES_LUA_LIB} + DEPENDS buildvm ${SOURCES_LUA_LIB} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +# Recorder definitions. +add_custom_command( + OUTPUT lj_recdef.h + COMMAND $ -m recdef -o lj_recdef.h ${SOURCES_LUA_LIB} + DEPENDS buildvm ${SOURCES_LUA_LIB} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +# Fold definitions. +add_custom_command( + OUTPUT lj_folddef.h + COMMAND $ -m folddef -o lj_folddef.h + ${CMAKE_CURRENT_SOURCE_DIR}/lj_opt_fold.c + DEPENDS buildvm lj_opt_fold.c + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +# VM definitions. +add_custom_command( + OUTPUT jit/vmdef.lua + COMMAND ${CMAKE_COMMAND} -E make_directory jit + COMMAND $ -m vmdef -o jit/vmdef.lua ${SOURCES_LUA_LIB} + DEPENDS buildvm ${SOURCES_LUA_LIB} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +add_custom_target( + buildvm_output + DEPENDS lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h + jit/vmdef.lua +) + +# --- Generate core and VM object files --------------------------------------- + +# Virtual machine. +add_library(vm_static OBJECT EXCLUDE_FROM_ALL lj_vm.S) +add_library(vm_shared OBJECT EXCLUDE_FROM_ALL lj_vm.S) +set_property(TARGET vm_shared APPEND PROPERTY + POSITION_INDEPENDENT_CODE ON +) +set_property(TARGET vm_static vm_shared APPEND PROPERTY + COMPILE_FLAGS "${TARGET_VM_FLAGS}" +) + +# Platform core. +add_library(core_static OBJECT EXCLUDE_FROM_ALL ${SOURCES_CORE}) +add_library(core_shared OBJECT EXCLUDE_FROM_ALL ${SOURCES_CORE}) +set_property(TARGET core_shared APPEND PROPERTY + POSITION_INDEPENDENT_CODE ON +) +set_property(TARGET core_static core_shared APPEND PROPERTY + COMPILE_FLAGS "${TARGET_C_FLAGS}" +) +target_include_directories(core_static PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(core_shared PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +add_dependencies(core_static buildvm_output) +add_dependencies(core_shared buildvm_output) + +# --- Generate output ---------------------------------------------------------- + +# Compiling and linking library binaries (static, shared). + +set(LIB_OBJECTS_STATIC + $ + $ +) +set(LIB_OBJECTS_SHARED + $ + $ +) + +add_library(libluajit_static STATIC EXCLUDE_FROM_ALL ${LIB_OBJECTS_STATIC}) +set_target_properties(libluajit_static PROPERTIES + OUTPUT_NAME "${LUAJIT_LIB_NAME}" + COMPILE_FLAGS "${TARGET_C_FLAGS}" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) +target_link_libraries(libluajit_static m) + +add_library(libluajit_shared SHARED EXCLUDE_FROM_ALL ${LIB_OBJECTS_SHARED}) +set_target_properties(libluajit_shared PROPERTIES + OUTPUT_NAME "${LUAJIT_LIB_NAME}" + COMPILE_FLAGS "${TARGET_C_FLAGS}" + LINK_FLAGS "${TARGET_SHARED_FLAGS}" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + VERSION "${LUAJIT_VERSION_MAJOR}.${LUAJIT_VERSION_MINOR}.${LUAJIT_VERSION_PATCH}" + SOVERSION "${LUAJIT_VERSION_MAJOR}" +) +target_link_libraries(libluajit_shared ${TARGET_LIBS}) + +# Compiling and linking CLIs. + +add_executable(luajit_static EXCLUDE_FROM_ALL ${CLI_SOURCES}) +set_target_properties(luajit_static PROPERTIES + OUTPUT_NAME "${LUAJIT_CLI_NAME}" + COMPILE_FLAGS "${TARGET_C_FLAGS}" + LINK_FLAGS "${TARGET_BIN_FLAGS}" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) +target_include_directories(luajit_static PRIVATE + ${CMAKE_CURRENT_BINARY_DIR} +) +target_link_libraries(luajit_static libluajit_static ${TARGET_LIBS}) + +add_executable(luajit_shared EXCLUDE_FROM_ALL ${CLI_SOURCES}) +set_target_properties(luajit_shared PROPERTIES + OUTPUT_NAME "${LUAJIT_CLI_NAME}" + COMPILE_FLAGS "${TARGET_C_FLAGS}" + LINK_FLAGS "${TARGET_BIN_FLAGS}" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) +target_include_directories(luajit_shared PRIVATE + ${CMAKE_CURRENT_BINARY_DIR} +) +target_link_libraries(luajit_shared libluajit_shared ${TARGET_LIBS}) + +if(NOT BUILDMODE STREQUAL "dynamic") + set(LIBLUAJIT_STATIC_DEPS libluajit_static) +endif() +if(NOT BUILDMODE STREQUAL "static") + set(LIBLUAJIT_SHARED_DEPS libluajit_shared) +endif() +set(LIBLUAJIT_DEPS ${LIBLUAJIT_STATIC_DEPS} ${LIBLUAJIT_SHARED_DEPS}) + +if(BUILDMODE STREQUAL "dynamic") + set(LUAJIT_DEPS luajit_shared) +else() + set(LUAJIT_DEPS luajit_static) +endif() + +add_custom_target(libluajit DEPENDS ${LIBLUAJIT_DEPS}) +add_custom_target(luajit ALL DEPENDS libluajit ${LUAJIT_DEPS}) + +install(TARGETS ${LUAJIT_DEPS} + RUNTIME + DESTINATION bin + COMPONENT luajit +) +install(TARGETS ${LIBLUAJIT_STATIC_DEPS} + ARCHIVE + DESTINATION lib + COMPONENT luajit +) +install(TARGETS ${LIBLUAJIT_SHARED_DEPS} + LIBRARY + DESTINATION lib + COMPONENT luajit +) + +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/lua.h # C API for Lua + ${CMAKE_CURRENT_SOURCE_DIR}/lualib.h # Lua standard libraries + ${CMAKE_CURRENT_SOURCE_DIR}/lauxlib.h # Auxiliary library's C API + ${CMAKE_CURRENT_SOURCE_DIR}/luaconf.h # Configuration header + ${CMAKE_CURRENT_SOURCE_DIR}/lua.hpp # Convenience wrapper for C++ + ${CMAKE_CURRENT_SOURCE_DIR}/luajit.h # LuaJIT-specific header + ${CMAKE_CURRENT_SOURCE_DIR}/lmisclib.h # Miscellaneous C API extensions + DESTINATION ${LUAJIT_INCLUDEDIR} + PERMISSIONS + OWNER_READ OWNER_WRITE + GROUP_READ + WORLD_READ + COMPONENT luajit +) + +install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/jit/bc.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/bcsave.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/dump.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/p.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/v.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/zone.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_x86.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_x64.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm64.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_arm64be.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_ppc.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mipsel.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips64.lua + ${CMAKE_CURRENT_SOURCE_DIR}/jit/dis_mips64el.lua + ${CMAKE_CURRENT_BINARY_DIR}/jit/vmdef.lua + DESTINATION ${LUAJIT_DATAROOTDIR}/jit + PERMISSIONS + OWNER_READ OWNER_WRITE + GROUP_READ + WORLD_READ + COMPONENT luajit +) diff --git a/src/host/CMakeLists.txt b/src/host/CMakeLists.txt new file mode 100644 index 0000000..fe2de5c --- /dev/null +++ b/src/host/CMakeLists.txt @@ -0,0 +1,61 @@ +# Building the toolchain for LuaJIT VM preprocessing. + +cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) + +# FIXME: Both minilua and buildvm need to be build with the HOST_* +# toolchain. + +# XXX: DynASM flags are set considering the target arch +include(SetDynASMFlags) + +# --- Build minilua ------------------------------------------------------------ + +# If left blank, minilua is built and used. You can supply an installed +# copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua. +if(NOT HOST_LUA) + set(MINILUA minilua) + add_executable(${MINILUA} minilua.c) + target_link_libraries(${MINILUA} m) + set(HOST_LUA $) +else() + separate_arguments(HOST_LUA UNIX_COMMAND ${HOST_LUA}) +endif() + +# --- Prepare dasm-ed VM description ------------------------------------------- + +set(DYNASM_DIR ${PROJECT_SOURCE_DIR}/dynasm) +set(DYNASM_DASC "${LUAJIT_SOURCE_DIR}/vm_${DYNASM_ARCH}.dasc") +set(DYNASM ${HOST_LUA} ${DYNASM_DIR}/dynasm.lua) + +add_custom_command( + COMMENT "Generating buildvm_arch.h" + OUTPUT buildvm_arch.h + COMMAND ${DYNASM} ${DYNASM_FLAGS} -o buildvm_arch.h ${DYNASM_DASC} + DEPENDS ${MINILUA} ${DYNASM_DASC} ${DYNASM_DIR}/*.lua + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +# --- Build buildvm ------------------------------------------------------------ + +add_executable(buildvm EXCLUDE_FROM_ALL + buildvm.c + buildvm_asm.c + buildvm_fold.c + buildvm_lib.c + buildvm_peobj.c + # XXX: Unfortunately CMake is a crap. I failed to specify + # autogenerated host/buildvm_arch.h as a dependency for + # host/buildvm.c, so I simply explicitly mentioned it in this + # *sources* list. + buildvm_arch.h +) +set_source_files_properties(buildvm.c PROPERTIES + OBJECT_DEPENDS ${DYNASM_DIR}/dasm_*.h +) +set_target_properties(buildvm PROPERTIES + COMPILE_FLAGS "${HOST_C_FLAGS} ${TARGET_C_FLAGS}" +) +target_include_directories(buildvm PRIVATE + ${LUAJIT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} +) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 0000000..f9ffc5e --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,77 @@ +# Building tools for developing with uJIT. +# Major portions taken verbatim or adapted from the uJIT. +# Copyright (C) 2015-2019 IPONWEB Ltd. + +# See the rationale in the root CMakeLists.txt +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) + +set(LUAJIT_TOOLS_DEPS) + +if(LUAJIT_DISABLE_MEMPROF) + message(STATUS "LuaJIT memory profiler support is disabled") +else() + # XXX: Can use genex here since the value need to be evaluated + # on the configuration phase. Fortunately, we know the exact + # path where LuaJIT binary is located. + set(LUAJIT_TOOLS_BIN ${LUAJIT_BINARY_DIR}/${LUAJIT_CLI_NAME}) + set(LUAJIT_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + configure_file(luajit-parse-memprof.in luajit-parse-memprof @ONLY ESCAPE_QUOTES) + + add_custom_target(tools-parse-memprof EXCLUDE_FROM_ALL DEPENDS + luajit-parse-memprof + memprof/humanize.lua + memprof/parse.lua + memprof.lua + utils/bufread.lua + utils/symtab.lua + ) + list(APPEND LUAJIT_TOOLS_DEPS tools-parse-memprof) + + install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/memprof/humanize.lua + ${CMAKE_CURRENT_SOURCE_DIR}/memprof/parse.lua + DESTINATION ${LUAJIT_DATAROOTDIR}/memprof + PERMISSIONS + OWNER_READ OWNER_WRITE + GROUP_READ + WORLD_READ + COMPONENT tools-parse-memprof + ) + install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/utils/bufread.lua + ${CMAKE_CURRENT_SOURCE_DIR}/utils/symtab.lua + DESTINATION ${LUAJIT_DATAROOTDIR}/utils + PERMISSIONS + OWNER_READ OWNER_WRITE + GROUP_READ + WORLD_READ + COMPONENT tools-parse-memprof + ) + install(FILES + ${CMAKE_CURRENT_SOURCE_DIR}/memprof.lua + DESTINATION ${LUAJIT_DATAROOTDIR} + PERMISSIONS + OWNER_READ OWNER_WRITE + GROUP_READ + WORLD_READ + COMPONENT tools-parse-memprof + ) + install(CODE + # XXX: Since the auxiliary script need to be configured in + # other way it need to be reconfigured it prior to its + # installation. Unfortunately, we need to manually specify + # the installation path in command. + # Hope this script will be gone as a result of the issue below + # https://github.com/tarantool/tarantool/issues/5688. + " + set(LUAJIT_TOOLS_BIN ${CMAKE_INSTALL_PREFIX}/bin/${LUAJIT_CLI_NAME}) + set(LUAJIT_TOOLS_DIR ${CMAKE_INSTALL_PREFIX}/${LUAJIT_DATAROOTDIR}) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/luajit-parse-memprof.in + ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof @ONLY ESCAPE_QUOTES) + message(STATUS \"Installing: ${CMAKE_INSTALL_PREFIX}/bin/luajit-parse-memprof\") + " + COMPONENT tools-parse-memprof + ) +endif() + +add_custom_target(LuaJIT-tools DEPENDS ${LUAJIT_TOOLS_DEPS}) -- 2.25.0