Skip to content

Commit c1046cb

Browse files
authored
GDV-71:[C++]Made Gandiva JNI a packagable library. (apache#42)
Modified the build to package the gandiva jni as a stand alone library that can be packaged in the Gandiva JAR. Also producing two versions of gandiva core - a static and a shared one. Fixed LLVM dependencies to be target based.
1 parent 41e4da8 commit c1046cb

6 files changed

Lines changed: 103 additions & 66 deletions

File tree

cmake/BuildUtils.cmake

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,60 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# Build the gandiva library
16+
function(build_gandiva_lib TYPE)
17+
string(TOUPPER ${TYPE} TYPE_UPPER_CASE)
18+
add_library(gandiva_${TYPE} ${TYPE_UPPER_CASE} $<TARGET_OBJECTS:gandiva_obj_lib>)
19+
20+
target_include_directories(gandiva_${TYPE}
21+
PUBLIC
22+
$<INSTALL_INTERFACE:include>
23+
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
24+
PRIVATE
25+
${CMAKE_SOURCE_DIR}/src
26+
)
27+
28+
# ARROW is a public dependency i.e users of gandiva also will have a dependency on arrow.
29+
target_link_libraries(gandiva_${TYPE}
30+
PUBLIC
31+
ARROW::ARROW_${TYPE_UPPER_CASE}
32+
PRIVATE
33+
Boost::boost
34+
Boost::regex
35+
Boost::system
36+
Boost::filesystem
37+
LLVM::LLVM_INTERFACE)
38+
39+
# Set version for the library.
40+
set(GANDIVA_VERSION_MAJOR 0)
41+
set(GANDIVA_VERSION_MINOR 1)
42+
set(GANDIVA_VERSION_PATCH 0)
43+
set(GANDIVA_VERSION ${GANDIVA_VERSION_MAJOR}.${GANDIVA_VERSION_MINOR}.${GANDIVA_VERSION_PATCH})
44+
45+
set_target_properties(gandiva_${TYPE} PROPERTIES
46+
VERSION ${GANDIVA_VERSION}
47+
SOVERSION ${GANDIVA_VERSION_MAJOR}
48+
OUTPUT_NAME gandiva
49+
)
50+
endfunction(build_gandiva_lib TYPE)
51+
1552
# Add a unittest executable, with its dependencies.
1653
function(add_gandiva_unit_test REL_TEST_NAME)
1754
get_filename_component(TEST_NAME ${REL_TEST_NAME} NAME_WE)
1855

1956
add_executable(${TEST_NAME} ${REL_TEST_NAME} ${ARGN})
2057
if(${REL_TEST_NAME} MATCHES "llvm")
2158
# If the unit test has llvm in its name, include llvm.
22-
target_link_llvm(${TEST_NAME} PRIVATE)
59+
add_dependencies(${TEST_NAME} LLVM::LLVM_INTERFACE)
60+
target_link_libraries(${TEST_NAME} PRIVATE LLVM::LLVM_INTERFACE)
2361
endif()
2462

2563
target_include_directories(${TEST_NAME} PRIVATE
2664
${CMAKE_SOURCE_DIR}/include
2765
${CMAKE_SOURCE_DIR}/src
2866
)
2967
target_link_libraries(${TEST_NAME}
30-
PRIVATE ${ARROW_LIB} gtest_main Boost::boost
68+
PRIVATE ${ARROW_LIB_SHARED} gtest_main Boost::boost
3169
)
3270
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
3371
set_property(TEST ${TEST_NAME} PROPERTY LABELS unittest ${TEST_NAME})
@@ -46,15 +84,15 @@ function(add_precompiled_unit_test REL_TEST_NAME)
4684
endfunction(add_precompiled_unit_test REL_TEST_NAME)
4785

4886
# Add an integ executable, with its dependencies.
49-
function(add_gandiva_integ_test REL_TEST_NAME)
87+
function(add_gandiva_integ_test REL_TEST_NAME GANDIVA_LIB)
5088
get_filename_component(TEST_NAME ${REL_TEST_NAME} NAME_WE)
5189

52-
add_executable(${TEST_NAME} ${REL_TEST_NAME} ${ARGN})
53-
target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_SOURCE_DIR})
54-
target_link_libraries(${TEST_NAME} PRIVATE gandiva gtest_main)
90+
add_executable(${TEST_NAME}_${GANDIVA_LIB} ${REL_TEST_NAME} ${ARGN})
91+
target_include_directories(${TEST_NAME}_${GANDIVA_LIB} PRIVATE ${CMAKE_SOURCE_DIR})
92+
target_link_libraries(${TEST_NAME}_${GANDIVA_LIB} PRIVATE ${GANDIVA_LIB} gtest_main)
5593

56-
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
57-
set_property(TEST ${TEST_NAME} PROPERTY LABELS integ ${TEST_NAME})
94+
add_test(NAME ${TEST_NAME}_${GANDIVA_LIB} COMMAND ${TEST_NAME}_${GANDIVA_LIB})
95+
set_property(TEST ${TEST_NAME}_${GANDIVA_LIB} PROPERTY LABELS integ ${TEST_NAME}_${GANDIVA_LIB})
5896
endfunction(add_gandiva_integ_test REL_TEST_NAME)
5997

6098
# Download and build external project.

cmake/FindARROW.cmake

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,23 @@
1414

1515
# Find Arrow library and includes.
1616

17-
find_library(ARROW_LIB arrow REQUIRED)
18-
message(STATUS "Found arrow library at ${ARROW_LIB}")
17+
find_library(ARROW_LIB_STATIC libarrow.a REQUIRED)
18+
find_library(ARROW_LIB_SHARED arrow REQUIRED)
19+
message(STATUS "Found arrow static library at ${ARROW_LIB_STATIC}")
20+
message(STATUS "Found arrow shared library at ${ARROW_LIB_SHARED}")
1921

2022
find_path(ARROW_INCLUDE_DIR arrow/type.h)
2123
message(STATUS "found arrow includes at ${ARROW_INCLUDE_DIR}")
2224

2325
# add an imported target ARROW::ARROW so that gandiva can take a dependency.
24-
add_library(ARROW::ARROW INTERFACE IMPORTED)
25-
set_target_properties(ARROW::ARROW PROPERTIES
26+
add_library(ARROW::ARROW_STATIC STATIC IMPORTED)
27+
add_library(ARROW::ARROW_SHARED INTERFACE IMPORTED)
28+
29+
set_target_properties(ARROW::ARROW_STATIC PROPERTIES
30+
INTERFACE_INCLUDE_DIRECTORIES "${ARROW_INCLUDE_DIR}"
31+
IMPORTED_LOCATION "${ARROW_LIB_STATIC}"
32+
)
33+
set_target_properties(ARROW::ARROW_SHARED PROPERTIES
2634
INTERFACE_INCLUDE_DIRECTORIES "${ARROW_INCLUDE_DIR}"
27-
INTERFACE_LINK_LIBRARIES "${ARROW_LIB}"
35+
INTERFACE_LINK_LIBRARIES "${ARROW_LIB_SHARED}"
2836
)

cmake/FindLLVM.cmake

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
2727
# Find the libraries that correspond to the LLVM components
2828
llvm_map_components_to_libnames(LLVM_LIBS core mcjit native ipo bitreader target linker analysis debuginfodwarf)
2929

30-
# Convenience function for targets to link llvm.
31-
function(target_link_llvm TARGET TYPE)
32-
target_include_directories(${TARGET} ${TYPE} ${LLVM_INCLUDE_DIRS})
33-
target_compile_definitions(${TARGET} ${TYPE} ${LLVM_DEFINITIONS})
34-
target_link_libraries(${TARGET} ${TYPE} ${LLVM_LIBS})
35-
endfunction()
30+
add_library(LLVM::LLVM_INTERFACE INTERFACE IMPORTED)
31+
32+
set_target_properties(LLVM::LLVM_INTERFACE PROPERTIES
33+
INTERFACE_INCLUDE_DIRECTORIES "${LLVM_INCLUDE_DIRS}"
34+
INTERFACE_COMPILE_FLAGS "${LLVM_DEFINITIONS}"
35+
INTERFACE_LINK_LIBRARIES "${LLVM_LIBS}"
36+
)
37+

integ/CMakeLists.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
project(gandiva)
1616

17-
add_gandiva_integ_test(projector_test.cc)
18-
add_gandiva_integ_test(if_expr_test.cc)
19-
add_gandiva_integ_test(boolean_expr_test.cc)
20-
add_gandiva_integ_test(literal_test.cc)
21-
add_gandiva_integ_test(date_time_test.cc)
22-
add_gandiva_integ_test(projector_build_validation_test.cc)
23-
add_gandiva_integ_test(utf8_test.cc)
24-
add_gandiva_integ_test(binary_test.cc)
17+
foreach(lib_type "shared" "static")
18+
add_gandiva_integ_test(projector_test.cc gandiva_${lib_type})
19+
add_gandiva_integ_test(if_expr_test.cc gandiva_${lib_type})
20+
add_gandiva_integ_test(literal_test.cc gandiva_${lib_type})
21+
add_gandiva_integ_test(projector_build_validation_test.cc gandiva_${lib_type})
22+
add_gandiva_integ_test(boolean_expr_test.cc gandiva_${lib_type})
23+
add_gandiva_integ_test(utf8_test.cc gandiva_${lib_type})
24+
add_gandiva_integ_test(binary_test.cc gandiva_${lib_type})
25+
endforeach(lib_type)

src/codegen/CMakeLists.txt

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,67 +17,55 @@ project(gandiva)
1717
# Find arrow
1818
find_package(ARROW)
1919

20-
find_package(Boost REQUIRED)
20+
find_package(Boost COMPONENTS system regex filesystem REQUIRED)
2121

2222
set(BC_FILE_PATH_CC "${CMAKE_CURRENT_BINARY_DIR}/bc_file_path.cc")
2323
configure_file(bc_file_path.cc.in ${BC_FILE_PATH_CC})
2424

25-
add_library(gandiva SHARED
26-
annotator.cc
27-
bitmap_accumulator.cc
28-
configuration.cc
29-
engine.cc
30-
expr_decomposer.cc
31-
expr_validator.cc
32-
function_registry.cc
33-
llvm_generator.cc
34-
llvm_types.cc
35-
projector.cc
36-
status.cc
37-
tree_expr_builder.cc
38-
${BC_FILE_PATH_CC})
25+
set(SRC_FILES annotator.cc
26+
engine.cc
27+
bitmap_accumulator.cc
28+
configuration.cc
29+
expr_decomposer.cc
30+
expr_validator.cc
31+
function_registry.cc
32+
llvm_generator.cc
33+
llvm_types.cc
34+
projector.cc
35+
status.cc
36+
tree_expr_builder.cc
37+
${BC_FILE_PATH_CC})
38+
39+
add_library(gandiva_obj_lib OBJECT ${SRC_FILES})
40+
41+
# set PIC so that object library can be included in shared libs.
42+
set_target_properties(gandiva_obj_lib PROPERTIES POSITION_INDEPENDENT_CODE 1)
3943

4044
# For users of gandiva library (including integ tests), include-dir is :
4145
# /usr/**/include dir after install,
4246
# cpp/include during build
4347
# For building gandiva library itself, include-dir (in addition to above) is :
4448
# cpp/src
45-
target_include_directories(gandiva
49+
target_include_directories(gandiva_obj_lib
4650
PUBLIC
4751
$<INSTALL_INTERFACE:include>
4852
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
4953
PRIVATE
5054
${CMAKE_SOURCE_DIR}/src
55+
$<TARGET_PROPERTY:LLVM::LLVM_INTERFACE,INTERFACE_INCLUDE_DIRECTORIES>
56+
$<TARGET_PROPERTY:ARROW::ARROW_SHARED,INTERFACE_INCLUDE_DIRECTORIES>
5157
)
5258

53-
# ARROW is a public dependency i.e users of gandiva also will have a dependency on arrow.
54-
target_link_libraries(gandiva
55-
PUBLIC
56-
ARROW::ARROW
57-
PRIVATE
58-
Boost::boost)
59+
build_gandiva_lib("shared")
5960

60-
# LLVM is a private dependency i.e users of gandiva will not need to include llvm headers
61-
# or link with llvm libraries.
62-
target_link_llvm(gandiva PRIVATE)
63-
64-
# Set version for the library.
65-
set(GANDIVA_VERSION_MAJOR 0)
66-
set(GANDIVA_VERSION_MINOR 1)
67-
set(GANDIVA_VERSION_PATCH 0)
68-
set(GANDIVA_VERSION ${GANDIVA_VERSION_MAJOR}.${GANDIVA_VERSION_MINOR}.${GANDIVA_VERSION_PATCH})
69-
70-
set_target_properties(gandiva PROPERTIES
71-
VERSION ${GANDIVA_VERSION}
72-
SOVERSION ${GANDIVA_VERSION_MAJOR}
73-
)
61+
build_gandiva_lib("static")
7462

7563
# install for gandiva
7664
include(GNUInstallDirs)
7765

7866
# install libgandiva
7967
install(
80-
TARGETS gandiva
68+
TARGETS gandiva_shared gandiva_static
8169
DESTINATION ${CMAKE_INSTALL_LIBDIR}
8270
)
8371

src/jni/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ target_include_directories(gandiva_jni
5252
${CMAKE_SOURCE_DIR}/src
5353
)
5454

55-
# PROTOBUF is a public dependency i.e users of gandiva also will have a dependency on arrow.
55+
# PROTOBUF is a private dependency i.e users of gandiva also will not have a dependency on protobuf.
5656
target_link_libraries(gandiva_jni
5757
PRIVATE
5858
protobuf::libprotobuf
59-
gandiva
59+
gandiva_static
6060
)

0 commit comments

Comments
 (0)