From 81da51a52856fad1f2fb5e41b47dd8e6b2468669 Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Wed, 25 Sep 2019 21:43:31 +0300 Subject: [PATCH 1/7] Disable some contribs for cross-compilation --- cmake/target.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmake/target.cmake b/cmake/target.cmake index 1be6abe8152b..51b268b7a04b 100644 --- a/cmake/target.cmake +++ b/cmake/target.cmake @@ -64,6 +64,15 @@ if (CMAKE_CROSSCOMPILING) set (HAS_POST_2038_EXITCODE "0" CACHE STRING "Result from TRY_RUN" FORCE) set (HAS_POST_2038_EXITCODE__TRYRUN_OUTPUT "" CACHE STRING "Output from TRY_RUN" FORCE) + + # FIXME: broken dependencies + set (USE_SNAPPY OFF) + set (ENABLE_SSL OFF) + set (ENABLE_PROTOBUF OFF) + set (ENABLE_PARQUET OFF) + set (ENABLE_READLINE OFF) + set (ENABLE_ICU OFF) + set (ENABLE_FASTOPS OFF) endif () # Don't know why but CXX_STANDARD doesn't work for cross-compilation From 77d4ffb4e99e2f22030142a5babafffb31294d6f Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Mon, 30 Sep 2019 11:55:59 +0300 Subject: [PATCH 2/7] Fix clang-8-darwin build --- docker/packager/packager | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docker/packager/packager b/docker/packager/packager index f9cd6974c5db..7b670a7fe2e5 100755 --- a/docker/packager/packager +++ b/docker/packager/packager @@ -119,11 +119,11 @@ def parse_env_variables(build_type, compiler, sanitizer, package_type, cache, di cmake_flags.append('-DCMAKE_CXX_COMPILER=`which {}`'.format(cxx)) if "darwin" in compiler: - cmake_flags.append("-DCMAKE_AR:FILEPATH=/cctools/bin/x86_64-apple-darwin-ar") \ - .append("-DCMAKE_RANLIB:FILEPATH=/cctools/bin/x86_64-apple-darwin-ranlib") \ - .append("-DCMAKE_SYSTEM_NAME=Darwin") \ - .append("-DSDK_PATH=/cctools/MacOSX10.14.sdk") \ - .append("-DLINKER_NAME=/cctools/bin/x86_64-apple-darwin-ld") + cmake_flags.append("-DCMAKE_AR:FILEPATH=/cctools/bin/x86_64-apple-darwin-ar") + cmake_flags.append("-DCMAKE_RANLIB:FILEPATH=/cctools/bin/x86_64-apple-darwin-ranlib") + cmake_flags.append("-DCMAKE_SYSTEM_NAME=Darwin") + cmake_flags.append("-DSDK_PATH=/cctools/MacOSX10.14.sdk") + cmake_flags.append("-DLINKER_NAME=/cctools/bin/x86_64-apple-darwin-ld") if sanitizer: result.append("SANITIZER={}".format(sanitizer)) From 33817fe59c90e202bc0e28be500111026b4e61ed Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Mon, 30 Sep 2019 13:21:29 +0300 Subject: [PATCH 3/7] Another fix --- docker/packager/packager | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docker/packager/packager b/docker/packager/packager index 7b670a7fe2e5..a29702d5cce6 100755 --- a/docker/packager/packager +++ b/docker/packager/packager @@ -107,7 +107,10 @@ def parse_env_variables(build_type, compiler, sanitizer, package_type, cache, di result = [] cmake_flags = ['$CMAKE_FLAGS', '-DADD_GDB_INDEX_FOR_GOLD=1'] - cc = compiler + if compiler.endswith("-darwin"): + cc = compiler[:-len("-darwin")] + else: + cc = compiler cxx = cc.replace('gcc', 'g++').replace('clang', 'clang++') if package_type == "deb": result.append("DEB_CC={}".format(cc)) From dfe363d5d475ef63bce005bd86c707b1b9f3ea89 Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Mon, 30 Sep 2019 15:21:08 +0300 Subject: [PATCH 4/7] Also fix docs --- docs/en/development/build_cross.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/en/development/build_cross.md b/docs/en/development/build_cross.md index ebbde15ec3fe..157921201586 100644 --- a/docs/en/development/build_cross.md +++ b/docs/en/development/build_cross.md @@ -14,39 +14,37 @@ sudo apt-get install clang-8 # Install Cross-Compilation Toolset +Let's remember the path where we install `cctools` as ${CCTOOLS} + ```bash -mkdir cctools +mkdir ${CCTOOLS} git clone https://github.com/tpoechtrager/apple-libtapi.git cd apple-libtapi -INSTALLPREFIX=../cctools ./build.sh +INSTALLPREFIX=${CCTOOLS} ./build.sh ./install.sh cd .. git clone https://github.com/tpoechtrager/cctools-port.git cd cctools-port/cctools -./configure --prefix=../cctools --with-libtapi=../cctools --target=x86_64-apple-darwin +./configure --prefix=${CCTOOLS} --with-libtapi=${CCTOOLS} --target=x86_64-apple-darwin make install -cd .. -cd cctools +cd ${CCTOOLS} wget https://github.com/phracker/MacOSX-SDKs/releases/download/10.14-beta4/MacOSX10.14.sdk.tar.xz tar xJf MacOSX10.14.sdk.tar.xz ``` -Let's remember the path where we created `cctools` directory as ${CCTOOLS_PARENT} - # Build ClickHouse ```bash cd ClickHouse mkdir build-osx CC=clang-8 CXX=clang++-8 cmake . -Bbuild-osx -DCMAKE_SYSTEM_NAME=Darwin \ - -DCMAKE_AR:FILEPATH=${CCTOOLS_PARENT}/cctools/bin/x86_64-apple-darwin-ar \ - -DCMAKE_RANLIB:FILEPATH=${CCTOOLS_PARENT}/cctools/bin/x86_64-apple-darwin-ranlib \ - -DLINKER_NAME=${CCTOOLS_PARENT}/cctools/bin/x86_64-apple-darwin-ld \ - -DSDK_PATH=${CCTOOLS_PARENT}/cctools/MacOSX10.14.sdk \ - -DUSE_SNAPPY=OFF -DENABLE_SSL=OFF -DENABLE_PROTOBUF=OFF -DENABLE_PARQUET=OFF -DENABLE_READLINE=OFF -DENABLE_ICU=OFF -DENABLE_FASTOPS=OFF + -DCMAKE_AR:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ar \ + -DCMAKE_RANLIB:FILEPATH=${CCTOOLS}/bin/x86_64-apple-darwin-ranlib \ + -DLINKER_NAME=${CCTOOLS}/bin/x86_64-apple-darwin-ld \ + -DSDK_PATH=${CCTOOLS}/MacOSX10.14.sdk ninja -C build-osx ``` From 6307702270d02d9962acae76ca7703ab7fcf7188 Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Tue, 1 Oct 2019 14:45:35 +0300 Subject: [PATCH 5/7] Add diagnostics --- cmake/target.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/target.cmake b/cmake/target.cmake index 51b268b7a04b..cfd93c4531d3 100644 --- a/cmake/target.cmake +++ b/cmake/target.cmake @@ -73,6 +73,10 @@ if (CMAKE_CROSSCOMPILING) set (ENABLE_READLINE OFF) set (ENABLE_ICU OFF) set (ENABLE_FASTOPS OFF) + + message (STATUS "Cross-compiling for Darwin") + else () + message (FATAL_ERROR "Trying to cross-compile to unsupported target: ${CMAKE_SYSTEM_NAME}!") endif () # Don't know why but CXX_STANDARD doesn't work for cross-compilation From faa762f8bb13076942c19b2df78cf399cc812b4a Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Wed, 2 Oct 2019 13:46:25 +0300 Subject: [PATCH 6/7] Check cross-compilation in each file individually. --- cmake/find/fastops.cmake | 2 +- cmake/find/icu.cmake | 2 +- cmake/find/parquet.cmake | 2 +- cmake/find/protobuf.cmake | 2 +- cmake/find/readline_edit.cmake | 2 +- cmake/find/snappy.cmake | 2 +- cmake/find/ssl.cmake | 2 +- cmake/target.cmake | 15 ++++++++------- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/cmake/find/fastops.cmake b/cmake/find/fastops.cmake index 08a977c240bd..61d1bd9f4e79 100644 --- a/cmake/find/fastops.cmake +++ b/cmake/find/fastops.cmake @@ -2,7 +2,7 @@ if (NOT ARCH_ARM AND NOT OS_FREEBSD) option (ENABLE_FASTOPS "Enable fast vectorized mathematical functions library by Mikhail Parakhin" ${NOT_UNBUNDLED}) endif () -if (ENABLE_FASTOPS) +if (ENABLE_FASTOPS AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") if(NOT EXISTS "${ClickHouse_SOURCE_DIR}/contrib/fastops/fastops/fastops.h") message(FATAL_ERROR "submodule contrib/fastops is missing. to fix try run: \n git submodule update --init --recursive") set(USE_FASTOPS 0) diff --git a/cmake/find/icu.cmake b/cmake/find/icu.cmake index d83a7ba4cb43..5be862f478a6 100644 --- a/cmake/find/icu.cmake +++ b/cmake/find/icu.cmake @@ -1,6 +1,6 @@ option(ENABLE_ICU "Enable ICU" ON) -if(ENABLE_ICU) +if(ENABLE_ICU AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") if (APPLE) set(ICU_ROOT "/usr/local/opt/icu4c" CACHE STRING "") endif() diff --git a/cmake/find/parquet.cmake b/cmake/find/parquet.cmake index 77ce38b255e2..79be144a7a4c 100644 --- a/cmake/find/parquet.cmake +++ b/cmake/find/parquet.cmake @@ -1,6 +1,6 @@ option (ENABLE_PARQUET "Enable parquet" ON) -if (ENABLE_PARQUET) +if (ENABLE_PARQUET AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") if (NOT OS_FREEBSD AND NOT APPLE) # Freebsd: ../contrib/arrow/cpp/src/arrow/util/bit-util.h:27:10: fatal error: endian.h: No such file or directory option(USE_INTERNAL_PARQUET_LIBRARY "Set to FALSE to use system parquet library instead of bundled" ${NOT_UNBUNDLED}) diff --git a/cmake/find/protobuf.cmake b/cmake/find/protobuf.cmake index 57d546392c18..fe990cfe3c81 100644 --- a/cmake/find/protobuf.cmake +++ b/cmake/find/protobuf.cmake @@ -1,6 +1,6 @@ option (ENABLE_PROTOBUF "Enable protobuf" ON) -if (ENABLE_PROTOBUF) +if (ENABLE_PROTOBUF AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") option(USE_INTERNAL_PROTOBUF_LIBRARY "Set to FALSE to use system protobuf instead of bundled" ${NOT_UNBUNDLED}) diff --git a/cmake/find/readline_edit.cmake b/cmake/find/readline_edit.cmake index c2bba6cbfab7..02e80a22fb12 100644 --- a/cmake/find/readline_edit.cmake +++ b/cmake/find/readline_edit.cmake @@ -2,7 +2,7 @@ include (CMakePushCheckState) cmake_push_check_state () option (ENABLE_READLINE "Enable readline" 1) -if (ENABLE_READLINE) +if (ENABLE_READLINE AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") set (READLINE_PATHS "/usr/local/opt/readline/lib") # First try find custom lib for macos users (default lib without history support) diff --git a/cmake/find/snappy.cmake b/cmake/find/snappy.cmake index a39139ee3630..3287ebee68ee 100644 --- a/cmake/find/snappy.cmake +++ b/cmake/find/snappy.cmake @@ -1,6 +1,6 @@ option(USE_SNAPPY "Enable support of snappy library" ON) -if (USE_SNAPPY) +if (USE_SNAPPY AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") option (USE_INTERNAL_SNAPPY_LIBRARY "Set to FALSE to use system snappy library instead of bundled" ${NOT_UNBUNDLED}) if(NOT USE_INTERNAL_SNAPPY_LIBRARY) diff --git a/cmake/find/ssl.cmake b/cmake/find/ssl.cmake index 58027276c5c9..29fa1b9286e4 100644 --- a/cmake/find/ssl.cmake +++ b/cmake/find/ssl.cmake @@ -1,6 +1,6 @@ option (ENABLE_SSL "Enable ssl" ON) -if (ENABLE_SSL) +if (ENABLE_SSL AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") if(NOT ARCH_32) option(USE_INTERNAL_SSL_LIBRARY "Set to FALSE to use system *ssl library instead of bundled" ${NOT_UNBUNDLED}) diff --git a/cmake/target.cmake b/cmake/target.cmake index cfd93c4531d3..2d3309ec1892 100644 --- a/cmake/target.cmake +++ b/cmake/target.cmake @@ -65,14 +65,15 @@ if (CMAKE_CROSSCOMPILING) set (HAS_POST_2038_EXITCODE "0" CACHE STRING "Result from TRY_RUN" FORCE) set (HAS_POST_2038_EXITCODE__TRYRUN_OUTPUT "" CACHE STRING "Output from TRY_RUN" FORCE) + # CMake < 3.13 doesn't respect same-name variables as values for options. # FIXME: broken dependencies - set (USE_SNAPPY OFF) - set (ENABLE_SSL OFF) - set (ENABLE_PROTOBUF OFF) - set (ENABLE_PARQUET OFF) - set (ENABLE_READLINE OFF) - set (ENABLE_ICU OFF) - set (ENABLE_FASTOPS OFF) + # set (USE_SNAPPY OFF) + # set (ENABLE_SSL OFF) + # set (ENABLE_PROTOBUF OFF) + # set (ENABLE_PARQUET OFF) + # set (ENABLE_READLINE OFF) + # set (ENABLE_ICU OFF) + # set (ENABLE_FASTOPS OFF) message (STATUS "Cross-compiling for Darwin") else () From 409d9ceb3662288a6dbb9c1ce5f0e4c7b8377423 Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Wed, 2 Oct 2019 14:32:26 +0300 Subject: [PATCH 7/7] Disable warning for clang < 9 --- contrib/libcxx-cmake/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/libcxx-cmake/CMakeLists.txt b/contrib/libcxx-cmake/CMakeLists.txt index 54bbb5882e95..82d11e3e32d9 100644 --- a/contrib/libcxx-cmake/CMakeLists.txt +++ b/contrib/libcxx-cmake/CMakeLists.txt @@ -44,7 +44,7 @@ target_include_directories(cxx SYSTEM BEFORE PUBLIC $