Skip to content

Commit

Permalink
refactor(build): include lpeg as a library
Browse files Browse the repository at this point in the history
  • Loading branch information
bfredl committed Apr 26, 2023
1 parent 9f0762f commit 61a9908
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 44 deletions.
12 changes: 3 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,21 @@ foreach(CFGNAME ${CMAKE_CONFIGURATION_TYPES})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CFGNAME} ${CMAKE_BINARY_DIR}/lib)
endforeach()

set(LUA_DEPENDENCIES lpeg)
if(NOT LUA_PRG)
foreach(CURRENT_LUA_PRG luajit lua5.1 lua5.2 lua)
unset(_CHECK_LUA_PRG CACHE)
unset(LUA_PRG_WORKS)
find_program(_CHECK_LUA_PRG ${CURRENT_LUA_PRG})

if(_CHECK_LUA_PRG)
check_lua_deps(${_CHECK_LUA_PRG} "${LUA_DEPENDENCIES}" LUA_PRG_WORKS)
if(LUA_PRG_WORKS)
set(LUA_PRG "${_CHECK_LUA_PRG}" CACHE FILEPATH "Path to a program.")
break()
endif()
set(LUA_PRG "${_CHECK_LUA_PRG}" CACHE FILEPATH "Path to a program.")
break()
endif()
endforeach()
unset(_CHECK_LUA_PRG CACHE)
else()
check_lua_deps(${LUA_PRG} "${LUA_DEPENDENCIES}" LUA_PRG_WORKS)
endif()

if(NOT LUA_PRG_WORKS)
if(NOT LUA_PRG)
message(FATAL_ERROR "Failed to find a Lua 5.1-compatible interpreter")
endif()

Expand Down
8 changes: 8 additions & 0 deletions cmake.deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ option(USE_BUNDLED_MSGPACK "Use the bundled msgpack." ${USE_BUNDLED})
option(USE_BUNDLED_LUAJIT "Use the bundled version of luajit." ${USE_BUNDLED})
option(USE_BUNDLED_LUAROCKS "Use the bundled version of luarocks." ${USE_BUNDLED})
option(USE_BUNDLED_LUV "Use the bundled version of luv." ${USE_BUNDLED})
option(USE_BUNDLED_LPEG "Use the bundled lpeg." ${USE_BUNDLED})
#XXX(tarruda): Lua is only used for debugging the functional test client, don't
# build it unless explicitly requested
option(USE_BUNDLED_LUA "Use the bundled version of lua." OFF)
Expand Down Expand Up @@ -161,6 +162,9 @@ set(LIBVTERM_SHA256 25a8ad9c15485368dfd0a8a9dca1aec8fea5c27da3fa74ec518d5d3787f0
set(LUV_URL https://github.com/luvit/luv/archive/093a977b82077591baefe1e880d37dfa2730bd54.tar.gz)
set(LUV_SHA256 222b38b6425f0926218e14e7da81481fdde6f9660c1feac25a53e6fb52e886e6)

set(LPEG_URL http://www.inf.puc-rio.br/~roberto/lpeg/lpeg-1.0.2.tar.gz)
set(LPEG_SHA256 48d66576051b6c78388faad09b70493093264588fcd0f258ddaab1cdd4a15ffe)

set(LUA_COMPAT53_URL https://github.com/keplerproject/lua-compat-5.3/archive/v0.9.tar.gz)
set(LUA_COMPAT53_SHA256 ad05540d2d96a48725bb79a1def35cf6652a4e2ec26376e2617c8ce2baa6f416)

Expand Down Expand Up @@ -245,6 +249,10 @@ if(USE_BUNDLED_LUV)
include(BuildLuv)
endif()

if(USE_BUNDLED_LPEG)
include(BuildLpeg)
endif()

if(USE_BUNDLED_GETTEXT)
include(BuildGettext)
endif()
Expand Down
22 changes: 22 additions & 0 deletions cmake.deps/cmake/BuildLpeg.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# TODO: these two from BuildLuv, deduplicate
set(LPEG_INCLUDE_FLAGS
"-I${DEPS_INSTALL_DIR}/include -I${DEPS_INSTALL_DIR}/include/luajit-2.1")
list(APPEND LPEG_CMAKE_ARGS
"-DCMAKE_C_FLAGS:STRING=${LPEG_INCLUDE_FLAGS}")

ExternalProject_Add(lpeg
URL ${LPEG_URL}
URL_HASH SHA256=${LPEG_SHA256}
DOWNLOAD_NO_PROGRESS TRUE
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/lpeg
PATCH_COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/cmake/LpegCMakeLists.txt
${DEPS_BUILD_DIR}/src/lpeg/CMakeLists.txt
CMAKE_ARGS ${DEPS_CMAKE_ARGS} ${LPEG_CMAKE_ARGS}
CMAKE_CACHE_ARGS ${DEPS_CMAKE_CACHE_ARGS})

if(USE_BUNDLED_LUAJIT)
add_dependencies(lpeg luajit)
elseif(USE_BUNDLED_LUA)
add_dependencies(lpeg lua)
endif()
2 changes: 0 additions & 2 deletions cmake.deps/cmake/BuildLuarocks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ function(Download ROCK VER)
set(CURRENT_DEP ${ROCK} PARENT_SCOPE)
endfunction()

Download(lpeg 1.0.2-1)

if(USE_BUNDLED_BUSTED)
if(WIN32)
set(BUSTED_EXE "${DEPS_BIN_DIR}/busted.bat")
Expand Down
11 changes: 11 additions & 0 deletions cmake.deps/cmake/LpegCMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.10)
project (lpeg C)

include(GNUInstallDirs)

file(GLOB LPEG_SOURCES ${CMAKE_SOURCE_DIR}/*.c)
add_library(lpeg STATIC ${LPEG_SOURCES})

install(TARGETS lpeg ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

# vim: set ft=cmake:
14 changes: 14 additions & 0 deletions cmake/FindLpeg.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
find_library(LPEG_LIBRARY NAMES lpeg_a lpeg liblpeg_a)

# Ubuntu-specific workaround to find system paths
function(ubuntu)
set(CMAKE_FIND_LIBRARY_PREFIXES "")
find_library(LPEG_LIBRARY NAMES lpeg PATH_SUFFIXES lua/5.1)
endfunction()
ubuntu()

message(STATUS "KRARK")
message(STATUS "${LPEG_LIBRARY}")

find_package_handle_standard_args(Lpeg DEFAULT_MSG LPEG_LIBRARY )
mark_as_advanced(LPEG_LIBRARY)
23 changes: 0 additions & 23 deletions cmake/LuaHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,3 @@ function(check_lua_module LUA_PRG_PATH MODULE RESULT_VAR)
set(${RESULT_VAR} True PARENT_SCOPE)
endif()
endfunction()

# Check Lua interpreter for dependencies
function(check_lua_deps LUA_PRG_PATH MODULES RESULT_VAR)
# Check if the lua interpreter at the given path
# satisfies all Neovim dependencies
message(STATUS "Checking Lua interpreter: ${LUA_PRG_PATH}")
if(NOT EXISTS ${LUA_PRG_PATH})
message(STATUS
"[${LUA_PRG_PATH}] file not found")
endif()

foreach(module ${MODULES})
check_lua_module(${LUA_PRG_PATH} ${module} has_module)
if(NOT has_module)
message(STATUS
"[${LUA_PRG_PATH}] The '${module}' lua package is required for building Neovim")
set(${RESULT_VAR} False PARENT_SCOPE)
return()
endif()
endforeach()

set(${RESULT_VAR} True PARENT_SCOPE)
endfunction()
7 changes: 7 additions & 0 deletions runtime/doc/lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,13 @@ regex:match_line({bufnr}, {line_idx} [, {start}, {end}]) *regex:match_line()*
|regex:match_str()|. If {start} is used, then the returned byte indices
will be relative {start}.

------------------------------------------------------------------------------
VIM.LPEG *lua-lpeg*

*vim.lpeg* *vim.re*
The Lpeg library for parsing expression grammars is being included as
`vim.lpeg`. In additional its regex-like interface is available as `vim.re`.

------------------------------------------------------------------------------
VIM.DIFF *lua-diff*

Expand Down
1 change: 1 addition & 0 deletions runtime/lua/vim/_init_packages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ vim._submodules = {
version = true,
fs = true,
iter = true,
re = true,
}

-- These are for loading runtime modules in the vim namespace lazily.
Expand Down
Loading

0 comments on commit 61a9908

Please sign in to comment.