Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ else()
endif()
declare_project(thirdparty/kobo-usbms ${EXCLUDE_FROM_ALL})

# lanes
declare_project(thirdparty/lanes DEPENDS luajit)

# leptonica
declare_project(thirdparty/leptonica DEPENDS libpng)

Expand Down
1 change: 1 addition & 0 deletions ffi-cdecl/lanes_cdecl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cdecl_func(luaopen_lanes_core)
2 changes: 2 additions & 0 deletions thirdparty/cmake_modules/koreader_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ if(MONOLIBTIC)
freetype2::freetype
giflib::gif
harfbuzz::harfbuzz
lanes::core
leptonica::leptonica
libjpeg-turbo::turbojpeg
libk2pdfopt::k2pdfopt
Expand Down Expand Up @@ -347,6 +348,7 @@ if(MONOLIBTIC)
giflib_decl
harfbuzz_cdecl
koptcontext_cdecl
lanes_cdecl
leptonica_cdecl
libarchive_cdecl
libwebp_decl
Expand Down
5 changes: 5 additions & 0 deletions thirdparty/cmake_modules/koreader_thirdparty_libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ declare_dependency(giflib::gif MONOLIBTIC gif)
# harfbuzz
declare_dependency(harfbuzz::harfbuzz INCLUDES freetype2 harfbuzz MONOLIBTIC harfbuzz)

# lanes
if(MONOLIBTIC)
declare_dependency(lanes::core LIBRARIES ${STAGING_DIR}/lib/lanes/core.a)
endif()

# libarchive
declare_dependency(libarchive::libarchive MONOLIBTIC archive)

Expand Down
32 changes: 32 additions & 0 deletions thirdparty/lanes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
list(APPEND PATCH_FILES
# Fix inline shenanigans.
fix_debug_build.patch
# Allow compiling with `-fvisibility=hidden`.
visibility.patch
)

list(APPEND CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DBUILD_SHARED_LIBS=$<NOT:$<BOOL:${MONOLIBTIC}>>
# Project options.
-DANDROID=${ANDROID}
)

list(APPEND BUILD_CMD COMMAND ninja)

append_install_commands(INSTALL_CMD ${SOURCE_DIR}/src/lanes.lua DESTINATION common)
if(MONOLIBTIC)
append_install_commands(INSTALL_CMD core.a DESTINATION ${STAGING_DIR}/lib/lanes)
else()
append_binary_install_command(INSTALL_CMD core.so DESTINATION common/lanes)
endif()

external_project(
DOWNLOAD GIT v3.17.1
https://github.com/LuaLanes/lanes.git
PATCH_FILES ${PATCH_FILES}
PATCH_OVERLAY overlay
CMAKE_ARGS ${CMAKE_ARGS}
BUILD_COMMAND ${BUILD_CMD}
INSTALL_COMMAND ${INSTALL_CMD}
)
20 changes: 20 additions & 0 deletions thirdparty/lanes/fix_debug_build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- a/src/macros_and_utils.h
+++ b/src/macros_and_utils.h
@@ -82,6 +82,7 @@

#define ASSERT_L(c) _ASSERT_L(L,c)

+__attribute__ ((always_inline))
inline void STACK_GROW(lua_State * L, int n_)
{
if (!lua_checkstack(L, n_))
--- a/src/lanes_private.h
+++ b/src/lanes_private.h
@@ -79,6 +79,7 @@
// 'Lane' are malloc/free'd and the handle only carries a pointer.
// This is not deep userdata since the handle's not portable among lanes.
//
+__attribute__ ((always_inline))
inline Lane* lua_toLane(lua_State* L, int i_)
{
return *(Lane**)(luaL_checkudata(L, i_, "Lane"));
31 changes: 31 additions & 0 deletions thirdparty/lanes/overlay/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.17.5)
project(lanes LANGUAGES C)

set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(LuaJIT luajit REQUIRED IMPORTED_TARGET)

if(BUILD_SHARED_LIBS)
add_library(core MODULE)
else()
add_library(core STATIC)
endif()
set_target_properties(core PROPERTIES C_VISIBILITY_PRESET hidden PREFIX "")
target_link_libraries(core PRIVATE PkgConfig::LuaJIT Threads::Threads m)
if(ANDROID)
target_link_libraries(core PRIVATE log)
endif()
target_sources(core PRIVATE
src/lanes.c
src/cancel.c
src/compat.c
src/threading.c
src/tools.c
src/state.c
src/linda.c
src/deep.c
src/keeper.c
src/universe.c
)
22 changes: 22 additions & 0 deletions thirdparty/lanes/visibility.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/src/deep.h
+++ b/src/deep.h
@@ -18,7 +18,7 @@
#if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC)
#define LANES_API __declspec(dllexport)
#else
-#define LANES_API
+#define LANES_API __attribute__ ((visibility("default")))
#endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC)
#endif // LANES_API

--- a/src/lanes.h
+++ b/src/lanes.h
@@ -7,7 +7,7 @@
#if (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC)
#define LANES_API __declspec(dllexport)
#else
-#define LANES_API
+#define LANES_API __attribute__ ((visibility("default")))
#endif // (defined PLATFORM_WIN32) || (defined PLATFORM_POCKETPC)

#define LANES_VERSION_MAJOR 3