Skip to content

Commit

Permalink
Fix C file generation in jit.bcsave.
Browse files Browse the repository at this point in the history
Thanks to codicodi.

(cherry picked from commit 62903ba)

--- l1.txt      2023-10-18 19:21:23.939547944 +0300
+++ l2.txt      2023-10-18 19:21:28.891489600 +0300
@@ -8,12 +8,11 @@
...
-0000000000002000 R luaJIT_BC_lj_lib_xxx
...
  • Loading branch information
Mike Pall authored and ligurio committed Oct 18, 2023
1 parent 7d5901d commit 10f8470
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/jit/bcsave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ local function bcsave_c(ctx, output, s)
local fp = savefile(output, "w")
if ctx.type == "c" then
fp:write(format([[
#ifdef _cplusplus
#ifdef __cplusplus
extern "C"
#endif
#ifdef _WIN32
Expand Down
1 change: 1 addition & 0 deletions test/tarantool-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ add_subdirectory(lj-727-lightuserdata-itern)
add_subdirectory(lj-802-panic-at-mcode-protfail)
add_subdirectory(lj-flush-on-trace)
add_subdirectory(lj-1004-oom-error-frame)
add_subdirectory(lj-jit-bcsave-c-generation)

# The part of the memory profiler toolchain is located in tools
# directory, jit, profiler, and bytecode toolchains are located
Expand Down
13 changes: 13 additions & 0 deletions test/tarantool-tests/lj-jit-bcsave-c-generation.test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local tap = require('tap')
local test = tap.test('lj-jit-bcsave-c-generation')

test:plan(1)

local module_name = 'lj_lib_xxx'
local ok, _ = pcall(require, module_name)
local symbol_name = ('luaJIT_BC_%s'):format(module_name)
local message = ('symbol "%s" is available in a library'):format(module_name)

test:ok(ok == true, message)

test:done(true)
46 changes: 46 additions & 0 deletions test/tarantool-tests/lj-jit-bcsave-c-generation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
set(LIB_NAME "lj_lib_xxx")
set(LUA_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.lua)
set(C_FILE ${LIB_NAME}.c)
set(CXX_FILE ${LIB_NAME}.cc)

make_lua_path(LUA_PATH
PATHS
${PROJECT_SOURCE_DIR}/src/?.lua
${PROJECT_SOURCE_DIR}/src/jit/?.lua
)

add_custom_target(export_bc
COMMAND ${CMAKE_COMMAND} -E env LUA_PATH=${LUA_PATH} ${LUAJIT_BINARY} -b ${LUA_FILE} ${C_FILE}
# Enforce CMake to using CXX compiler.
# COMMAND ${CMAKE_COMMAND} -E rename ${C_FILE} ${CXX_FILE}
DEPENDS luajit-main ${LUA_FILE}
# BYPRODUCTS ${CXX_FILE}
BYPRODUCTS ${C_FILE}
COMMENT "Exporting bytecode to a C file"
VERBATIM
)

# add_custom_command(
# OUTPUT ${CXX_FILE}
# COMMAND ${CMAKE_COMMAND} -E env LUA_PATH=${LUA_PATH} ${LUAJIT_BINARY} -b ${LUA_FILE} ${C_FILE}
# # Enforce CMake to using CXX compiler.
# COMMAND ${CMAKE_COMMAND} -E rename ${C_FILE} ${CXX_FILE}
# DEPENDS luajit-main ${LUA_FILE}
# BYPRODUCTS ${CXX_FILE}
# COMMENT "Exporting bytecode to a C file"
# VERBATIM
# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
# )

# add_library(${LIB_NAME} SHARED OBJECT EXCLUDE_FROM_ALL ${CXX_FILE})
# add_dependencies(${LIB_NAME} export_bc)
# # set_target_properties("xxx" PROPERTIES LINKER_LANGUAGE CXX)
# set_target_properties(${LIB_NAME} PROPERTIES
# LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
# PREFIX ""
# )
# list(APPEND TESTLIBS ${LIB_NAME})

# BuildTestCLib(${LIB_NAME} ${CXX_FILE})
BuildTestCLib(${LIB_NAME} ${C_FILE})
add_dependencies(${LIB_NAME} export_bc)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local a = 1
local b = 2

return {
a = a,
b = b,
}

0 comments on commit 10f8470

Please sign in to comment.