Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate gandiva to arrow build. #8

Merged
merged 3 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ Always OFF if building binaries"
set(PARQUET_ARROW_LINKAGE "shared" CACHE STRING
"How to link Arrow libraries with libparquet.so. static|shared (default shared)")

# Gandiva related build options
option(ARROW_GANDIVA
"Build the Gandiva libraries"
OFF)

endif()

if(ARROW_BUILD_TESTS OR ARROW_BUILD_BENCHMARKS)
Expand Down Expand Up @@ -746,3 +751,7 @@ endif()
if(ARROW_PARQUET)
add_subdirectory(src/parquet)
endif()

if(ARROW_GANDIVA)
add_subdirectory(src/gandiva)
endif()
43 changes: 43 additions & 0 deletions cpp/cmake_modules/FindLLVM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Usage of this module as follows:
#
# find_package(LLVM)
#

set(GANDIVA_LLVM_VERSION 6.0)
find_package(LLVM ${GANDIVA_LLVM_VERSION} REQUIRED CONFIG HINTS
/usr/local/opt/llvm
/usr/share)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
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)

set(CLANG_EXECUTABLE ${LLVM_TOOLS_BINARY_DIR}/clang CACHE STRING "clang")
set(LINK_EXECUTABLE ${LLVM_TOOLS_BINARY_DIR}/llvm-link CACHE STRING "link")
set(CLANG_FORMAT_EXECUTABLE ${LLVM_TOOLS_BINARY_DIR}/clang-format CACHE STRING "clang-format")

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}"
)
1 change: 1 addition & 0 deletions cpp/cmake_modules/FindProtobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ mark_as_advanced (
PROTOBUF_STATIC_LIB
PROTOC_STATIC_LIB
)

175 changes: 175 additions & 0 deletions cpp/cmake_modules/GandivaBuildUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Build the gandiva library
function(build_gandiva_lib TYPE ARROW)
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
PRIVATE
Boost::boost
Boost::regex
Boost::system
Boost::filesystem
LLVM::LLVM_INTERFACE
${RE2_STATIC_LIB})

if (${TYPE} MATCHES "static" AND NOT APPLE)
target_link_libraries(gandiva_${TYPE}
LINK_PRIVATE
-static-libstdc++ -static-libgcc)
endif()

# 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" OR
${REL_TEST_NAME} MATCHES "expression_registry")
# If the unit test has llvm in its name, include llvm.
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_shared ${GTEST_STATIC_LIB} ${GTEST_MAIN_STATIC_LIB} ${RE2_STATIC_LIB} Boost::boost
)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
set_property(TEST ${TEST_NAME} PROPERTY LABELS unittest ${TEST_NAME})
endfunction(add_gandiva_unit_test REL_TEST_NAME)

# Add a unittest executable for a precompiled file (used to generate IR)
function(add_precompiled_unit_test REL_TEST_NAME)
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}/src)
target_link_libraries(${TEST_NAME} PRIVATE ${RE2_STATIC_LIB} ${GTEST_STATIC_LIB} ${GTEST_MAIN_STATIC_LIB})
target_compile_definitions(${TEST_NAME} PRIVATE GANDIVA_UNIT_TEST=1)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
set_property(TEST ${TEST_NAME} PROPERTY LABELS unittest ${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 GANDIVA_LIB)
get_filename_component(TEST_NAME ${REL_TEST_NAME} NAME_WE)

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_STATIC_LIB} ${GTEST_MAIN_STATIC_LIB})

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.
function(build_external PROJ)
message("Building ${PROJ} as external project")
# configure the download
configure_file(${CMAKE_SOURCE_DIR}/cmake/${PROJ}-CMakeLists.txt.in ${CMAKE_BINARY_DIR}/${PROJ}-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJ}-download )
if(result)
message(FATAL_ERROR "CMake step for ${PROJ} failed: ${result}")
endif(result)

# unpack
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${PROJ}-download )
if(result)
message(FATAL_ERROR "Build step for ${PROJ} failed: ${result}")
endif(result)

# Add project directly to the build.
add_subdirectory(${CMAKE_BINARY_DIR}/${PROJ}-src
${CMAKE_BINARY_DIR}/${PROJ}-build
EXCLUDE_FROM_ALL)
endfunction(build_external PROJ)

file(GLOB_RECURSE LINT_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/integ/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/integ/*.cc"
)

# Add "make stylecheck" target
function(add_stylecheck)
if (UNIX)
add_custom_target(stylecheck
COMMENT "Performing stylecheck on all .cpp/.h files"
# use ! to check for no replacement
COMMAND !
${CLANG_FORMAT_EXECUTABLE}
-style=file
-output-replacements-xml
${LINT_FILES}
| grep "replacement offset"
)
endif (UNIX)
endfunction(add_stylecheck)

# Add "make stylefix" target
function(add_stylefix)
if (UNIX)
add_custom_target(stylefix
COMMENT "Performing stylefix on all .cpp/.h files"
COMMAND
echo ${LINT_FILES} | xargs ${CLANG_FORMAT_EXECUTABLE} -style=file -i
)
endif (UNIX)
endfunction(add_stylefix)

function(prevent_in_source_builds)
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(FATAL_ERROR "Gandiva does not support in-source builds")
endif()
endfunction(prevent_in_source_builds)
44 changes: 0 additions & 44 deletions cpp/src/CMakeLists.txt

This file was deleted.

Loading