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

[CMake] build velox as static library #12

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ endif()
# set the project name
project(velox)

set(DEPS_INSTALL "/opt/install")
list(APPEND CMAKE_PREFIX_PATH "${DEPS_INSTALL}")
list(APPEND CMAKE_MODULE_PATH "${DEPS_INSTALL}")
set(Boost_USE_STATIC_RUNTIME ON)
set(GFLAGS_USE_TARGET_NAMESPACE TRUE)
message(STATUS "prefix path ${CMAKE_PREFIX_PATH}")
message(STATUS "module path ${CMAKE_MODULE_PATH}")

list(PREPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMake"
"${PROJECT_SOURCE_DIR}/CMake/third-party")

Expand Down Expand Up @@ -539,3 +547,25 @@ endif()

add_subdirectory(third_party)
add_subdirectory(velox)

# install as a subdirectory only
install(EXPORT ${PROJECT_NAME}Targets
NAMESPACE velox::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

configure_package_config_file(
CMake/veloxConfig.cmake.in
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

install(DIRECTORY velox
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.inc"
PATTERN "*.h"
)
3 changes: 2 additions & 1 deletion scripts/setup-helper-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ function get_cxx_flags {
;;

"avx")
echo -n "-mavx2 -mfma -mavx -mf16c -mlzcnt -std=c++17 -mbmi2 $ADDITIONAL_FLAGS"
echo -n "-mavx2 -mfma -mavx -mf16c -mlzcnt -mno-avx512bw -mno-avx512cd \
-mno-avx512dq -mno-avx512f -std=c++17 -mbmi2 $ADDITIONAL_FLAGS"
;;

"sse")
Expand Down
4 changes: 2 additions & 2 deletions scripts/setup-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ function install_conda {
}

function install_velox_deps {
run_and_time install_fmt
run_and_time install_folly
#run_and_time install_fmt
#run_and_time install_folly
run_and_time install_fizz
run_and_time install_wangle
run_and_time install_fbthrift
Expand Down
181 changes: 115 additions & 66 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,84 +12,133 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")

include(ExternalProject)

if(VELOX_ENABLE_ARROW)
find_package(Thrift)
if(Thrift_FOUND)
set(THRIFT_SOURCE "SYSTEM")
else()
set(THRIFT_SOURCE "BUNDLED")
endif()
set(ARROW_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/arrow_ep")
set(ARROW_CMAKE_ARGS
-DARROW_PARQUET=ON
-DARROW_WITH_LZ4=ON
-DARROW_WITH_SNAPPY=ON
-DARROW_WITH_ZLIB=ON
-DARROW_WITH_ZSTD=ON
-DARROW_JEMALLOC=OFF
-DARROW_SIMD_LEVEL=NONE
-DARROW_RUNTIME_SIMD_LEVEL=NONE
-DARROW_WITH_UTF8PROC=OFF
-DARROW_TESTING=ON
-DCMAKE_INSTALL_PREFIX=${ARROW_PREFIX}/install
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DARROW_BUILD_STATIC=ON
-DThrift_SOURCE=${THRIFT_SOURCE})
set(ARROW_LIBDIR ${ARROW_PREFIX}/install/${CMAKE_INSTALL_LIBDIR})
find_package(Arrow)

add_library(thrift STATIC IMPORTED GLOBAL)
if(NOT Thrift_FOUND)
set(THRIFT_ROOT ${ARROW_PREFIX}/src/arrow_ep-build/thrift_ep-install)
set(THRIFT_LIB ${THRIFT_ROOT}/lib/libthrift.a)
add_library(arrow STATIC IMPORTED GLOBAL)
add_library(arrow_testing STATIC IMPORTED GLOBAL)
add_library(parquet STATIC IMPORTED GLOBAL)

file(MAKE_DIRECTORY ${THRIFT_ROOT}/include)
set(THRIFT_INCLUDE_DIR ${THRIFT_ROOT}/include)
endif()
if(NOT Arrow_FOUND)
find_package(Thrift)
if(Thrift_FOUND)
set(THRIFT_SOURCE "SYSTEM")
else()
set(THRIFT_SOURCE "BUNDLED")
endif()
set(ARROW_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/arrow_ep")
set(ARROW_CMAKE_ARGS
-DARROW_PARQUET=ON
-DARROW_WITH_LZ4=ON
-DARROW_WITH_SNAPPY=ON
-DARROW_WITH_ZLIB=ON
-DARROW_WITH_ZSTD=ON
-DARROW_JEMALLOC=OFF
-DARROW_SIMD_LEVEL=NONE
-DARROW_RUNTIME_SIMD_LEVEL=NONE
-DARROW_WITH_UTF8PROC=OFF
-DARROW_TESTING=ON
-DCMAKE_INSTALL_PREFIX=${ARROW_PREFIX}/install
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DARROW_BUILD_STATIC=ON
-DThrift_SOURCE=${THRIFT_SOURCE}
)
set(ARROW_LIBDIR ${ARROW_PREFIX}/install/${CMAKE_INSTALL_LIBDIR})
file(MAKE_DIRECTORY ${ARROW_INCLUDE_DIR})
set(ARROW_INCLUDE_DIR ${ARROW_PREFIX}/install/include)
set(ARROW_STATIC_LIB ${ARROW_LIBDIR}/libarrow.a)
set(PARQUET_STATIC_LIB ${ARROW_LIBDIR}/libparquet.a)

set_property(TARGET thrift PROPERTY INTERFACE_INCLUDE_DIRECTORIES
${THRIFT_INCLUDE_DIR})
set_property(TARGET thrift PROPERTY IMPORTED_LOCATION ${THRIFT_LIB})
if(NOT Thrift_FOUND)
set(THRIFT_ROOT ${ARROW_PREFIX}/src/arrow_ep-build/thrift_ep-install)
set(THRIFT_LIB ${THRIFT_ROOT}/lib/libthrift.a)

set(VELOX_ARROW_BUILD_VERSION 13.0.0)
set(VELOX_ARROW_BUILD_SHA256_CHECKSUM
35dfda191262a756be934eef8afee8d09762cad25021daa626eb249e251ac9e6)
set(VELOX_ARROW_SOURCE_URL
"https://archive.apache.org/dist/arrow/arrow-${VELOX_ARROW_BUILD_VERSION}/apache-arrow-${VELOX_ARROW_BUILD_VERSION}.tar.gz"
)
file(MAKE_DIRECTORY ${THRIFT_ROOT}/include)
set(THRIFT_INCLUDE_DIR ${THRIFT_ROOT}/include)
endif()

resolve_dependency_url(ARROW)
set(VELOX_ARROW_BUILD_VERSION 13.0.0)
set(VELOX_ARROW_BUILD_SHA256_CHECKSUM 35dfda191262a756be934eef8afee8d09762cad25021daa626eb249e251ac9e6)
set(VELOX_ARROW_SOURCE_URL
"https://archive.apache.org/dist/arrow/arrow-${VELOX_ARROW_BUILD_VERSION}/apache-arrow-${VELOX_ARROW_BUILD_VERSION}.tar.gz"
)

ExternalProject_Add(
arrow_ep
PREFIX ${ARROW_PREFIX}
URL ${VELOX_ARROW_SOURCE_URL}
URL_HASH ${VELOX_ARROW_BUILD_SHA256_CHECKSUM}
SOURCE_SUBDIR cpp
CMAKE_ARGS ${ARROW_CMAKE_ARGS}
BUILD_BYPRODUCTS ${ARROW_LIBDIR}/libarrow.a ${ARROW_LIBDIR}/libparquet.a
${ARROW_LIBDIR}/libarrow_testing.a ${THRIFT_LIB})
add_library(arrow STATIC IMPORTED GLOBAL)
add_library(arrow_testing STATIC IMPORTED GLOBAL)
add_library(parquet STATIC IMPORTED GLOBAL)
add_dependencies(arrow arrow_ep)
resolve_dependency_url(ARROW)

ExternalProject_Add(
arrow_ep
PREFIX ${ARROW_PREFIX}
URL ${VELOX_ARROW_SOURCE_URL}
URL_HASH ${VELOX_ARROW_BUILD_SHA256_CHECKSUM}
SOURCE_SUBDIR cpp
CMAKE_ARGS ${ARROW_CMAKE_ARGS}
BUILD_BYPRODUCTS
${ARROW_LIBDIR}/libarrow.a
${ARROW_LIBDIR}/libparquet.a
${ARROW_LIBDIR}/libarrow_testing.a
${THRIFT_LIB}
)
add_dependencies(arrow arrow_ep)
set_target_properties(arrow_testing PROPERTIES IMPORTED_LOCATION ${ARROW_LIBDIR}/libarrow_testing.a)
else() # NOT Arrow_FOUND
find_package(Thrift)
if(NOT Thrift_FOUND)
set(ARROW_THRIFT_BUILD_VERSION 0.20.0)
set(THRIFT_SOURCE_URL
"https://downloads.apache.org/thrift/${ARROW_THRIFT_BUILD_VERSION}/thrift-${ARROW_THRIFT_BUILD_VERSION}.tar.gz"
)
set(ARROW_THRIFT_BUILD_SHA256_CHECKSUM b5d8311a779470e1502c027f428a1db542f5c051c8e1280ccd2163fa935ff2d6)
set(THRIFT_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/thrift_ep-install")
set(THRIFT_INCLUDE_DIR ${THRIFT_PREFIX}/include)
file(MAKE_DIRECTORY ${THRIFT_INCLUDE_DIR})
set(THRIFT_CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${THRIFT_PREFIX}
-DCMAKE_INSTALL_RPATH=${THRIFT_PREFIX}/lib
-DBUILD_STATIC_LIBS=ON
-DBUILD_TESTING=OFF
# Work around https://gitlab.kitware.com/cmake/cmake/issues/18865
-DBoost_NO_BOOST_CMAKE=ON
-DBUILD_COMPILER=OFF
-DBUILD_EXAMPLES=OFF
-DBUILD_TUTORIALS=OFF
-DCMAKE_DEBUG_POSTFIX=
-DWITH_AS3=OFF
-DWITH_CPP=ON
-DWITH_C_GLIB=OFF
-DWITH_JAVA=OFF
-DWITH_JAVASCRIPT=OFF
-DWITH_LIBEVENT=OFF
-DWITH_NODEJS=OFF
-DWITH_PYTHON=OFF
-DWITH_QT5=OFF
-DWITH_ZLIB=OFF
)
set(THRIFT_LIB ${THRIFT_PREFIX}/lib/libthrift.a)

ExternalProject_Add(
thrift_ep
PREFIX ${THRIFT_PREFIX}
URL ${THRIFT_SOURCE_URL}
URL_HASH "SHA256=${ARROW_THRIFT_BUILD_SHA256_CHECKSUM}"
BUILD_BYPRODUCTS ${THRIFT_LIB}
CMAKE_ARGS ${THRIFT_CMAKE_ARGS}
)
add_dependencies(thrift thrift_ep)
endif()
find_package(Parquet CONFIG REQUIRED)
endif() # NOT Arrow_FOUND
add_dependencies(arrow_testing arrow)
add_dependencies(parquet arrow)
file(MAKE_DIRECTORY ${ARROW_PREFIX}/install/include)
set_target_properties(
arrow arrow_testing parquet PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
${ARROW_PREFIX}/install/include)
set_target_properties(arrow PROPERTIES IMPORTED_LOCATION
${ARROW_LIBDIR}/libarrow.a)
set_property(TARGET arrow PROPERTY INTERFACE_LINK_LIBRARIES ${RE2} thrift)
set_target_properties(
arrow_testing PROPERTIES IMPORTED_LOCATION
${ARROW_LIBDIR}/libarrow_testing.a)
set_target_properties(parquet PROPERTIES IMPORTED_LOCATION
${ARROW_LIBDIR}/libparquet.a)

endif()
set_property(TARGET thrift PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${THRIFT_INCLUDE_DIR})
set_property(TARGET thrift PROPERTY IMPORTED_LOCATION ${THRIFT_LIB})
set_target_properties(arrow arrow_testing parquet PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${ARROW_INCLUDE_DIR})
set_target_properties(arrow PROPERTIES IMPORTED_LOCATION ${ARROW_STATIC_LIB})
set_target_properties(parquet PROPERTIES IMPORTED_LOCATION ${PARQUET_STATIC_LIB})
endif() # VELOX_ENABLE_ARROW
1 change: 1 addition & 0 deletions velox/common/base/SuccinctPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#pragma once
#include <cinttypes>
#include <string>

namespace facebook::velox {
Expand Down
6 changes: 6 additions & 0 deletions velox/common/process/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ target_link_libraries(
if(${VELOX_BUILD_TESTING})
add_subdirectory(tests)
endif()

install(TARGETS velox_process EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
1 change: 1 addition & 0 deletions velox/common/process/ProcessBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include <cinttypes>
#include <pthread.h>
#include <sys/types.h>
#include <string>
Expand Down
6 changes: 6 additions & 0 deletions velox/common/time/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ endif()

add_library(velox_time Timer.cpp CpuWallTimer.cpp)
target_link_libraries(velox_time PUBLIC velox_process Folly::folly fmt::fmt)

install(TARGETS velox_time EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
1 change: 1 addition & 0 deletions velox/connectors/hive/HiveConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <optional>
#include <string>
#include <cstdint>

namespace facebook::velox {
class Config;
Expand Down
6 changes: 6 additions & 0 deletions velox/flag_definitions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@
# limitations under the License.
add_library(velox_flag_definitions OBJECT flags.cpp)
target_link_libraries(velox_flag_definitions PRIVATE gflags::gflags)

install(TARGETS velox_flag_definitions EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
3 changes: 3 additions & 0 deletions velox/substrait/SubstraitParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ int32_t SubstraitParser::parseReferenceSegment(
kStructField: {
return refSegment.struct_field().field();
}
case ::substrait::Expression::ReferenceSegment::ReferenceTypeCase::kListElement: {
return refSegment.list_element().offset();
}
default:
VELOX_NYI(
"Substrait conversion not supported for ReferenceSegment '{}'",
Expand Down
6 changes: 4 additions & 2 deletions velox/substrait/SubstraitToVeloxExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace facebook::velox::substrait {
/// expressions.
class SubstraitVeloxExprConverter {
public:
virtual ~SubstraitVeloxExprConverter() = default;

/// subParser: A Substrait parser used to convert Substrait representations
/// into recognizable representations. functionMap: A pre-constructed map
/// storing the relations between the function id and the function name.
Expand Down Expand Up @@ -54,7 +56,7 @@ class SubstraitVeloxExprConverter {
const ::substrait::Expression::Literal& substraitLit);

/// Convert Substrait Expression into Velox Expression.
core::TypedExprPtr toVeloxExpr(
virtual core::TypedExprPtr toVeloxExpr(
const ::substrait::Expression& substraitExpr,
const RowTypePtr& inputType);

Expand All @@ -63,7 +65,7 @@ class SubstraitVeloxExprConverter {
const ::substrait::Expression::IfThen& substraitIfThen,
const RowTypePtr& inputType);

private:
protected:
/// Convert list literal to ArrayVector.
ArrayVectorPtr literalsToArrayVector(
const ::substrait::Expression::Literal& listLiteral);
Expand Down
4 changes: 2 additions & 2 deletions velox/substrait/SubstraitToVeloxPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class SubstraitVeloxPlanConverter {
const RowTypePtr& type);

/// Convert Substrait Rel into Velox PlanNode.
core::PlanNodePtr toVeloxPlan(const ::substrait::Rel& rel);
virtual core::PlanNodePtr toVeloxPlan(const ::substrait::Rel& rel);

/// Convert Substrait RelRoot into Velox PlanNode.
core::PlanNodePtr toVeloxPlan(const ::substrait::RelRoot& root);
Expand Down Expand Up @@ -121,7 +121,7 @@ class SubstraitVeloxPlanConverter {
const ::substrait::RelCommon& relCommon,
const core::PlanNodePtr& noEmitNode);

private:
protected:
/// Returns unique ID to use for plan node. Produces sequential numbers
/// starting from zero.
std::string nextPlanNodeId();
Expand Down
4 changes: 2 additions & 2 deletions velox/type/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -2392,7 +2392,7 @@ struct fmt::formatter<facebook::velox::TypeKind> {

template <typename FormatContext>
auto format(const facebook::velox::TypeKind& k, FormatContext& ctx) const {
return format_to(ctx.out(), "{}", facebook::velox::mapTypeKindToName(k));
return fmt::format_to(ctx.out(), "{}", facebook::velox::mapTypeKindToName(k));
}
};

Expand All @@ -2407,6 +2407,6 @@ struct fmt::formatter<

template <typename FormatContext>
auto format(const std::shared_ptr<T>& k, FormatContext& ctx) const {
return format_to(ctx.out(), "{}", k->toString());
return fmt::format_to(ctx.out(), "{}", k->toString());
}
};
Loading
Loading