Customizable internal compiler

This commit is contained in:
proller 2017-03-02 16:34:43 +03:00
parent e8aa65f802
commit 067ff7a5c7
5 changed files with 79 additions and 28 deletions

View File

@ -1,11 +1,12 @@
include(${ClickHouse_SOURCE_DIR}/cmake/dbms_include.cmake) include(${ClickHouse_SOURCE_DIR}/cmake/dbms_include.cmake)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libdivide) include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libdivide)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libcpuid/include/) include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libcpuid/include)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libfarmhash) include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libfarmhash)
include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libmetrohash/src) include_directories (BEFORE ${ClickHouse_SOURCE_DIR}/contrib/libmetrohash/src)
include_directories (${ClickHouse_SOURCE_DIR}/libs/libdaemon/include/) include_directories (${ClickHouse_SOURCE_DIR}/libs/libdaemon/include)
include_directories (${ODBC_INCLUDE_DIRECTORIES}) include_directories (${ODBC_INCLUDE_DIRECTORIES})
include_directories (${ClickHouse_BINARY_DIR}/dbms/include)
if (NOT NO_WERROR) if (NOT NO_WERROR)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")

View File

@ -0,0 +1,12 @@
#pragma once
#cmakedefine PATH_SHARE "@PATH_SHARE@"
#cmakedefine INTERNAL_COMPILER_FLAGS "@INTERNAL_COMPILER_FLAGS@"
#cmakedefine INTERNAL_COMPILER_EXECUTABLE "@INTERNAL_COMPILER_EXECUTABLE@"
#cmakedefine INTERNAL_COMPILER_HEADERS "@INTERNAL_COMPILER_HEADERS@"
#cmakedefine INTERNAL_COMPILER_HEADERS_ROOT "@INTERNAL_COMPILER_HEADERS_ROOT@"
#cmakedefine01 INTERNAL_COMPILER_CUSTOM_ROOT
#cmakedefine INTERNAL_DOUBLE_CONVERSION_INCLUDE_DIR "@INTERNAL_DOUBLE_CONVERSION_INCLUDE_DIR@"
#cmakedefine INTERNAL_Poco_Foundation_INCLUDE_DIR "@INTERNAL_Poco_Foundation_INCLUDE_DIR@"
#cmakedefine INTERNAL_Poco_Util_INCLUDE_DIR "@INTERNAL_Poco_Util_INCLUDE_DIR@"
#cmakedefine INTERNAL_Boost_INCLUDE_DIRS "@INTERNAL_Boost_INCLUDE_DIRS@"

View File

@ -20,6 +20,7 @@
#include <DB/Interpreters/Aggregator.h> #include <DB/Interpreters/Aggregator.h>
#include <common/ClickHouseRevision.h> #include <common/ClickHouseRevision.h>
#include <DB/Interpreters/config_compile.h>
namespace ProfileEvents namespace ProfileEvents
@ -353,7 +354,7 @@ void Aggregator::compileIfPossible(AggregatedDataVariants::Type type)
* по окончании которой вызывается колбэк on_ready. * по окончании которой вызывается колбэк on_ready.
*/ */
SharedLibraryPtr lib = params.compiler->getOrCount(key, params.min_count_to_compile, SharedLibraryPtr lib = params.compiler->getOrCount(key, params.min_count_to_compile,
"-include /usr/share/clickhouse/headers/dbms/include/DB/Interpreters/SpecializedAggregator.h", "-include " INTERNAL_COMPILER_HEADERS "/dbms/include/DB/Interpreters/SpecializedAggregator.h",
get_code, on_ready); get_code, on_ready);
/// Если результат уже готов. /// Если результат уже готов.

View File

@ -1,3 +1,43 @@
if (CMAKE_SYSTEM MATCHES "FreeBSD")
set (PATH_SHARE "/usr/local/share" CACHE STRING "")
else ()
set (PATH_SHARE "/usr/share" CACHE STRING "")
endif ()
if (INTERNAL_COMPILER_SAME)
set (INTERNAL_COMPILER_EXECUTABLE "${CMAKE_CXX_COMPILER}" CACHE STRING "")
else ()
set (INTERNAL_COMPILER_EXECUTABLE "${PATH_SHARE}/clickhouse/bin/clang" CACHE STRING "")
endif ()
set (INTERNAL_COMPILER_NO_WARNING OFF CACHE BOOL "")
#original string:
# -x c++ -std=gnu++1y -O3 -g -Wall -Werror -Wnon-virtual-dtor -march=native -msse4 -mpopcnt -D NDEBUG -D_GLIBCXX_USE_CXX11_ABI=0 -shared -fPIC -fvisibility=hidden -fno-implement-inlines
set (INTERNAL_COMPILER_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -x c++ -march=native -shared -fPIC -fvisibility=hidden -fno-implement-inlines " CACHE STRING "")
string(REPLACE "-no-pie" "" INTERNAL_COMPILER_FLAGS ${INTERNAL_COMPILER_FLAGS})
if (INTERNAL_COMPILER_NO_WARNING)
string (REPLACE "-Wall" "" INTERNAL_COMPILER_FLAGS ${INTERNAL_COMPILER_FLAGS})
string (REPLACE "-Werror" "" INTERNAL_COMPILER_FLAGS ${INTERNAL_COMPILER_FLAGS})
endif ()
set (INTERNAL_COMPILER_HEADERS "${PATH_SHARE}/clickhouse/headers" CACHE STRING "")
set (INTERNAL_COMPILER_HEADERS_ROOT "${INTERNAL_COMPILER_HEADERS}" CACHE STRING "")
set (INTERNAL_COMPILER_CUSTOM_ROOT ON CACHE BOOL "")
list(GET Poco_INCLUDE_DIRS 0 Poco_Foundation_INCLUDE_DIR)
list(GET Poco_INCLUDE_DIRS 1 Poco_Util_INCLUDE_DIR)
string (REPLACE ${ClickHouse_SOURCE_DIR} ${INTERNAL_COMPILER_HEADERS} INTERNAL_DOUBLE_CONVERSION_INCLUDE_DIR ${DOUBLE_CONVERSION_INCLUDE_DIR})
string (REPLACE ${ClickHouse_SOURCE_DIR} ${INTERNAL_COMPILER_HEADERS} INTERNAL_Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
string (REPLACE ${ClickHouse_SOURCE_DIR} ${INTERNAL_COMPILER_HEADERS} INTERNAL_Poco_Foundation_INCLUDE_DIR ${Poco_Foundation_INCLUDE_DIR})
string (REPLACE ${ClickHouse_SOURCE_DIR} ${INTERNAL_COMPILER_HEADERS} INTERNAL_Poco_Util_INCLUDE_DIR ${Poco_Util_INCLUDE_DIR})
message (STATUS "Using internal compiler: headers=${INTERNAL_COMPILER_HEADERS} : ${INTERNAL_COMPILER_EXECUTABLE} ${INTERNAL_COMPILER_FLAGS}")
set (CONFIG_COMPILE ${ClickHouse_BINARY_DIR}/dbms/include/DB/Interpreters/config_compile.h)
configure_file (${ClickHouse_SOURCE_DIR}/dbms/include/DB/Interpreters/config_compile.h.in ${CONFIG_COMPILE})
if (ENABLE_TESTS) if (ENABLE_TESTS)
add_subdirectory (tests) add_subdirectory (tests)
endif (ENABLE_TESTS) endif (ENABLE_TESTS)

View File

@ -12,6 +12,7 @@
#include <DB/IO/WriteBufferFromFile.h> #include <DB/IO/WriteBufferFromFile.h>
#include <DB/Interpreters/Compiler.h> #include <DB/Interpreters/Compiler.h>
#include <DB/Interpreters/config_compile.h>
namespace ProfileEvents namespace ProfileEvents
@ -182,31 +183,27 @@ void Compiler::compile(
/// Слегка неудобно. /// Слегка неудобно.
command << command <<
"LD_LIBRARY_PATH=/usr/share/clickhouse/bin/" "LD_LIBRARY_PATH=" PATH_SHARE "/clickhouse/bin/"
" /usr/share/clickhouse/bin/clang" " " INTERNAL_COMPILER_EXECUTABLE
" -B /usr/share/clickhouse/bin/" " -B " PATH_SHARE "/clickhouse/bin/"
" -x c++ -std=gnu++1y -O3 -g -Wall -Werror -Wnon-virtual-dtor -march=native -msse4 -mpopcnt -D NDEBUG" " " INTERNAL_COMPILER_FLAGS
#if _GLIBCXX_USE_CXX11_ABI == 0 #if INTERNAL_COMPILER_CUSTOM_ROOT
" -D_GLIBCXX_USE_CXX11_ABI=0" " -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/local/include/"
#elif _GLIBCXX_USE_CXX11_ABI == 1 " -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/include/"
" -D_GLIBCXX_USE_CXX11_ABI=1" " -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/include/mysql/"
#endif " -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/include/c++/*/"
" -shared -fPIC -fvisibility=hidden -fno-implement-inlines" " -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/include/x86_64-linux-gnu/"
" -isystem /usr/share/clickhouse/headers/usr/local/include/" " -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/include/x86_64-linux-gnu/c++/*/"
" -isystem /usr/share/clickhouse/headers/usr/include/" " -isystem " INTERNAL_COMPILER_HEADERS_ROOT "/usr/local/lib/clang/*/include/"
" -isystem /usr/share/clickhouse/headers/usr/include/mysql/" #endif
" -isystem /usr/share/clickhouse/headers/usr/include/c++/*/" " -I " INTERNAL_COMPILER_HEADERS "/dbms/include/"
" -isystem /usr/share/clickhouse/headers/usr/include/x86_64-linux-gnu/" " -I " INTERNAL_COMPILER_HEADERS "/contrib/libcityhash/include/"
" -isystem /usr/share/clickhouse/headers/usr/include/x86_64-linux-gnu/c++/*/" " -I " INTERNAL_DOUBLE_CONVERSION_INCLUDE_DIR
" -isystem /usr/share/clickhouse/headers/usr/local/lib/clang/*/include/" " -I " INTERNAL_Poco_Foundation_INCLUDE_DIR
" -I /usr/share/clickhouse/headers/dbms/include/" " -I " INTERNAL_Poco_Util_INCLUDE_DIR
" -I /usr/share/clickhouse/headers/contrib/libcityhash/include/" " -I " INTERNAL_Boost_INCLUDE_DIRS
" -I /usr/share/clickhouse/headers/contrib/libdouble-conversion/" " -I " INTERNAL_COMPILER_HEADERS "/libs/libcommon/include/"
" -I /usr/share/clickhouse/headers/contrib/libpoco/Foundation/include/" " -I " INTERNAL_COMPILER_HEADERS "/libs/libmysqlxx/include/"
" -I /usr/share/clickhouse/headers/contrib/libpoco/Util/include/"
" -I /usr/share/clickhouse/headers/contrib/libboost/boost_1_62_0/"
" -I /usr/share/clickhouse/headers/libs/libcommon/include/"
" -I /usr/share/clickhouse/headers/libs/libmysqlxx/include/"
" " << additional_compiler_flags << " " << additional_compiler_flags <<
" -o " << so_tmp_file_path << " " << cpp_file_path " -o " << so_tmp_file_path << " " << cpp_file_path
<< " 2>&1 || echo Exit code: $?"; << " 2>&1 || echo Exit code: $?";