Skip to content

Commit

Permalink
apacheGH-37410: [C++][Gandiva] Add support for using LLVM shared libr…
Browse files Browse the repository at this point in the history
…ary (apache#37412)

### Rationale for this change

Gandiva always links LLVM statically. But we can use LLVM shared library instead to reduce `libgandiva.so` size.

### What changes are included in this PR?

Add `ARROW_LLVM_USE_SHARED` like other dependencies.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

Yes.

This has a backward incompatible change. LLVM shared library not static libraries is used by default. If you want to use LLVM static libraries, you need to specify `-DARROW_LLVM_USE_SHARED=OFF` or `-DARROW_DEPENDENCY_USE_SHARED=OFF` explicitly.
* Closes: apache#37410

Lead-authored-by: Sutou Kouhei <kou@clear-code.com>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
  • Loading branch information
2 people authored and loicalleyne committed Nov 13, 2023
1 parent 26430f4 commit 8052abb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
9 changes: 9 additions & 0 deletions cpp/cmake_modules/DefineOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@ takes precedence over ccache if a storage backend is configured" ON)
"Rely on jemalloc shared libraries where relevant"
${ARROW_DEPENDENCY_USE_SHARED})

if(MSVC)
# LLVM doesn't support shared library with MSVC.
set(ARROW_LLVM_USE_SHARED_DEFAULT OFF)
else()
set(ARROW_LLVM_USE_SHARED_DEFAULT ${ARROW_DEPENDENCY_USE_SHARED})
endif()
define_option(ARROW_LLVM_USE_SHARED "Rely on LLVM shared libraries where relevant"
${ARROW_LLVM_USE_SHARED_DEFAULT})

define_option(ARROW_LZ4_USE_SHARED "Rely on lz4 shared libraries where relevant"
${ARROW_DEPENDENCY_USE_SHARED})

Expand Down
55 changes: 29 additions & 26 deletions cpp/cmake_modules/FindLLVMAlt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ if(NOT LLVM_FOUND)
endif()

if(LLVM_FOUND)
# Find the libraries that correspond to the LLVM components
llvm_map_components_to_libnames(LLVM_LIBS
core
mcjit
native
ipo
bitreader
target
linker
analysis
debuginfodwarf)

find_program(LLVM_LINK_EXECUTABLE llvm-link HINTS ${LLVM_TOOLS_BINARY_DIR})

find_program(CLANG_EXECUTABLE
Expand All @@ -94,22 +82,37 @@ if(LLVM_FOUND)
INTERFACE_COMPILE_FLAGS "${LLVM_DEFINITIONS}")

add_library(LLVM::LLVM_LIBS INTERFACE IMPORTED)
set_target_properties(LLVM::LLVM_LIBS PROPERTIES INTERFACE_LINK_LIBRARIES
"${LLVM_LIBS}")
if(ARROW_LLVM_USE_SHARED)
target_link_libraries(LLVM::LLVM_LIBS INTERFACE LLVM)
else()
# Find the libraries that correspond to the LLVM components
llvm_map_components_to_libnames(LLVM_LIBS
core
mcjit
native
ipo
bitreader
target
linker
analysis
debuginfodwarf)
target_link_libraries(LLVM::LLVM_LIBS INTERFACE ${LLVM_LIBS})

if(TARGET LLVMSupport AND NOT ARROW_ZSTD_USE_SHARED)
get_target_property(LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES LLVMSupport
INTERFACE_LINK_LIBRARIES)
list(FIND LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES zstd::libzstd_shared
LLVM_SUPPORT_LIBZSTD_INDEX)
if(NOT LLVM_SUPPORT_LIBZSTD_INDEX EQUAL -1)
list(REMOVE_AT LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES ${LLVM_SUPPORT_LIBZSTD_INDEX})
list(INSERT LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES ${LLVM_SUPPORT_LIBZSTD_INDEX}
zstd::libzstd_static)
if(TARGET LLVMSupport AND NOT ARROW_ZSTD_USE_SHARED)
get_target_property(LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES LLVMSupport
INTERFACE_LINK_LIBRARIES)
list(FIND LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES zstd::libzstd_shared
LLVM_SUPPORT_LIBZSTD_INDEX)
if(NOT LLVM_SUPPORT_LIBZSTD_INDEX EQUAL -1)
list(REMOVE_AT LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES
${LLVM_SUPPORT_LIBZSTD_INDEX})
list(INSERT LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES ${LLVM_SUPPORT_LIBZSTD_INDEX}
zstd::libzstd_static)
endif()
set_target_properties(LLVMSupport
PROPERTIES INTERFACE_LINK_LIBRARIES
"${LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES}")
endif()
set_target_properties(LLVMSupport
PROPERTIES INTERFACE_LINK_LIBRARIES
"${LLVM_SUPPORT_INTERFACE_LINK_LIBRARIES}")
endif()
endif()

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/gandiva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ add_dependencies(gandiva ${GANDIVA_LIBRARIES})
arrow_install_all_headers("gandiva")

set(GANDIVA_STATIC_TEST_LINK_LIBS gandiva_static ${ARROW_TEST_LINK_LIBS})
set(GANDIVA_SHARED_TEST_LINK_LIBS gandiva_shared ${ARROW_TEST_LINK_LIBS})
set(GANDIVA_SHARED_TEST_LINK_LIBS gandiva_shared ${ARROW_TEST_LINK_LIBS} LLVM::LLVM_LIBS)
if(ARROW_WITH_UTF8PROC)
list(APPEND GANDIVA_SHARED_TEST_LINK_LIBS utf8proc::utf8proc)
list(APPEND GANDIVA_STATIC_TEST_LINK_LIBS utf8proc::utf8proc)
endif()
if(WIN32)
list(APPEND GANDIVA_STATIC_TEST_LINK_LIBS ${GANDIVA_OPENSSL_TARGETS})
list(APPEND GANDIVA_SHARED_TEST_LINK_LIBS LLVM::LLVM_LIBS ${GANDIVA_OPENSSL_TARGETS})
list(APPEND GANDIVA_SHARED_TEST_LINK_LIBS ${GANDIVA_OPENSSL_TARGETS})
endif()

function(ADD_GANDIVA_TEST REL_TEST_NAME)
Expand Down

0 comments on commit 8052abb

Please sign in to comment.