Skip to content

Commit

Permalink
GDV-71:[C++]Made Gandiva JNI a packagable library. (apache#42)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
praveenbingo authored Jul 4, 2018
1 parent d2c1eb8 commit 5a39298
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 66 deletions.
54 changes: 46 additions & 8 deletions cpp/src/gandiva/cmake/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,60 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Build the gandiva library
function(build_gandiva_lib TYPE)
string(TOUPPER ${TYPE} TYPE_UPPER_CASE)
add_library(gandiva_${TYPE} ${TYPE_UPPER_CASE} $<TARGET_OBJECTS:gandiva_obj_lib>)

target_include_directories(gandiva_${TYPE}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
PRIVATE
${CMAKE_SOURCE_DIR}/src
)

# ARROW is a public dependency i.e users of gandiva also will have a dependency on arrow.
target_link_libraries(gandiva_${TYPE}
PUBLIC
ARROW::ARROW_${TYPE_UPPER_CASE}
PRIVATE
Boost::boost
Boost::regex
Boost::system
Boost::filesystem
LLVM::LLVM_INTERFACE)

# Set version for the library.
set(GANDIVA_VERSION_MAJOR 0)
set(GANDIVA_VERSION_MINOR 1)
set(GANDIVA_VERSION_PATCH 0)
set(GANDIVA_VERSION ${GANDIVA_VERSION_MAJOR}.${GANDIVA_VERSION_MINOR}.${GANDIVA_VERSION_PATCH})

set_target_properties(gandiva_${TYPE} PROPERTIES
VERSION ${GANDIVA_VERSION}
SOVERSION ${GANDIVA_VERSION_MAJOR}
OUTPUT_NAME gandiva
)
endfunction(build_gandiva_lib TYPE)

# Add a unittest executable, with its dependencies.
function(add_gandiva_unit_test REL_TEST_NAME)
get_filename_component(TEST_NAME ${REL_TEST_NAME} NAME_WE)

add_executable(${TEST_NAME} ${REL_TEST_NAME} ${ARGN})
if(${REL_TEST_NAME} MATCHES "llvm")
# If the unit test has llvm in its name, include llvm.
target_link_llvm(${TEST_NAME} PRIVATE)
add_dependencies(${TEST_NAME} LLVM::LLVM_INTERFACE)
target_link_libraries(${TEST_NAME} PRIVATE LLVM::LLVM_INTERFACE)
endif()

target_include_directories(${TEST_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/src
)
target_link_libraries(${TEST_NAME}
PRIVATE ${ARROW_LIB} gtest_main Boost::boost
PRIVATE ${ARROW_LIB_SHARED} gtest_main Boost::boost
)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
set_property(TEST ${TEST_NAME} PROPERTY LABELS unittest ${TEST_NAME})
Expand All @@ -46,15 +84,15 @@ function(add_precompiled_unit_test REL_TEST_NAME)
endfunction(add_precompiled_unit_test REL_TEST_NAME)

# Add an integ executable, with its dependencies.
function(add_gandiva_integ_test REL_TEST_NAME)
function(add_gandiva_integ_test REL_TEST_NAME GANDIVA_LIB)
get_filename_component(TEST_NAME ${REL_TEST_NAME} NAME_WE)

add_executable(${TEST_NAME} ${REL_TEST_NAME} ${ARGN})
target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(${TEST_NAME} PRIVATE gandiva gtest_main)
add_executable(${TEST_NAME}_${GANDIVA_LIB} ${REL_TEST_NAME} ${ARGN})
target_include_directories(${TEST_NAME}_${GANDIVA_LIB} PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(${TEST_NAME}_${GANDIVA_LIB} PRIVATE ${GANDIVA_LIB} gtest_main)

add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
set_property(TEST ${TEST_NAME} PROPERTY LABELS integ ${TEST_NAME})
add_test(NAME ${TEST_NAME}_${GANDIVA_LIB} COMMAND ${TEST_NAME}_${GANDIVA_LIB})
set_property(TEST ${TEST_NAME}_${GANDIVA_LIB} PROPERTY LABELS integ ${TEST_NAME}_${GANDIVA_LIB})
endfunction(add_gandiva_integ_test REL_TEST_NAME)

# Download and build external project.
Expand Down
18 changes: 13 additions & 5 deletions cpp/src/gandiva/cmake/FindARROW.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@

# Find Arrow library and includes.

find_library(ARROW_LIB arrow REQUIRED)
message(STATUS "Found arrow library at ${ARROW_LIB}")
find_library(ARROW_LIB_STATIC libarrow.a REQUIRED)
find_library(ARROW_LIB_SHARED arrow REQUIRED)
message(STATUS "Found arrow static library at ${ARROW_LIB_STATIC}")
message(STATUS "Found arrow shared library at ${ARROW_LIB_SHARED}")

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

# add an imported target ARROW::ARROW so that gandiva can take a dependency.
add_library(ARROW::ARROW INTERFACE IMPORTED)
set_target_properties(ARROW::ARROW PROPERTIES
add_library(ARROW::ARROW_STATIC STATIC IMPORTED)
add_library(ARROW::ARROW_SHARED INTERFACE IMPORTED)

set_target_properties(ARROW::ARROW_STATIC PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ARROW_INCLUDE_DIR}"
IMPORTED_LOCATION "${ARROW_LIB_STATIC}"
)
set_target_properties(ARROW::ARROW_SHARED PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ARROW_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${ARROW_LIB}"
INTERFACE_LINK_LIBRARIES "${ARROW_LIB_SHARED}"
)
14 changes: 8 additions & 6 deletions cpp/src/gandiva/cmake/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
# 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)

# Convenience function for targets to link llvm.
function(target_link_llvm TARGET TYPE)
target_include_directories(${TARGET} ${TYPE} ${LLVM_INCLUDE_DIRS})
target_compile_definitions(${TARGET} ${TYPE} ${LLVM_DEFINITIONS})
target_link_libraries(${TARGET} ${TYPE} ${LLVM_LIBS})
endfunction()
add_library(LLVM::LLVM_INTERFACE INTERFACE IMPORTED)

set_target_properties(LLVM::LLVM_INTERFACE PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LLVM_INCLUDE_DIRS}"
INTERFACE_COMPILE_FLAGS "${LLVM_DEFINITIONS}"
INTERFACE_LINK_LIBRARIES "${LLVM_LIBS}"
)

17 changes: 9 additions & 8 deletions cpp/src/gandiva/integ/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

project(gandiva)

add_gandiva_integ_test(projector_test.cc)
add_gandiva_integ_test(if_expr_test.cc)
add_gandiva_integ_test(boolean_expr_test.cc)
add_gandiva_integ_test(literal_test.cc)
add_gandiva_integ_test(date_time_test.cc)
add_gandiva_integ_test(projector_build_validation_test.cc)
add_gandiva_integ_test(utf8_test.cc)
add_gandiva_integ_test(binary_test.cc)
foreach(lib_type "shared" "static")
add_gandiva_integ_test(projector_test.cc gandiva_${lib_type})
add_gandiva_integ_test(if_expr_test.cc gandiva_${lib_type})
add_gandiva_integ_test(literal_test.cc gandiva_${lib_type})
add_gandiva_integ_test(projector_build_validation_test.cc gandiva_${lib_type})
add_gandiva_integ_test(boolean_expr_test.cc gandiva_${lib_type})
add_gandiva_integ_test(utf8_test.cc gandiva_${lib_type})
add_gandiva_integ_test(binary_test.cc gandiva_${lib_type})
endforeach(lib_type)
62 changes: 25 additions & 37 deletions cpp/src/gandiva/src/codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,55 @@ project(gandiva)
# Find arrow
find_package(ARROW)

find_package(Boost REQUIRED)
find_package(Boost COMPONENTS system regex filesystem REQUIRED)

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

add_library(gandiva SHARED
annotator.cc
bitmap_accumulator.cc
configuration.cc
engine.cc
expr_decomposer.cc
expr_validator.cc
function_registry.cc
llvm_generator.cc
llvm_types.cc
projector.cc
status.cc
tree_expr_builder.cc
${BC_FILE_PATH_CC})
set(SRC_FILES annotator.cc
engine.cc
bitmap_accumulator.cc
configuration.cc
expr_decomposer.cc
expr_validator.cc
function_registry.cc
llvm_generator.cc
llvm_types.cc
projector.cc
status.cc
tree_expr_builder.cc
${BC_FILE_PATH_CC})

add_library(gandiva_obj_lib OBJECT ${SRC_FILES})

# set PIC so that object library can be included in shared libs.
set_target_properties(gandiva_obj_lib PROPERTIES POSITION_INDEPENDENT_CODE 1)

# For users of gandiva library (including integ tests), include-dir is :
# /usr/**/include dir after install,
# cpp/include during build
# For building gandiva library itself, include-dir (in addition to above) is :
# cpp/src
target_include_directories(gandiva
target_include_directories(gandiva_obj_lib
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
PRIVATE
${CMAKE_SOURCE_DIR}/src
$<TARGET_PROPERTY:LLVM::LLVM_INTERFACE,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:ARROW::ARROW_SHARED,INTERFACE_INCLUDE_DIRECTORIES>
)

# ARROW is a public dependency i.e users of gandiva also will have a dependency on arrow.
target_link_libraries(gandiva
PUBLIC
ARROW::ARROW
PRIVATE
Boost::boost)
build_gandiva_lib("shared")

# LLVM is a private dependency i.e users of gandiva will not need to include llvm headers
# or link with llvm libraries.
target_link_llvm(gandiva PRIVATE)

# Set version for the library.
set(GANDIVA_VERSION_MAJOR 0)
set(GANDIVA_VERSION_MINOR 1)
set(GANDIVA_VERSION_PATCH 0)
set(GANDIVA_VERSION ${GANDIVA_VERSION_MAJOR}.${GANDIVA_VERSION_MINOR}.${GANDIVA_VERSION_PATCH})

set_target_properties(gandiva PROPERTIES
VERSION ${GANDIVA_VERSION}
SOVERSION ${GANDIVA_VERSION_MAJOR}
)
build_gandiva_lib("static")

# install for gandiva
include(GNUInstallDirs)

# install libgandiva
install(
TARGETS gandiva
TARGETS gandiva_shared gandiva_static
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/gandiva/src/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ target_include_directories(gandiva_jni
${CMAKE_SOURCE_DIR}/src
)

# PROTOBUF is a public dependency i.e users of gandiva also will have a dependency on arrow.
# PROTOBUF is a private dependency i.e users of gandiva also will not have a dependency on protobuf.
target_link_libraries(gandiva_jni
PRIVATE
protobuf::libprotobuf
gandiva
gandiva_static
)

0 comments on commit 5a39298

Please sign in to comment.