diff --git a/.github/workflows/commit-ci.yml b/.github/workflows/commit-ci.yml index 25eb476301..ad6a49a206 100644 --- a/.github/workflows/commit-ci.yml +++ b/.github/workflows/commit-ci.yml @@ -98,3 +98,7 @@ jobs: path: app/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/* # keep 90 days retention-days: 90 + + - name: Stop Gradle daemon + if: always() + run: ./gradlew --stop diff --git a/.github/workflows/pull-request-ci.yml b/.github/workflows/pull-request-ci.yml index 021d3ae01c..341448fbfb 100644 --- a/.github/workflows/pull-request-ci.yml +++ b/.github/workflows/pull-request-ci.yml @@ -86,3 +86,7 @@ jobs: path: app/build/outputs/apk/debug/ # keep 30 days retention-days: 30 + + - name: Stop Gradle daemon + if: always() + run: ./gradlew --stop diff --git a/app/src/main/jni/CMakeLists.txt b/app/src/main/jni/CMakeLists.txt index 6cfe14bbbb..f62895af96 100644 --- a/app/src/main/jni/CMakeLists.txt +++ b/app/src/main/jni/CMakeLists.txt @@ -2,58 +2,64 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -cmake_minimum_required(VERSION 3.18.0) +cmake_minimum_required(VERSION 4.1) project(trime VERSION 3.0.0) -# for reproducible build; GNU hash is enough above API 22 -add_link_options("LINKER:--build-id=none") +list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) +# strip absolute source paths from debug info for reproducible builds +add_library(trime-reproducible-build INTERFACE IMPORTED) +set_target_properties( + trime-reproducible-build + PROPERTIES INTERFACE_COMPILE_OPTIONS + "-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.") # general options -option(BUILD_SHARED_LIBS "" OFF) -option(BUILD_TESTING "" OFF) +option(BUILD_SHARED_LIBS "Build shared libraries" OFF) +option(BUILD_TESTING "Build tests" OFF) option(ENABLE_LOGGING "Enable logging with spdlog library" ON) include(Boost) # spdlog is owned by librime and is linked statically into rime-static. if(ENABLE_LOGGING) - set(SPDLOG_BUILD_SHARED OFF CACHE BOOL "" FORCE) - set(SPDLOG_BUILD_PIC ON CACHE BOOL "" FORCE) - set(SPDLOG_BUILD_EXAMPLE OFF CACHE BOOL "" FORCE) - set(SPDLOG_BUILD_TESTS OFF CACHE BOOL "" FORCE) - set(SPDLOG_INSTALL OFF CACHE BOOL "" FORCE) - set(SPDLOG_FMT_EXTERNAL OFF CACHE BOOL "" FORCE) + set(SPDLOG_BUILD_SHARED OFF) + set(SPDLOG_BUILD_PIC ON) + set(SPDLOG_BUILD_EXAMPLE OFF) + set(SPDLOG_BUILD_TESTS OFF) + set(SPDLOG_INSTALL OFF) + set(SPDLOG_FMT_EXTERNAL OFF) add_subdirectory(librime/deps/spdlog EXCLUDE_FROM_ALL) - target_compile_options( - spdlog PRIVATE "-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.") + target_link_libraries(spdlog PRIVATE trime-reproducible-build) endif() -option(YAML_CPP_BUILD_TOOLS "" OFF) -option(YAML_CPP_BUILD_TESTS "" OFF) -option(YAML_CPP_INSTALL "" OFF) +# yaml-cpp +option(YAML_CPP_BUILD_TOOLS "Build yaml-cpp tools" OFF) +option(YAML_CPP_BUILD_TESTS "Build yaml-cpp tests" OFF) +option(YAML_CPP_INSTALL "Install yaml-cpp" OFF) add_subdirectory(librime/deps/yaml-cpp) -# enable compress for leveldb -option(SNAPPY_BUILD_TESTS "" OFF) -option(SNAPPY_BUILD_BENCHMARKS "" OFF) -option(SNAPPY_INSTALL "" OFF) +# snappy: compression for leveldb +option(SNAPPY_BUILD_TESTS "Build snappy tests" OFF) +option(SNAPPY_BUILD_BENCHMARKS "Build snappy benchmarks" OFF) +option(SNAPPY_INSTALL "Install snappy" OFF) add_subdirectory(snappy) +# leveldb set(HAVE_SNAPPY TRUE) -option(LEVELDB_BUILD_TESTS "" OFF) -option(LEVELDB_BUILD_BENCHMARKS "" OFF) -option(LEVELDB_INSTALL "" OFF) +option(LEVELDB_BUILD_TESTS "Build leveldb tests" OFF) +option(LEVELDB_BUILD_BENCHMARKS "Build leveldb benchmarks" OFF) +option(LEVELDB_INSTALL "Install leveldb" OFF) add_subdirectory(librime/deps/leveldb) +# marisa add_subdirectory(librime/deps/marisa-trie) -target_compile_options( - marisa PRIVATE "-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.") - set(LIBMARISA marisa) -option(USE_SYSTEM_MARISA "" ON) +option(USE_SYSTEM_MARISA "Use the system marisa library" ON) +target_link_libraries(marisa PRIVATE trime-reproducible-build) + +# opencc add_subdirectory(librime/deps/opencc) # OpenCC's data/ builds its dictionaries by running the freshly built # opencc_dict, which is an Android executable and cannot run on the build @@ -64,8 +70,8 @@ set_property( PROPERTY EXCLUDE_FROM_ALL TRUE) include(OpenccWorkarounds) +# keysym.h is shipped in librime/include for cross-compilation. set(X11Keysym "${CMAKE_SOURCE_DIR}/librime/include") -include_directories("${X11Keysym}") include(Rime) diff --git a/app/src/main/jni/cmake/FindBoost.cmake b/app/src/main/jni/cmake/FindBoost.cmake index 61cae8ca9b..65853d58a4 100644 --- a/app/src/main/jni/cmake/FindBoost.cmake +++ b/app/src/main/jni/cmake/FindBoost.cmake @@ -2,18 +2,21 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +# Boost is provided by the downloaded CMake distribution in the build tree. set(Boost_FOUND TRUE) +set(Boost_VERSION ${BOOST_VERSION}) +# Export the Boost components as the namespaced targets librime expects. list(TRANSFORM BOOST_INCLUDE_LIBRARIES PREPEND Boost:: OUTPUT_VARIABLE Boost_LIBRARIES) +# include directories file( GLOB __boost_installed_libs LIST_DIRECTORIES true RELATIVE "${CMAKE_BINARY_DIR}" "${CMAKE_BINARY_DIR}/boost/libs/*") -foreach(__lib ${__boost_installed_libs}) - set(__full_dir "${CMAKE_SOURCE_DIR}/${__lib}/include") - list(APPEND Boost_INCLUDE_DIRS "${__full_dir}") +foreach(__lib IN LISTS __boost_installed_libs) + list(APPEND Boost_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/${__lib}/include") endforeach() diff --git a/app/src/main/jni/cmake/FindLevelDb.cmake b/app/src/main/jni/cmake/FindLevelDb.cmake index e3b12420ad..ca1d7e166e 100644 --- a/app/src/main/jni/cmake/FindLevelDb.cmake +++ b/app/src/main/jni/cmake/FindLevelDb.cmake @@ -2,5 +2,7 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -set(LevelDb_FOUNT TRUE) +# leveldb is added as a subdirectory of the top-level build. +set(LevelDb_FOUND TRUE) set(LevelDb_LIBRARY leveldb) +set(LevelDb_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/librime/deps/leveldb/include") diff --git a/app/src/main/jni/cmake/OpenccWorkarounds.cmake b/app/src/main/jni/cmake/OpenccWorkarounds.cmake index a8610b61f2..13ca218383 100644 --- a/app/src/main/jni/cmake/OpenccWorkarounds.cmake +++ b/app/src/main/jni/cmake/OpenccWorkarounds.cmake @@ -2,7 +2,8 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -# Since OpenCC doesn't include its headers in the binary dir, we need to install -# them manually. -file(GLOB LIBOPENCC_HEADERS librime/deps/opencc/src/*.hpp) +# OpenCC doesn't put its headers in the binary dir, so copy them manually. +file( + GLOB LIBOPENCC_HEADERS CONFIGURE_DEPENDS + "${CMAKE_SOURCE_DIR}/librime/deps/opencc/src/*.hpp") file(COPY ${LIBOPENCC_HEADERS} DESTINATION "${CMAKE_BINARY_DIR}/include/opencc") diff --git a/app/src/main/jni/cmake/Rime.cmake b/app/src/main/jni/cmake/Rime.cmake index 841fc0b63c..ee572c7887 100644 --- a/app/src/main/jni/cmake/Rime.cmake +++ b/app/src/main/jni/cmake/Rime.cmake @@ -13,21 +13,19 @@ foreach(plugin ${RIME_PLUGINS}) endif() endforeach() -# librime-lua +# librime-lua depends on the thirdparty sources in a separate submodule. if(NOT EXISTS "${CMAKE_SOURCE_DIR}/librime/plugins/librime-lua/thirdparty") file(CREATE_LINK "${CMAKE_SOURCE_DIR}/librime-lua-deps" "${CMAKE_SOURCE_DIR}/librime/plugins/librime-lua/thirdparty" COPY_ON_ERROR SYMBOLIC) endif() -option(BUILD_TEST "" OFF) -option(BUILD_STATIC "" ON) +# librime +option(BUILD_TEST "Build librime tests" OFF) +option(BUILD_STATIC "Build librime statically" ON) add_subdirectory(librime) target_compile_options( - rime-static PRIVATE "-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=." "-Wno-error=deprecated-declarations") - -target_compile_options( - rime-lua-objs PRIVATE "-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.") - -target_compile_options( - rime-octagram-objs PRIVATE "-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=.") + rime-static PRIVATE "-Wno-error=deprecated-declarations") +target_link_libraries(rime-static PRIVATE trime-reproducible-build) +target_link_libraries(rime-lua-objs PRIVATE trime-reproducible-build) +target_link_libraries(rime-octagram-objs PRIVATE trime-reproducible-build) diff --git a/app/src/main/jni/librime b/app/src/main/jni/librime index bb56876890..1c0a468e7f 160000 --- a/app/src/main/jni/librime +++ b/app/src/main/jni/librime @@ -1 +1 @@ -Subproject commit bb56876890ba60f446fa2640c244b1794b965eda +Subproject commit 1c0a468e7fff2b2763400abe1e892ed66d08b00e diff --git a/app/src/main/jni/librime_jni/CMakeLists.txt b/app/src/main/jni/librime_jni/CMakeLists.txt index f6c2808c0a..05445ad9c8 100644 --- a/app/src/main/jni/librime_jni/CMakeLists.txt +++ b/app/src/main/jni/librime_jni/CMakeLists.txt @@ -4,11 +4,16 @@ find_package(Opencc REQUIRED) -aux_source_directory(. RIME_JNI_SOURCES) +file(GLOB RIME_JNI_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cc") add_library(rime_jni SHARED ${RIME_JNI_SOURCES}) -target_link_libraries(rime_jni rime-static ${Opencc_LIBRARY}) + +# for reproducible build; GNU hash is enough above API 22 +target_link_libraries(rime_jni PRIVATE rime-static ${Opencc_LIBRARY}) +target_link_options(rime_jni PRIVATE "LINKER:--build-id=none") + target_include_directories(rime_jni PRIVATE "${CMAKE_BINARY_DIR}/librime/src" "${CMAKE_SOURCE_DIR}/librime/src" + "${X11Keysym}" "${Opencc_INCLUDE_PATH}" ) diff --git a/build-logic/convention/src/main/kotlin/OpenCCDataPlugin.kt b/build-logic/convention/src/main/kotlin/OpenCCDataPlugin.kt index 34497a8517..7af92e11b8 100644 --- a/build-logic/convention/src/main/kotlin/OpenCCDataPlugin.kt +++ b/build-logic/convention/src/main/kotlin/OpenCCDataPlugin.kt @@ -25,6 +25,7 @@ import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.register import org.gradle.process.ExecOperations +import java.io.ByteArrayOutputStream import java.io.File import javax.inject.Inject @@ -382,10 +383,20 @@ class OpenCCDataPlugin : Plugin { cmake: String, args: List, ) { - execOperations - .exec { + val output = ByteArrayOutputStream() + val exitValue = + execOperations.exec { commandLine = listOf(cmake) + args - }.assertNormalExitValue() + standardOutput = output + errorOutput = output + isIgnoreExitValue = true + }.exitValue + if (exitValue != 0) { + throw GradleException( + "OpenCC host build failed with exit code $exitValue:\n" + + output.toString(Charsets.UTF_8), + ) + } } } }