From b2ff2f55218707f01cdb014c03ed5079806f8537 Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Thu, 29 Aug 2024 08:56:29 +0800 Subject: [PATCH] [GLUTEN-7049][VL] Install lib stemmer through vcpkg (#7050) --- cpp/velox/CMakeLists.txt | 19 ++++++++++++++---- dev/vcpkg/ports/libstemmer/CMakeLists.txt | 22 +++++++++++++++++++++ dev/vcpkg/ports/libstemmer/portfile.cmake | 24 +++++++++++++++++++++++ dev/vcpkg/ports/libstemmer/vcpkg.json | 12 ++++++++++++ dev/vcpkg/vcpkg.json | 3 ++- 5 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 dev/vcpkg/ports/libstemmer/CMakeLists.txt create mode 100644 dev/vcpkg/ports/libstemmer/portfile.cmake create mode 100644 dev/vcpkg/ports/libstemmer/vcpkg.json diff --git a/cpp/velox/CMakeLists.txt b/cpp/velox/CMakeLists.txt index 202863b2a2e9..1d7e8548aa04 100644 --- a/cpp/velox/CMakeLists.txt +++ b/cpp/velox/CMakeLists.txt @@ -299,12 +299,22 @@ target_link_libraries(velox PUBLIC Folly::folly) find_re2() target_link_libraries(velox PUBLIC ${RE2_LIBRARY}) -import_library(external::stemmer - ${VELOX_BUILD_PATH}/_deps/libstemmer/src/libstemmer/libstemmer.a) -target_link_libraries(velox PUBLIC external::stemmer) - set(CMAKE_FIND_LIBRARY_SUFFIXES_BCK ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + +find_library(STEMMER_LIB NAMES libstemmer.a) +if(STEMMER_LIB) + message(STATUS "Found stemmer: ${STEMMER_LIB}") + add_library(external::stemmer STATIC IMPORTED) + set_target_properties(external::stemmer PROPERTIES IMPORTED_LOCATION + ${STEMMER_LIB}) +else() + import_library( + external::stemmer + ${VELOX_BUILD_PATH}/_deps/libstemmer/src/libstemmer/libstemmer.a) +endif() +target_link_libraries(velox PUBLIC external::stemmer) + find_package(simdjson CONFIG) if(simdjson_FOUND AND TARGET simdjson::simdjson) target_link_libraries(velox PUBLIC simdjson::simdjson) @@ -313,6 +323,7 @@ else() ${VELOX_BUILD_PATH}/_deps/simdjson-build/libsimdjson.a) target_link_libraries(velox PUBLIC external::simdjson) endif() + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_BCK}) if(BUILD_TESTS) diff --git a/dev/vcpkg/ports/libstemmer/CMakeLists.txt b/dev/vcpkg/ports/libstemmer/CMakeLists.txt new file mode 100644 index 000000000000..787bb26ec3f7 --- /dev/null +++ b/dev/vcpkg/ports/libstemmer/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.8.0) + +project(libstemmer) + +file(GLOB SNOWBALL_SOURCES + src_c/*.c + runtime/api.c + runtime/utilities.c + libstemmer/libstemmer.c +) + +add_library(stemmer ${SNOWBALL_SOURCES}) + +install( + TARGETS stemmer + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) +if(NOT DISABLE_INSTALL_HEADERS) + install(FILES include/libstemmer.h DESTINATION include) +endif() diff --git a/dev/vcpkg/ports/libstemmer/portfile.cmake b/dev/vcpkg/ports/libstemmer/portfile.cmake new file mode 100644 index 000000000000..253027ad72e0 --- /dev/null +++ b/dev/vcpkg/ports/libstemmer/portfile.cmake @@ -0,0 +1,24 @@ +vcpkg_check_linkage(ONLY_STATIC_LIBRARY) +string(SUBSTRING "${VERSION}" 5 -1 VERSION) + +vcpkg_download_distfile(ARCHIVE + URLS "https://snowballstem.org/dist/libstemmer_c-${VERSION}.tar.gz" + FILENAME "libstemmer_c-${VERSION}.tar.gz" + SHA512 a61a06a046a6a5e9ada12310653c71afb27b5833fa9e21992ba4bdf615255de991352186a8736d0156ed754248a0ffb7b7712e8d5ea16f75174d1c8ddd37ba4a +) + +vcpkg_extract_source_archive( + SOURCE_PATH + ARCHIVE "${ARCHIVE}" +) + +file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}") + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS_DEBUG -DDISABLE_INSTALL_HEADERS=ON +) + +vcpkg_cmake_install() + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING") diff --git a/dev/vcpkg/ports/libstemmer/vcpkg.json b/dev/vcpkg/ports/libstemmer/vcpkg.json new file mode 100644 index 000000000000..03e8275d0b25 --- /dev/null +++ b/dev/vcpkg/ports/libstemmer/vcpkg.json @@ -0,0 +1,12 @@ +{ + "name": "libstemmer", + "version": "2021.2.2.0", + "description": "Snowball is a small string processing language designed for creating stemming algorithms for use in Information Retrieval", + "homepage": "https://snowballstem.org/", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + } + ] +} diff --git a/dev/vcpkg/vcpkg.json b/dev/vcpkg/vcpkg.json index 6eec2190d043..618293ff63f2 100644 --- a/dev/vcpkg/vcpkg.json +++ b/dev/vcpkg/vcpkg.json @@ -52,7 +52,8 @@ "benchmark", "jemalloc", "icu", - "thrift" + "thrift", + "libstemmer" ] }, "velox-s3": {