diff --git a/Makefile b/Makefile index 26bdd1ca2..052155fc8 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ $(BASE_PREFIX)clean: rm -rf $(OUTPUT_DIR) $(BASE_PREFIX)distclean: - rm -rf $(dir $(filter $(KOR_BASE)/build/%,$(OUTPUT_DIR))) $(wildcard $(THIRDPARTY_DIR)/*/build) + rm -rf $(dir $(filter $(KOR_BASE)/build/%,$(OUTPUT_DIR))) $(wildcard $(THIRDPARTY_DIR)/*/build $(THIRDPARTY_DIR)/spec/*/build) info: $(strip $(build_info)) @@ -190,7 +190,7 @@ cache-key: $(KOR_BASE)/Makefile $(KOR_BASE)/cache-key.base define BINARY_PATHS $(filter-out - $(addprefix $(OUTPUT_DIR)/,cmake staging thirdparty), + $(addprefix $(OUTPUT_DIR)/,cmake spec staging thirdparty), $(wildcard $(OUTPUT_DIR)/*)) endef diff --git a/Makefile.defs b/Makefile.defs index 600b0093b..0d6dd0f5d 100644 --- a/Makefile.defs +++ b/Makefile.defs @@ -667,6 +667,7 @@ endif OUTPUT_DIR ?= $(KOR_BASE)/build/$(MACHINE) CMAKE_DIR = $(OUTPUT_DIR)/cmake STAGING_DIR = $(OUTPUT_DIR)/staging +SPEC_ROCKS_DIR = $(OUTPUT_DIR)/spec/rocks BUILD_ENTRYPOINT = $(CMAKE_DIR)/build.ninja @@ -763,13 +764,7 @@ endif THIRDPARTY_DIR = $(KOR_BASE)/thirdparty -LUAROCKS_BINARY := $(firstword $(shell command -v luarocks luarocks-5.1)) -ifneq (,$(LUAROCKS_BINARY)) - # Detect versioned LR 3 binary, see koreader-base/pull/1003 - ifneq (,$(shell $(LUAROCKS_BINARY) --help | grep -Eo -- --lua-version)) - LUAROCKS_BINARY += --lua-version=5.1 - endif -endif +LUAROCKS_BINARY := $(abspath $(STAGING_DIR)/bin/luarocks) # Dynamic libraries must be compiled with "-shared" and "-fPIC". # (And we enforce PIC everywhere via CFLAGS/CXXFLAGS). @@ -927,6 +922,7 @@ set(VECTO_CFLAGS "$(VECTO_CFLAGS)") set(BASE_DIR $(abspath $(KOR_BASE))) set(OUTPUT_DIR $(abspath $(OUTPUT_DIR))) set(STAGING_DIR $(abspath $(STAGING_DIR))) +set(SPEC_ROCKS_DIR $(abspath $(SPEC_ROCKS_DIR))) set(THIRDPARTY_DIR $(abspath $(THIRDPARTY_DIR))) set(MAKE $(MAKE)) @@ -1079,7 +1075,8 @@ ifneq (,$(EMULATE_READER)) define busted_fn busted() {( -eval "$$($(LUAROCKS_BINARY) path)"; +export LUA_CPATH='./?.so;$(abspath $(SPEC_ROCKS_DIR)/lib/lua/5.1/?.so)' +export LUA_PATH='./?.lua;$(abspath $(SPEC_ROCKS_DIR)/share/lua/5.1/?.lua);$(abspath $(SPEC_ROCKS_DIR)/share/lua/5.1/?/init.lua)' export TESSDATA_DIR="$$PWD/data"; ./luajit -e 'require "busted.runner" {standalone = false}' /dev/null --exclude-tags=notest diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index d8a9bf352..2f84e224a 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -305,6 +305,9 @@ declare_project(thirdparty/luajit) # luajson declare_project(thirdparty/luajson) +# luarocks +declare_project(thirdparty/luarocks DEPENDS luajit EXCLUDE_FROM_ALL) + # luasec declare_project(thirdparty/luasec DEPENDS luajit luasocket openssl) @@ -405,6 +408,29 @@ declare_project(thirdparty/zsync2 DEPENDS curl openssl zlib ${EXCLUDE_FROM_ALL}) # }}} +# TESTSUITE DEPENDENCIES. {{{ + +if(EMULATE_READER) + add_custom_target(spec-rocks) + foreach(PRJ + busted + dkjson + lua-term + lua_cliargs + luafilesystem + luassert + luasystem + mediator_lua + penlight + say + ) + declare_project(thirdparty/spec/${PRJ} DEPENDS luarocks) + add_dependencies(spec-rocks ${PRJ}) + endforeach() +endif() + +# }}} + # Koreader executables and libs. # NOTE: thirdparty dependencies are manually handled later # for finer control (see `cmake/koreader/CMakeLists.txt` diff --git a/thirdparty/cmake_modules/koenv.sh b/thirdparty/cmake_modules/koenv.sh index 28045b672..09f21814b 100644 --- a/thirdparty/cmake_modules/koenv.sh +++ b/thirdparty/cmake_modules/koenv.sh @@ -99,6 +99,12 @@ extract_archive() { ( # Of course `cmake -E tar` does not support `--strip-components=n`, # so we need to use a temporary directory and move things around… rm -rf "${sourcedir}" "${sourcedir}.tmp" || return 1 + case "${archive}" in + *.src.rock) + # Luarocks source rock, there's no need to extract it. + return 0 + ;; + esac mkdir "${sourcedir}.tmp" || return 1 oldpwd="${PWD}" cd "${sourcedir}.tmp" diff --git a/thirdparty/cmake_modules/koreader_external_project.cmake b/thirdparty/cmake_modules/koreader_external_project.cmake index 3b8bb912e..7ae5e3ed9 100644 --- a/thirdparty/cmake_modules/koreader_external_project.cmake +++ b/thirdparty/cmake_modules/koreader_external_project.cmake @@ -320,3 +320,61 @@ function(external_project) ) endfunction() + +function(luarocks_external_project URL MD5) + + # Arguments. + cmake_parse_arguments( + PARSE_ARGV 2 + # Prefix. + "" + # Options. + "" + # One value keywords. + "ROCKSPEC;TREE" + # Multi-value keywords. + "" + ) + if(_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "unparsed arguments: ${_UNPARSED_ARGUMENTS}") + endif() + if(NOT DEFINED _TREE) + set(_TREE ${STAGING_DIR}) + endif() + + # Build command. + if(DEFINED _ROCKSPEC) + # Build in source tree. + set(BINARY_DIR ${SOURCE_DIR}) + endif() + list(APPEND BUILD_CMD COMMAND ${STAGING_DIR}/bin/luarocks --tree ${BINARY_DIR}/dist) + if(URL MATCHES [=[/([a-z0-9_-]+)-(([0-9]+)(\.[0-9]+)*-[0-9]+)\.src\.rock$]=]) + # From source rock (e.g https://luarocks.org/manifests/lunarmodules/say-1.4.1-3.src.rock). + set(NAME ${CMAKE_MATCH_1}) + set(VERSION ${CMAKE_MATCH_2}) + list(APPEND BUILD_CMD build ${DOWNLOAD_DIR}/${NAME}-${VERSION}.src.rock) + else() + if(NOT DEFINED _ROCKSPEC) + message(FATAL_ERROR "missing ROCKSPEC for luarocks project: ${PROJECT_NAME}") + endif() + list(APPEND BUILD_CMD make ${_ROCKSPEC}) + endif() + list(APPEND BUILD_CMD --deps-mode none --force-fast --no-doc --no-manifest) + + # Install command. + list(APPEND INSTALL_CMD COMMAND mkdir -p ${SPEC_ROCKS_DIR}) + list(APPEND INSTALL_CMD COMMAND ${CMAKE_COMMAND} -E copy_directory ${BINARY_DIR}/dist ${_TREE}) + + # External project. + external_project( + DOWNLOAD URL ${MD5} ${URL} + BUILD_COMMAND ${BUILD_CMD} + INSTALL_COMMAND ${INSTALL_CMD} + ) + +endfunction() + +function(spec_rock) + cmake_parse_arguments(PARSE_ARGV 0 "" "" "" "") + luarocks_external_project(${_UNPARSED_ARGUMENTS} TREE ${SPEC_ROCKS_DIR}) +endfunction() diff --git a/thirdparty/luarocks/CMakeLists.txt b/thirdparty/luarocks/CMakeLists.txt new file mode 100644 index 000000000..5a9cdbb9f --- /dev/null +++ b/thirdparty/luarocks/CMakeLists.txt @@ -0,0 +1,26 @@ +# Build in source tree. +set(BINARY_DIR ${SOURCE_DIR}) + +list(APPEND CFG_CMD COMMAND + ./configure + --prefix=${STAGING_DIR} + --with-lua=${STAGING_DIR} +) + +list(APPEND BUILD_CMD COMMAND make) + +list(APPEND INSTALL_CMD COMMAND make install) + +# Try to use our compilation flags. +set(LIBFLAGS ${DYNLIB_LDFLAGS}) +foreach(VAR CC CFLAGS LIBFLAGS) + list(APPEND INSTALL_CMD COMMAND ${STAGING_DIR}/bin/luarocks config -- ${VAR} "${${VAR}}") +endforeach() + +external_project( + DOWNLOAD URL ab95865ced3c123908bd2f1fe6843606 + https://github.com/luarocks/luarocks/archive/refs/tags/v3.11.1.tar.gz + CONFIGURE_COMMAND ${CFG_CMD} + BUILD_COMMAND ${BUILD_CMD} + INSTALL_COMMAND ${INSTALL_CMD} +) diff --git a/thirdparty/spec/busted/CMakeLists.txt b/thirdparty/spec/busted/CMakeLists.txt new file mode 100644 index 000000000..7551ebaed --- /dev/null +++ b/thirdparty/spec/busted/CMakeLists.txt @@ -0,0 +1,4 @@ +spec_rock( + https://luarocks.org/manifests/lunarmodules/busted-2.2.0-1.src.rock + 85aa90d2d9d0213fcd8528bc489a3519 +) diff --git a/thirdparty/spec/dkjson/CMakeLists.txt b/thirdparty/spec/dkjson/CMakeLists.txt new file mode 100644 index 000000000..976f0e640 --- /dev/null +++ b/thirdparty/spec/dkjson/CMakeLists.txt @@ -0,0 +1,4 @@ +spec_rock( + https://luarocks.org/manifests/dhkolf/dkjson-2.8-1.src.rock + 4d002b7591658983248f8214e9459e1d +) diff --git a/thirdparty/spec/lua-term/CMakeLists.txt b/thirdparty/spec/lua-term/CMakeLists.txt new file mode 100644 index 000000000..d9e2ed7c4 --- /dev/null +++ b/thirdparty/spec/lua-term/CMakeLists.txt @@ -0,0 +1,5 @@ +spec_rock( + https://github.com/hoelzro/lua-term/archive/0.08.tar.gz + 672b60c1e856129891fe29e23632c032 + ROCKSPEC lua-term-0.8-1.rockspec +) diff --git a/thirdparty/spec/lua_cliargs/CMakeLists.txt b/thirdparty/spec/lua_cliargs/CMakeLists.txt new file mode 100644 index 000000000..5381993d5 --- /dev/null +++ b/thirdparty/spec/lua_cliargs/CMakeLists.txt @@ -0,0 +1,4 @@ +spec_rock( + https://luarocks.org/manifests/lunarmodules/lua_cliargs-3.0-2.src.rock + cca85e869fac1b42252692693aed0333 +) diff --git a/thirdparty/spec/luafilesystem/CMakeLists.txt b/thirdparty/spec/luafilesystem/CMakeLists.txt new file mode 100644 index 000000000..204cc6344 --- /dev/null +++ b/thirdparty/spec/luafilesystem/CMakeLists.txt @@ -0,0 +1,4 @@ +spec_rock( + https://luarocks.org/manifests/hisham/luafilesystem-1.8.0-1.src.rock + 93bd2cbd66d6fc25ff89920ef9293c6e +) diff --git a/thirdparty/spec/luassert/CMakeLists.txt b/thirdparty/spec/luassert/CMakeLists.txt new file mode 100644 index 000000000..63e9c25e5 --- /dev/null +++ b/thirdparty/spec/luassert/CMakeLists.txt @@ -0,0 +1,4 @@ +spec_rock( + https://luarocks.org/manifests/lunarmodules/luassert-1.9.0-1.src.rock + 0df52010a5a5f728da0b9b7615a82da6 +) diff --git a/thirdparty/spec/luasystem/CMakeLists.txt b/thirdparty/spec/luasystem/CMakeLists.txt new file mode 100644 index 000000000..4f42b16a2 --- /dev/null +++ b/thirdparty/spec/luasystem/CMakeLists.txt @@ -0,0 +1,4 @@ +spec_rock( + https://luarocks.org/manifests/lunarmodules/luasystem-0.4.4-1.src.rock + 608a105f844a052e0055800d80e925f8 +) diff --git a/thirdparty/spec/mediator_lua/CMakeLists.txt b/thirdparty/spec/mediator_lua/CMakeLists.txt new file mode 100644 index 000000000..2b70f0a44 --- /dev/null +++ b/thirdparty/spec/mediator_lua/CMakeLists.txt @@ -0,0 +1,5 @@ +spec_rock( + https://github.com/Olivine-Labs/mediator_lua/archive/v1.1.2-0.tar.gz + 3ef01fc6ced99f6e4c2a229e91c459bf + ROCKSPEC mediator_lua-1.1.2-0.rockspec +) diff --git a/thirdparty/spec/penlight/CMakeLists.txt b/thirdparty/spec/penlight/CMakeLists.txt new file mode 100644 index 000000000..5d156a063 --- /dev/null +++ b/thirdparty/spec/penlight/CMakeLists.txt @@ -0,0 +1,4 @@ +spec_rock( + https://luarocks.org/manifests/tieske/penlight-1.14.0-2.src.rock + ab64b4b635e2514db64b4eabfd9d2220 +) diff --git a/thirdparty/spec/say/CMakeLists.txt b/thirdparty/spec/say/CMakeLists.txt new file mode 100644 index 000000000..aa9d2611b --- /dev/null +++ b/thirdparty/spec/say/CMakeLists.txt @@ -0,0 +1,4 @@ +spec_rock( + https://luarocks.org/manifests/lunarmodules/say-1.4.1-3.src.rock + 3b776612edf1e659b2a1e95698597e44 +)