From 1597d2f886f75c1b9b90872d7fc7a9dbfb93701c Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 12 Oct 2021 03:30:08 +0300 Subject: [PATCH 01/12] Hermetic builds --- PreLoad.cmake | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/PreLoad.cmake b/PreLoad.cmake index 0a25a55e7bf..be911bd9267 100644 --- a/PreLoad.cmake +++ b/PreLoad.cmake @@ -18,3 +18,20 @@ if (NOT DEFINED ENV{CLION_IDE} AND NOT DEFINED ENV{XCODE_IDE}) set(CMAKE_GENERATOR "Ninja" CACHE INTERNAL "" FORCE) endif () endif() + + +# Default toolchain - this is needed to avoid dependency on OS files. +execute_process(COMMAND uname -s OUTPUT_VARIABLE OS) +execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCH) + +if (OS MATCHES "Linux" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) + if (ARCH MATCHES "amd64|x86_64") + set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-x86_64.cmake" CACHE INTERNAL "" FORCE) + elseif (ARCH MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)") + set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-aarch64.cmake" CACHE INTERNAL "" FORCE) + elseif (ARCH MATCHES "^(ppc64le.*|PPC64LE.*)") + set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-ppc64le.cmake" CACHE INTERNAL "" FORCE) + else () + message (FATAL_ERROR "Unsupported architecture: ${ARCH}") + endif () +endif() From d0f7a10c6af2aef445096b6787aefda07a577253 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 12 Oct 2021 03:34:07 +0300 Subject: [PATCH 02/12] Fix fasttest --- docker/test/fasttest/run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/test/fasttest/run.sh b/docker/test/fasttest/run.sh index c8a3ad7c998..cca2f757f8b 100755 --- a/docker/test/fasttest/run.sh +++ b/docker/test/fasttest/run.sh @@ -159,6 +159,7 @@ function clone_submodules cd "$FASTTEST_SOURCE" SUBMODULES_TO_UPDATE=( + contrib/sysroot contrib/magic_enum contrib/abseil-cpp contrib/boost From b1ea87907cda6802c6f65491ab8b8e334258ab97 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 12 Oct 2021 05:41:05 +0300 Subject: [PATCH 03/12] Minor change --- PreLoad.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PreLoad.cmake b/PreLoad.cmake index be911bd9267..286fa798e8e 100644 --- a/PreLoad.cmake +++ b/PreLoad.cmake @@ -24,7 +24,7 @@ endif() execute_process(COMMAND uname -s OUTPUT_VARIABLE OS) execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCH) -if (OS MATCHES "Linux" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) +if (OS MATCHES "Linux" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE AND NOT UNBUNDLED) if (ARCH MATCHES "amd64|x86_64") set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-x86_64.cmake" CACHE INTERNAL "" FORCE) elseif (ARCH MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)") From bdd06279a4197d25d752c05b0b804260a7b79521 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 12 Oct 2021 05:43:53 +0300 Subject: [PATCH 04/12] Fix PVS Studio --- PreLoad.cmake | 2 +- docker/test/pvs/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PreLoad.cmake b/PreLoad.cmake index 286fa798e8e..78342c8d0be 100644 --- a/PreLoad.cmake +++ b/PreLoad.cmake @@ -24,7 +24,7 @@ endif() execute_process(COMMAND uname -s OUTPUT_VARIABLE OS) execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCH) -if (OS MATCHES "Linux" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE AND NOT UNBUNDLED) +if (OS MATCHES "Linux" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE AND NOT UNBUNDLED AND NOT DISABLE_HERMETIC_BUILD) if (ARCH MATCHES "amd64|x86_64") set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-x86_64.cmake" CACHE INTERNAL "" FORCE) elseif (ARCH MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)") diff --git a/docker/test/pvs/Dockerfile b/docker/test/pvs/Dockerfile index f4675d35819..00db82ba59d 100644 --- a/docker/test/pvs/Dockerfile +++ b/docker/test/pvs/Dockerfile @@ -38,7 +38,7 @@ RUN set -x \ && dpkg -i "${PKG_VERSION}.deb" CMD echo "Running PVS version $PKG_VERSION" && cd /repo_folder && pvs-studio-analyzer credentials $LICENCE_NAME $LICENCE_KEY -o ./licence.lic \ - && cmake . -D"ENABLE_EMBEDDED_COMPILER"=OFF -D"USE_INTERNAL_PROTOBUF_LIBRARY"=OFF -D"USE_INTERNAL_GRPC_LIBRARY"=OFF -DCMAKE_C_COMPILER=clang-13 -DCMAKE_CXX_COMPILER=clang\+\+-13 \ + && cmake . -D"ENABLE_EMBEDDED_COMPILER"=OFF -D"USE_INTERNAL_PROTOBUF_LIBRARY"=OFF -D"USE_INTERNAL_GRPC_LIBRARY"=OFF -D"DISABLE_HERMETIC_BUILD"=ON -DCMAKE_C_COMPILER=clang-13 -DCMAKE_CXX_COMPILER=clang\+\+-13 \ && ninja re2_st clickhouse_grpc_protos \ && pvs-studio-analyzer analyze -o pvs-studio.log -e contrib -j 4 -l ./licence.lic; \ cp /repo_folder/pvs-studio.log /test_output; \ From 71e9211c6b28fc70cc7564ac1463b7888bd8a927 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 13 Oct 2021 01:12:50 +0300 Subject: [PATCH 05/12] Fix build --- PreLoad.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/PreLoad.cmake b/PreLoad.cmake index 78342c8d0be..51bae39603d 100644 --- a/PreLoad.cmake +++ b/PreLoad.cmake @@ -24,7 +24,13 @@ endif() execute_process(COMMAND uname -s OUTPUT_VARIABLE OS) execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCH) -if (OS MATCHES "Linux" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE AND NOT UNBUNDLED AND NOT DISABLE_HERMETIC_BUILD) +if (OS MATCHES "Linux" + AND NOT DEFINED CMAKE_TOOLCHAIN_FILE + AND NOT UNBUNDLED + AND NOT DISABLE_HERMETIC_BUILD + AND ($ENV{CC} MATCHES ".*clang.*" OR CMAKE_C_COMPILER MATCHES ".*clang.*") + AND (USE_STATIC_LIBRARIES OR NOT DEFINED USE_STATIC_LIBRARIES)) + if (ARCH MATCHES "amd64|x86_64") set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-x86_64.cmake" CACHE INTERNAL "" FORCE) elseif (ARCH MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)") @@ -34,4 +40,5 @@ if (OS MATCHES "Linux" AND NOT DEFINED CMAKE_TOOLCHAIN_FILE AND NOT UNBUNDLED AN else () message (FATAL_ERROR "Unsupported architecture: ${ARCH}") endif () + endif() From 8d43a5d4b2f1a1d897c0320271a609c219e4edfb Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 24 Nov 2021 03:01:21 +0300 Subject: [PATCH 06/12] Maybe fix build --- cmake/linux/default_libs.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/linux/default_libs.cmake b/cmake/linux/default_libs.cmake index 86fd7fddcff..d729a6126d5 100644 --- a/cmake/linux/default_libs.cmake +++ b/cmake/linux/default_libs.cmake @@ -5,7 +5,7 @@ set (DEFAULT_LIBS "-nodefaultlibs") # We need builtins from Clang's RT even without libcxx - for ubsan+int128. # See https://bugs.llvm.org/show_bug.cgi?id=16404 -if (COMPILER_CLANG AND NOT CMAKE_CROSSCOMPILING) +if (COMPILER_CLANG) execute_process (COMMAND ${CMAKE_CXX_COMPILER} --print-libgcc-file-name --rtlib=compiler-rt OUTPUT_VARIABLE BUILTINS_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) else () set (BUILTINS_LIBRARY "-lgcc") From 7ecffd71861c7c8c27540099d5febce0a39cd1d1 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 24 Nov 2021 15:43:09 +0300 Subject: [PATCH 07/12] Fix build --- cmake/linux/default_libs.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmake/linux/default_libs.cmake b/cmake/linux/default_libs.cmake index d729a6126d5..23374916418 100644 --- a/cmake/linux/default_libs.cmake +++ b/cmake/linux/default_libs.cmake @@ -6,7 +6,11 @@ set (DEFAULT_LIBS "-nodefaultlibs") # We need builtins from Clang's RT even without libcxx - for ubsan+int128. # See https://bugs.llvm.org/show_bug.cgi?id=16404 if (COMPILER_CLANG) - execute_process (COMMAND ${CMAKE_CXX_COMPILER} --print-libgcc-file-name --rtlib=compiler-rt OUTPUT_VARIABLE BUILTINS_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process (COMMAND ${CMAKE_CXX_COMPILER} --target=${CMAKE_CXX_COMPILER_TARGET} --print-libgcc-file-name --rtlib=compiler-rt OUTPUT_VARIABLE BUILTINS_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (NOT EXISTS "${BUILTINS_LIBRARY}") + set (BUILTINS_LIBRARY "-lgcc") + endif () else () set (BUILTINS_LIBRARY "-lgcc") endif () From 92031e6b3134ad522a78e818bd5e19d718ce7400 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 24 Nov 2021 20:25:11 +0300 Subject: [PATCH 08/12] Fix PVS-Studio --- docker/test/pvs/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/test/pvs/Dockerfile b/docker/test/pvs/Dockerfile index eb25bec5262..5dc32ebcc22 100644 --- a/docker/test/pvs/Dockerfile +++ b/docker/test/pvs/Dockerfile @@ -40,7 +40,7 @@ RUN set -x \ ENV CCACHE_DIR=/test_output/ccache CMD echo "Running PVS version $PKG_VERSION" && mkdir -p $CCACHE_DIR && cd /repo_folder && pvs-studio-analyzer credentials $LICENCE_NAME $LICENCE_KEY -o ./licence.lic \ - && cmake . -D"ENABLE_EMBEDDED_COMPILER"=OFF -D"USE_INTERNAL_PROTOBUF_LIBRARY"=OFF -D"USE_INTERNAL_GRPC_LIBRARY"=OFF -D"DISABLE_HERMETIC_BUILD"=ON -DCMAKE_C_COMPILER=clang-13 -DCMAKE_CXX_COMPILER=clang\+\+-13 \ + && cmake . -D"ENABLE_EMBEDDED_COMPILER"=OFF -D"DISABLE_HERMETIC_BUILD"=ON -DCMAKE_C_COMPILER=clang-13 -DCMAKE_CXX_COMPILER=clang\+\+-13 \ && ninja re2_st clickhouse_grpc_protos \ && pvs-studio-analyzer analyze -o pvs-studio.log -e contrib -j 4 -l ./licence.lic; \ cp /repo_folder/pvs-studio.log /test_output; \ From 05b8f0b8913283f333acbfe492f8d56fb0c1e759 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 25 Nov 2021 01:34:51 +0300 Subject: [PATCH 09/12] Update submodule --- contrib/sysroot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/sysroot b/contrib/sysroot index c04ba53ba66..4ef348b7f30 160000 --- a/contrib/sysroot +++ b/contrib/sysroot @@ -1 +1 @@ -Subproject commit c04ba53ba661fda2cd8386c6c08ea81a253d901f +Subproject commit 4ef348b7f30f2ad5b02b266268b3c948e51ad457 From 05349ce7a61a3b00f624966d32b86fa81fd46e62 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 25 Nov 2021 01:50:54 +0300 Subject: [PATCH 10/12] Do not build protobuf twice --- cmake/add_warning.cmake | 6 +++--- contrib/protobuf-cmake/CMakeLists.txt | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmake/add_warning.cmake b/cmake/add_warning.cmake index bc9642c9cc6..e7797fcc7a6 100644 --- a/cmake/add_warning.cmake +++ b/cmake/add_warning.cmake @@ -12,13 +12,13 @@ macro (add_warning flag) if (SUPPORTS_CXXFLAG_${underscored_flag}) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W${flag}") else () - message (WARNING "Flag -W${flag} is unsupported") + message (STATUS "Flag -W${flag} is unsupported") endif () if (SUPPORTS_CFLAG_${underscored_flag}) set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W${flag}") else () - message (WARNING "Flag -W${flag} is unsupported") + message (STATUS "Flag -W${flag} is unsupported") endif () endmacro () @@ -39,7 +39,7 @@ macro (target_add_warning target flag) if (SUPPORTS_CXXFLAG_${underscored_flag}) target_compile_options (${target} PRIVATE "-W${flag}") else () - message (WARNING "Flag -W${flag} is unsupported") + message (STATUS "Flag -W${flag} is unsupported") endif () endmacro () diff --git a/contrib/protobuf-cmake/CMakeLists.txt b/contrib/protobuf-cmake/CMakeLists.txt index 82e212417ac..484524f4278 100644 --- a/contrib/protobuf-cmake/CMakeLists.txt +++ b/contrib/protobuf-cmake/CMakeLists.txt @@ -211,7 +211,9 @@ add_library(protobuf::libprotoc ALIAS libprotoc) set(protoc_files ${protobuf_source_dir}/src/google/protobuf/compiler/main.cc) -if (NOT CMAKE_CROSSCOMPILING) +if (CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME + AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL CMAKE_SYSTEM_PROCESSOR) + add_executable(protoc ${protoc_files}) target_link_libraries(protoc libprotoc libprotobuf pthread) add_executable(protobuf::protoc ALIAS protoc) From 7a95d7f29d8a750d1bf5cd698c82aa6182afc171 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 25 Nov 2021 01:55:36 +0300 Subject: [PATCH 11/12] Remove annoying messages --- contrib/krb5-cmake/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contrib/krb5-cmake/CMakeLists.txt b/contrib/krb5-cmake/CMakeLists.txt index d6c3c23b14e..f7318a5bf8a 100644 --- a/contrib/krb5-cmake/CMakeLists.txt +++ b/contrib/krb5-cmake/CMakeLists.txt @@ -500,7 +500,6 @@ function(preprocess_et out_var) COMMAND perl "${KRB5_SOURCE_DIR}/util/et/compile_et" -d "${KRB5_SOURCE_DIR}/util/et" ${in_f} DEPENDS ${in_f} "${KRB5_SOURCE_DIR}/util/et/compile_et" WORKING_DIRECTORY ${ET_PATH} - COMMENT "Creating preprocessed file ${F_C}" VERBATIM ) list(APPEND result ${F_C}) @@ -526,7 +525,6 @@ add_custom_command( add_custom_target( ERROR_MAP_H DEPENDS "${KRB5_SOURCE_DIR}/lib/gssapi/krb5/error_map.h" - COMMENT "generating error_map.h" VERBATIM ) @@ -539,14 +537,12 @@ add_custom_command( add_custom_target( ERRMAP_H DEPENDS "${KRB5_SOURCE_DIR}/lib/gssapi/generic/errmap.h" - COMMENT "generating errmap.h" VERBATIM ) add_custom_target( KRB_5_H DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/krb5/krb5.h" - COMMENT "generating krb5.h" VERBATIM ) From 2373456866ea78f3d38d423f3359fff822987baa Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 25 Nov 2021 04:18:54 +0300 Subject: [PATCH 12/12] Fix build --- src/Common/renameat2.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Common/renameat2.cpp b/src/Common/renameat2.cpp index 238268d3624..8ee9081af56 100644 --- a/src/Common/renameat2.cpp +++ b/src/Common/renameat2.cpp @@ -99,11 +99,16 @@ bool supportsRenameat2() return supports; } +} + #else #define RENAME_NOREPLACE -1 #define RENAME_EXCHANGE -1 +namespace DB +{ + static bool renameat2(const std::string &, const std::string &, int) { return false; @@ -114,8 +119,13 @@ bool supportsRenameat2() return false; } +} + #endif +namespace DB +{ + static void renameNoReplaceFallback(const std::string & old_path, const std::string & new_path) { /// NOTE it's unsafe