diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 3936f9035..9cf262a87 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -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) diff --git a/ffi-cdecl/lanes_cdecl.c b/ffi-cdecl/lanes_cdecl.c new file mode 100644 index 000000000..07ccb6531 --- /dev/null +++ b/ffi-cdecl/lanes_cdecl.c @@ -0,0 +1 @@ +cdecl_func(luaopen_lanes_core) diff --git a/thirdparty/cmake_modules/koreader_targets.cmake b/thirdparty/cmake_modules/koreader_targets.cmake index 1a94fcea7..af64918fa 100644 --- a/thirdparty/cmake_modules/koreader_targets.cmake +++ b/thirdparty/cmake_modules/koreader_targets.cmake @@ -298,6 +298,7 @@ if(MONOLIBTIC) freetype2::freetype giflib::gif harfbuzz::harfbuzz + lanes::core leptonica::leptonica libjpeg-turbo::turbojpeg libk2pdfopt::k2pdfopt @@ -347,6 +348,7 @@ if(MONOLIBTIC) giflib_decl harfbuzz_cdecl koptcontext_cdecl + lanes_cdecl leptonica_cdecl libarchive_cdecl libwebp_decl diff --git a/thirdparty/cmake_modules/koreader_thirdparty_libs.cmake b/thirdparty/cmake_modules/koreader_thirdparty_libs.cmake index dea138078..41f8648d0 100644 --- a/thirdparty/cmake_modules/koreader_thirdparty_libs.cmake +++ b/thirdparty/cmake_modules/koreader_thirdparty_libs.cmake @@ -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) diff --git a/thirdparty/lanes/CMakeLists.txt b/thirdparty/lanes/CMakeLists.txt new file mode 100644 index 000000000..98fc12e30 --- /dev/null +++ b/thirdparty/lanes/CMakeLists.txt @@ -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=$> + # 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} +) diff --git a/thirdparty/lanes/fix_debug_build.patch b/thirdparty/lanes/fix_debug_build.patch new file mode 100644 index 000000000..869470ca7 --- /dev/null +++ b/thirdparty/lanes/fix_debug_build.patch @@ -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")); diff --git a/thirdparty/lanes/overlay/CMakeLists.txt b/thirdparty/lanes/overlay/CMakeLists.txt new file mode 100644 index 000000000..2c10ef442 --- /dev/null +++ b/thirdparty/lanes/overlay/CMakeLists.txt @@ -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 +) diff --git a/thirdparty/lanes/visibility.patch b/thirdparty/lanes/visibility.patch new file mode 100644 index 000000000..a0d51cbce --- /dev/null +++ b/thirdparty/lanes/visibility.patch @@ -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