Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] build: refactor static build process
@ 2020-06-22 18:16 HustonMmmavr
  2020-07-27 22:41 ` Alexander Turenko
  0 siblings, 1 reply; 6+ messages in thread
From: HustonMmmavr @ 2020-06-22 18:16 UTC (permalink / raw)
  To: tarantool-patches, yaroslav.dynnikov, avtikhon,
	alexander.turenko, sergeyb

From: Yaroslav Dynnikov <yaroslav.dynnikov@gmail.com>

Refactored static build process to use static-build/CMakeLists.txt
instead of Dockerfile.staticbuild (this allows to support static
build on macOS). Following third-party dependencies for static build
are installed via cmake `ExternalProject_Add`:
  - OpenSSL
  - Zlib
  - Ncurses
  - Readline
  - Unwind

* Added support static build for macOS
* Prevented linking tarantool binary with system libcurses.dylib at
  macOS by setting flag `CURSES_NEED_NCURSES` to TRUE at file
  cmake/FindReadline.cmake
* Fixed `CONFIGURE_COMMAND` while building bundled libcurl for staic
  build at file cmake/BuildLibCURL.cmake:
    - disable building shared libcurl libraries (by setting
      `--disable-shared` option)
    - disable hiding libcurl symbols (by setting
      `--disable-symbol-hiding` option)
    - prevent linking libcurl with system libz by settign
      `--with-zlib=${FOUND_ZLIB_ROOT_DIR}` option)
* Removed Dockerfile.staticbuild
* Added new gitlab.ci jobs to test new style static build:
  - static_build_no_deps_linux
  - static_build_no_deps_osx_15
* Removed static_docker_build gitlab.ci job

Closes #5095
---

Also this patch has it's own tests.

Branch: https://github.com/tarantool/tarantool/tree/rosik/refactor-static-build
Issue: https://github.com/tarantool/tarantool/issues/5095

@ChangeLog
* Refactor static build: use static-build/CMakeLists.txt
instead of Dockerfile.staticbuild

 .gitlab-ci.yml                                |  13 +-
 .travis.mk                                    |  53 +++-
 Dockerfile.staticbuild                        |  98 --------
 cmake/BuildLibCURL.cmake                      |  18 +-
 cmake/FindReadline.cmake                      |   2 +
 cmake/compiler.cmake                          |  19 +-
 cmake/os.cmake                                |   5 +-
 static-build/.gitignore                       |   4 +
 static-build/CMakeLists.txt                   | 228 ++++++++++++++++++
 static-build/README.md                        |  23 ++
 static-build/test/CheckDependencies.cmake     |  43 ++++
 static-build/test/static-build/box.lua        |   3 +
 .../test/static-build/curl-features.test.lua  |  67 +++++
 .../test/static-build/exports.test.lua        | 148 ++++++++++++
 static-build/test/static-build/suite.ini      |   6 +
 .../test/static-build/traceback.test.lua      |  15 ++
 static-build/test/test-run.py                 |   1 +
 17 files changed, 618 insertions(+), 128 deletions(-)
 delete mode 100644 Dockerfile.staticbuild
 create mode 100644 static-build/.gitignore
 create mode 100644 static-build/CMakeLists.txt
 create mode 100644 static-build/README.md
 create mode 100644 static-build/test/CheckDependencies.cmake
 create mode 100755 static-build/test/static-build/box.lua
 create mode 100755 static-build/test/static-build/curl-features.test.lua
 create mode 100755 static-build/test/static-build/exports.test.lua
 create mode 100644 static-build/test/static-build/suite.ini
 create mode 100755 static-build/test/static-build/traceback.test.lua
 create mode 120000 static-build/test/test-run.py

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 65b2fb126..d5697750b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -502,10 +502,15 @@ static_build:
   script:
     - ${GITLAB_MAKE} test_static_build
 
-static_docker_build:
+static_build_no_deps_linux:
+  <<: *docker_test_definition
+  script:
+    - ${GITLAB_MAKE} test_static_build_no_deps_linux
+
+static_build_no_deps_osx_15:
   stage: test
+  <<: *shell_cleanup_script
   tags:
-    - deploy_test
-  <<: *docker_cleanup_script
+    - osx_15
   script:
-    - ${GITLAB_MAKE} test_static_docker_build
+    - ${GITLAB_MAKE} test_static_build_no_deps_osx
diff --git a/.travis.mk b/.travis.mk
index 748321f26..a92f583c8 100644
--- a/.travis.mk
+++ b/.travis.mk
@@ -144,8 +144,12 @@ deps_debian_static:
 test_static_build: deps_debian_static
 	CMAKE_EXTRA_PARAMS=-DBUILD_STATIC=ON make -f .travis.mk test_debian_no_deps
 
-test_static_docker_build:
-	docker build --no-cache --network=host --build-arg RUN_TESTS=ON -f Dockerfile.staticbuild .
+# New static build
+
+test_static_build_no_deps_linux:
+	cd static-build && cmake . && make -j && ctest -V
+	cd test && /usr/bin/python test-run.py --force \
+		--builddir ${PWD}/static-build/tarantool-prefix/src/tarantool-build $(TEST_RUN_EXTRA_PARAMS)
 
 #######
 # OSX #
@@ -172,15 +176,16 @@ build_osx:
 	cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_WERROR=ON ${CMAKE_EXTRA_PARAMS}
 	make -j
 
-test_osx_no_deps: build_osx
-	# Limits: Increase the maximum number of open file descriptors on macOS:
-	#   Travis-ci needs the "ulimit -n <value>" call
-	#   Gitlab-ci needs the "launchctl limit maxfiles <value>" call
-	# Also gitlib-ci needs the password to change the limits, while
-	# travis-ci runs under root user. Limit setup must be in the same
-	# call as tests runs call.
-	# Tests: Temporary excluded replication/ suite with some tests
-	#        from other suites by issues #4357 and #4370
+
+# Limits: Increase the maximum number of open file descriptors on macOS:
+#   Travis-ci needs the "ulimit -n <value>" call
+#   Gitlab-ci needs the "launchctl limit maxfiles <value>" call
+# Also gitlib-ci needs the password to change the limits, while
+# travis-ci runs under root user. Limit setup must be in the same
+# call as tests runs call.
+# Tests: Temporary excluded replication/ suite with some tests
+#        from other suites by issues #4357 and #4370
+INIT_TEST_ENV_OSX=\
 	sudo -S launchctl limit maxfiles ${MAX_FILES} || : ; \
 		launchctl limit maxfiles || : ; \
 		ulimit -n ${MAX_FILES} || : ; \
@@ -189,11 +194,33 @@ test_osx_no_deps: build_osx
 		launchctl limit maxproc || : ; \
 		ulimit -u ${MAX_PROC} || : ; \
 		ulimit -u ; \
-		rm -rf /tmp/tnt ; \
-		cd test && ./test-run.py --vardir /tmp/tnt --force $(TEST_RUN_EXTRA_PARAMS)
+		rm -rf /tmp/tnt
+
+test_osx_no_deps: build_osx
+	# Init macOS test env
+	${INIT_TEST_ENV_OSX}; \
+	cd test && ./test-run.py --vardir /tmp/tnt --force $(TEST_RUN_EXTRA_PARAMS)
 
 test_osx: deps_osx test_osx_no_deps
 
+# Static macOS build
+
+STATIC_OSX_PKGS=autoconf automake libtool cmake file://$${PWD}/tools/brew_taps/tntpython2.rb
+base_deps_osx:
+	brew update || echo | /usr/bin/ruby -e \
+		"$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
+	brew install --force ${STATIC_OSX_PKGS} || brew upgrade ${STATIC_OSX_PKGS}
+	pip install --force-reinstall -r test-run/requirements.txt
+
+test_static_build_no_deps_osx: base_deps_osx
+	cd static-build && cmake . && make -j && ctest -V
+	# Init macOS test env
+	${INIT_TEST_ENV_OSX}; \
+	cd test && ./test-run.py --vardir /tmp/tnt \
+		--builddir ${PWD}/static-build/tarantool-prefix/src/tarantool-build \
+		--force $(TEST_RUN_EXTRA_PARAMS)
+
+
 ###########
 # FreeBSD #
 ###########
diff --git a/Dockerfile.staticbuild b/Dockerfile.staticbuild
deleted file mode 100644
index 253f2d5e9..000000000
--- a/Dockerfile.staticbuild
+++ /dev/null
@@ -1,98 +0,0 @@
-FROM centos:7
-
-RUN yum install -y epel-release
-RUN yum install -y yum install https://centos7.iuscommunity.org/ius-release.rpm
-
-RUN set -x \
-    && yum -y install \
-        libstdc++ \
-        libstdc++-static \
-        readline \
-        openssl \
-        lz4 \
-        binutils \
-        ncurses \
-        libgomp \
-        lua \
-        curl \
-        tar \
-        zip \
-        unzip \
-        libunwind \
-        zlib \
-    && yum -y install \
-        perl \
-        gcc-c++ \
-        cmake \
-        lz4-devel \
-        binutils-devel \
-        lua-devel \
-        make \
-        git \
-        autoconf \
-        automake \
-        libtool \
-        wget
-
-RUN yum -y install ncurses-static readline-static zlib-static pcre-static glibc-static
-
-RUN yum -y install python-devel python-pip
-
-RUN set -x && \
-    cd / && \
-    curl -O -L https://www.openssl.org/source/openssl-1.1.1f.tar.gz && \
-    tar -xvf openssl-1.1.1f.tar.gz && \
-    cd openssl-1.1.1f && \
-    ./config --libdir=lib && \
-    make -j && make install
-
-RUN set -x && \
-    cd / && \
-    curl -O -L https://github.com/unicode-org/icu/releases/download/release-62-1/icu4c-62_1-src.tgz && \
-    tar -xvf icu4c-62_1-src.tgz && \
-    cd icu/source && \
-    ./configure --with-data-packaging=static --enable-static --enable-shared && \
-    make -j && make install
-
-RUN set -x && \
-    cd / && \
-    curl -O -L http://download.savannah.nongnu.org/releases/libunwind/libunwind-1.3-rc1.tar.gz && \
-    tar -xvf libunwind-1.3-rc1.tar.gz && \
-    cd libunwind-1.3-rc1 && \
-    ./configure --enable-static --enable-shared && \
-    make -j && make install
-
-COPY . /tarantool
-
-WORKDIR /tarantool
-
-RUN set -x && \
-    git submodule init && \
-    git submodule update
-
-# Cleanup for 'build' directory added, because it purges all artefacts
-# produced for curl build, including the old configuration in build/curl
-RUN set -x && \
-    find . -name 'CMakeFiles' -type d -exec rm -rf {} + && \
-    find . -name 'CMakeCache.txt' -type f -delete && \
-    rm -rf build
-
-RUN pip install -r /tarantool/test-run/requirements.txt
-
-RUN set -x && \
-    cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-         -DENABLE_DIST:BOOL=ON \
-         -DBUILD_STATIC=ON \
-         -DOPENSSL_USE_STATIC_LIBS=ON \
-         -DOPENSSL_ROOT_DIR=/usr/local \
-         . && \
-    make -j && make install
-
-ARG RUN_TESTS
-RUN if [ -n "${RUN_TESTS}" ]; then \
-        set -x && \
-        cd test && \
-        /usr/bin/python test-run.py --force; \
-    fi
-
-ENTRYPOINT ["/bin/bash"]
diff --git a/cmake/BuildLibCURL.cmake b/cmake/BuildLibCURL.cmake
index 5f8b15a63..365c14284 100644
--- a/cmake/BuildLibCURL.cmake
+++ b/cmake/BuildLibCURL.cmake
@@ -4,15 +4,20 @@ macro(curl_build)
     set(LIBCURL_BINARY_DIR ${PROJECT_BINARY_DIR}/build/curl/work)
     set(LIBCURL_INSTALL_DIR ${PROJECT_BINARY_DIR}/build/curl/dest)
 
+    message(STATUS "Looking for zlib")
+    find_path(ZLIB_INCLUDE_DIR zlib.h)
+    message(STATUS "Looking for zlib.h - ${ZLIB_INCLUDE_DIR}")
     if (BUILD_STATIC)
-        set(LIBZ_LIB_NAME libz.a)
+        find_library(LIBZ_LIBRARY NAMES libz.a)
     else()
-        set(LIBZ_LIB_NAME z)
+        find_library(LIBZ_LIBRARY NAMES z)
     endif()
-    find_library(LIBZ_LIBRARY NAMES ${LIBZ_LIB_NAME})
-    if ("${LIBZ_LIBRARY}" STREQUAL "LIBZ_LIBRARY-NOTFOUND")
+    message(STATUS "Looking for libz - ${LIBZ_LIBRARY}")
+
+    if (NOT ZLIB_INCLUDE_DIR OR NOT LIBZ_LIBRARY)
         message(FATAL_ERROR "Unable to find zlib")
     endif()
+    get_filename_component(FOUND_ZLIB_ROOT_DIR ${ZLIB_INCLUDE_DIR} DIRECTORY)
 
     # Use the same OpenSSL library for libcurl as is used for
     # tarantool itself.
@@ -88,9 +93,10 @@ macro(curl_build)
 
                 --prefix <INSTALL_DIR>
                 --enable-static
-                --enable-shared
+                --disable-shared
+                --disable-symbol-hiding
 
-                --with-zlib
+                --with-zlib=${FOUND_ZLIB_ROOT_DIR}
                 ${LIBCURL_OPENSSL_OPT}
                 --with-ca-fallback
 
diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake
index c48bdcb3e..8422181d6 100644
--- a/cmake/FindReadline.cmake
+++ b/cmake/FindReadline.cmake
@@ -14,7 +14,9 @@ if(BUILD_STATIC)
     if (NOT CURSES_INFO_LIBRARY)
         set(CURSES_INFO_LIBRARY "")
     endif()
+    set(CURSES_NEED_NCURSES TRUE)
 endif()
+
 find_package(Curses)
 if(NOT CURSES_FOUND)
     find_package(Termcap)
diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake
index 5a1141ebd..14f1e1186 100644
--- a/cmake/compiler.cmake
+++ b/cmake/compiler.cmake
@@ -33,10 +33,6 @@ if (CMAKE_COMPILER_IS_GNUCC)
            Your GCC version is ${CMAKE_CXX_COMPILER_VERSION}, please update
                    ")
        endif()
-else()
-     if (BUILD_STATIC)
-           message(FATAL_ERROR "Static build is supported for GCC only")
-     endif()
 endif()
 
 #
@@ -120,8 +116,19 @@ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO
 
 unset(CC_DEBUG_OPT)
 
+message(STATUS "Looking for libunwind.h")
+find_path(UNWIND_INCLUDE_DIR libunwind.h)
+message(STATUS "Looking for libunwind.h - ${UNWIND_INCLUDE_DIR}")
+
+if (UNWIND_INCLUDE_DIR)
+    include_directories(${UNWIND_INCLUDE_DIR})
+endif()
+
+set(CMAKE_REQUIRED_INCLUDES ${UNWIND_INCLUDE_DIR})
 check_include_file(libunwind.h HAVE_LIBUNWIND_H)
-if(BUILD_STATIC)
+set(CMAKE_REQUIRED_INCLUDES "")
+
+if(BUILD_STATIC AND NOT TARGET_OS_DARWIN)
     set(UNWIND_LIB_NAME libunwind.a)
 else()
     set(UNWIND_LIB_NAME unwind)
@@ -185,7 +192,7 @@ if (ENABLE_BACKTRACE)
     find_package_message(UNWIND_LIBRARIES "Found unwind" "${UNWIND_LIBRARIES}")
 endif()
 
-if(BUILD_STATIC)
+if(BUILD_STATIC AND NOT TARGET_OS_DARWIN)
     # Static linking for c++ routines
     add_compile_flags("C;CXX" "-static-libstdc++")
 endif()
diff --git a/cmake/os.cmake b/cmake/os.cmake
index 905be61df..276a79b42 100644
--- a/cmake/os.cmake
+++ b/cmake/os.cmake
@@ -107,7 +107,10 @@ elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
 
     # Latest versions of Homebrew wont 'link --force' for libraries, that were
     # preinstalled in system. So we'll use this dirty hack
-    find_program(HOMEBREW_EXECUTABLE brew)
+
+    if (NOT BUILD_STATIC)
+        find_program(HOMEBREW_EXECUTABLE brew)
+    endif()
     if(EXISTS ${HOMEBREW_EXECUTABLE})
         execute_process(COMMAND ${HOMEBREW_EXECUTABLE} --prefix
                         OUTPUT_VARIABLE HOMEBREW_PREFIX
diff --git a/static-build/.gitignore b/static-build/.gitignore
new file mode 100644
index 000000000..c8028a870
--- /dev/null
+++ b/static-build/.gitignore
@@ -0,0 +1,4 @@
+*-prefix
+/Makefile
+/test/var
+/build
diff --git a/static-build/CMakeLists.txt b/static-build/CMakeLists.txt
new file mode 100644
index 000000000..86582af0a
--- /dev/null
+++ b/static-build/CMakeLists.txt
@@ -0,0 +1,228 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(tarantool-env NONE)
+
+include(ExternalProject)
+set(OPENSSL_VERSION 1.1.1f)
+set(ZLIB_VERSION 1.2.11)
+set(NCURSES_VERSION 6.2)
+set(READLINE_VERSION 8.0)
+set(UNWIND_VERSION 1.3-rc1)
+
+find_program(C_COMPILER gcc)
+find_program(CXX_COMPILER g++)
+set(CMAKE_C_COMPILER ${C_COMPILER})
+set(CMAKE_CXX_COMPILER ${CXX_COMPILER})
+
+#
+# OpenSSL
+#
+ExternalProject_Add(openssl
+    URL https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
+    CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
+        CXX=${CMAKE_CXX_COMPILER}
+        <SOURCE_DIR>/config
+        --prefix=<INSTALL_DIR>
+        --libdir=lib
+        no-shared
+    INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install_sw
+)
+
+#
+# ICU
+#
+ExternalProject_Add(icu
+    URL https://github.com/unicode-org/icu/releases/download/release-62-1/icu4c-62_1-src.tgz
+    CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
+        CXX=${CMAKE_CXX_COMPILER}
+        <SOURCE_DIR>/source/configure
+        --with-data-packaging=static
+        --prefix=<INSTALL_DIR>
+        --disable-shared
+        --enable-static
+)
+
+#
+# ZLIB
+#
+ExternalProject_Add(zlib
+    URL https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz
+    CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
+        <SOURCE_DIR>/configure
+        --prefix=<INSTALL_DIR>
+        --static
+    TEST_COMMAND ${CMAKE_MAKE_PROGRAM} check
+)
+
+#
+# Ncurses
+#
+ExternalProject_Add(ncurses
+    URL https://ftp.gnu.org/gnu/ncurses/ncurses-${NCURSES_VERSION}.tar.gz
+    CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
+        CXX=${CMAKE_CXX_COMPILER}
+        <SOURCE_DIR>/configure
+        --prefix=<INSTALL_DIR>
+)
+
+#
+# ReadLine
+#
+ExternalProject_Add(readline
+    URL https://ftp.gnu.org/gnu/readline/readline-${READLINE_VERSION}.tar.gz
+    CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
+        <SOURCE_DIR>/configure
+        --prefix=<INSTALL_DIR>
+        --disable-shared
+    # STEP_TARGETS download
+)
+
+#
+# ICONV
+#
+if (NOT APPLE)
+    # In linux iconv is embedded into glibc
+    # So we find system header and copy it locally
+    find_path(ICONV_INCLUDE_DIR iconv.h)
+    if(NOT ICONV_INCLUDE_DIR)
+        message(FATAL_ERROR "iconv include header not found")
+    endif()
+
+    set(ICONV_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/iconv-prefix")
+
+    add_custom_command(
+        OUTPUT "${ICONV_INSTALL_PREFIX}/include/iconv.h"
+        COMMAND ${CMAKE_COMMAND} -E make_directory
+            "${ICONV_INSTALL_PREFIX}/include"
+        COMMAND ${CMAKE_COMMAND} -E copy
+            "${ICONV_INCLUDE_DIR}/iconv.h"
+            "${ICONV_INSTALL_PREFIX}/include/iconv.h"
+    )
+    add_custom_target(iconv
+        DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/iconv-prefix/include/iconv.h"
+    )
+    set_target_properties(iconv
+        PROPERTIES _EP_INSTALL_DIR ${ICONV_INSTALL_PREFIX}
+    )
+else()
+    ExternalProject_Add(iconv
+        URL https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
+        CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
+            <SOURCE_DIR>/configure
+            --prefix=<INSTALL_DIR>
+            --disable-shared
+            --enable-static
+            --with-gnu-ld
+        STEP_TARGETS download
+    )
+endif()
+
+#
+# Unwind
+#
+if (APPLE)
+    # On macOS libunwind is a part of MacOSX.sdk
+    # So we need to find library and header and
+    # copy it locally
+    find_path(UNWIND_INCLUDE_DIR libunwind.h)
+    find_library(UNWIND_LIBRARY libunwind.dylib
+        PATH_SUFFIXES system
+    )
+
+    set(UNWIND_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/unwind-prefix")
+
+    set(UNWIND_DEPENDENCIES)
+
+    if (UNWIND_INCLUDE_DIR AND UNWIND_LIBRARY)
+        add_custom_command(
+            OUTPUT "${UNWIND_INSTALL_PREFIX}/include/unwind.h"
+            OUTPUT "${UNWIND_INSTALL_PREFIX}/include/libunwind.h"
+            COMMAND ${CMAKE_COMMAND} -E make_directory
+                "${UNWIND_INSTALL_PREFIX}/include"
+            COMMAND ${CMAKE_COMMAND} -E copy
+                "${UNWIND_INCLUDE_DIR}/libunwind.h"
+                "${UNWIND_INCLUDE_DIR}/unwind.h"
+                "${UNWIND_INSTALL_PREFIX}/include/"
+        )
+        add_custom_command(
+            OUTPUT "${UNWIND_INSTALL_PREFIX}/lib/libunwind.dylib"
+            COMMAND ${CMAKE_COMMAND} -E make_directory
+                "${UNWIND_INSTALL_PREFIX}/lib"
+            COMMAND ${CMAKE_COMMAND} -E copy
+                "${UNWIND_LIBRARY}"
+                "${UNWIND_INSTALL_PREFIX}/lib/"
+        )
+        set(UNWIND_DEPENDENCIES
+            ${UNWIND_DEPENDENCIES}
+            "${UNWIND_INSTALL_PREFIX}/lib/libunwind.dylib"
+            "${UNWIND_INSTALL_PREFIX}/include/libunwind.h"
+        )
+    else()
+        message(STATUS "Unwind not found")
+    endif()
+
+    add_custom_target(unwind DEPENDS ${UNWIND_DEPENDENCIES})
+    set_target_properties(unwind
+        PROPERTIES _EP_INSTALL_DIR ${UNWIND_INSTALL_PREFIX}
+    )
+else()
+    ExternalProject_Add(unwind
+        URL https://download.savannah.nongnu.org/releases/libunwind/libunwind-${UNWIND_VERSION}.tar.gz
+        CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
+            CXX=${CMAKE_CXX_COMPILER}
+            <SOURCE_DIR>/configure
+            --prefix=<INSTALL_DIR>
+            --disable-shared
+            --enable-static
+        STEP_TARGETS download
+    )
+endif()
+
+foreach(PROJ openssl icu zlib ncurses readline iconv unwind)
+    ExternalProject_Get_Property(${PROJ} install_dir)
+    set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}:${install_dir})
+    set(TARANTOOL_DEPENDS ${PROJ} ${TARANTOOL_DEPENDS})
+    message(STATUS "Add external project ${PROJ} in ${install_dir}")
+endforeach()
+
+ExternalProject_Add(tarantool
+    DEPENDS ${TARANTOOL_DEPENDS}
+    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..
+    LIST_SEPARATOR :
+    CMAKE_ARGS
+        # Override LOCALSTATEDIR to avoid cmake "special" cases:
+        # https://cmake.org/cmake/help/v3.4/module/GNUInstallDirs.html#special-cases
+        -DCMAKE_INSTALL_LOCALSTATEDIR=<INSTALL_DIR>/var
+        -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
+        -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
+        -DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=FALSE
+        -DOPENSSL_USE_STATIC_LIBS=TRUE
+        -DCMAKE_BUILD_TYPE=Debug
+        -DBUILD_STATIC=TRUE
+        -DENABLE_DIST=TRUE
+        -DENABLE_BACKTRACE=TRUE
+        -DPACKAGE:STRING=${PACKAGE_NAME}
+        -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+        -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
+        ${CMAKE_TARANTOOL_ARGS}
+    BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -j
+    STEP_TARGETS build
+)
+
+enable_testing()
+ExternalProject_Get_Property(tarantool binary_dir)
+SET(TARANTOOL_BINARY_DIR ${binary_dir})
+
+add_test(
+    NAME check-dependencies
+    COMMAND ${CMAKE_COMMAND}
+        -D FILE=${TARANTOOL_BINARY_DIR}/src/tarantool
+        -P CheckDependencies.cmake
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
+)
+
+add_test(
+    NAME test-run-static
+    COMMAND ./test-run.py --builddir ${TARANTOOL_BINARY_DIR}
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
+)
diff --git a/static-build/README.md b/static-build/README.md
new file mode 100644
index 000000000..29fe085c3
--- /dev/null
+++ b/static-build/README.md
@@ -0,0 +1,23 @@
+# Tarantool static build tooling
+
+These files help to prepare environment for building Tarantool
+statically. And builds it.
+
+## Prerequisites
+
+CentOS:
+
+```bash
+yum install -y \
+    git perl gcc cmake make gcc-c++ libstdc++-static autoconf automake libtool \
+    python-msgpack python-yaml python-argparse python-six python-gevent
+```
+
+
+### Usage
+
+```bash
+cmake .
+make -j
+ctest -V
+```
diff --git a/static-build/test/CheckDependencies.cmake b/static-build/test/CheckDependencies.cmake
new file mode 100644
index 000000000..49e91e7fa
--- /dev/null
+++ b/static-build/test/CheckDependencies.cmake
@@ -0,0 +1,43 @@
+## This is a cmake-based test, it checks that tarantool static binary
+# has no dependencies except allowed ones.
+
+include(GetPrerequisites)
+if(NOT FILE)
+    message(FATAL_ERROR "Usage: "
+        "${CMAKE_COMMAND} -DFILE=<FILENAME> -P CheckDependencies.cmake")
+elseif(NOT EXISTS ${FILE})
+    message(FATAL_ERROR "${FILE}: No such file")
+endif()
+
+get_prerequisites(${FILE} DEPENDENCIES 0 0 "" "")
+
+if (APPLE)
+    set(ALLOWLIST
+        libSystem
+        CoreFoundation
+        libc++
+    )
+elseif(UNIX)
+    set(ALLOWLIST
+        libdl
+        librt
+        libc
+        libm
+        libgcc_s
+        libpthread
+    )
+else()
+    message(FATAL_ERROR "Unknown platform")
+endif()
+
+foreach(DEPENDENCY_FILE ${DEPENDENCIES})
+    message("Dependency: ${DEPENDENCY_FILE}")
+endforeach()
+
+foreach(DEPENDENCY_FILE ${DEPENDENCIES})
+    get_filename_component(libname ${DEPENDENCY_FILE} NAME_WE)
+    list (FIND ALLOWLIST ${libname} _index)
+    if (_index EQUAL -1)
+        message(FATAL_ERROR "Blocklisted dependency: ${DEPENDENCY_FILE}")
+    endif()
+endforeach()
diff --git a/static-build/test/static-build/box.lua b/static-build/test/static-build/box.lua
new file mode 100755
index 000000000..bad8a9055
--- /dev/null
+++ b/static-build/test/static-build/box.lua
@@ -0,0 +1,3 @@
+#!/usr/bin/env tarantool
+
+require('console').listen(os.getenv('ADMIN'))
diff --git a/static-build/test/static-build/curl-features.test.lua b/static-build/test/static-build/curl-features.test.lua
new file mode 100755
index 000000000..57b1c4306
--- /dev/null
+++ b/static-build/test/static-build/curl-features.test.lua
@@ -0,0 +1,67 @@
+#!/usr/bin/env tarantool
+
+local tap = require('tap')
+local ffi = require('ffi')
+ffi.cdef([[
+    struct curl_version_info_data {
+        int age;                  /* see description below */
+        const char *version;      /* human readable string */
+        unsigned int version_num; /* numeric representation */
+        const char *host;         /* human readable string */
+        int features;             /* bitmask, see below */
+        char *ssl_version;        /* human readable string */
+        long ssl_version_num;     /* not used, always zero */
+        const char *libz_version; /* human readable string */
+        const char * const *protocols; /* protocols */
+
+        /* when 'age' is CURLVERSION_SECOND or higher, the members below exist */
+        const char *ares;         /* human readable string */
+        int ares_num;             /* number */
+
+        /* when 'age' is CURLVERSION_THIRD or higher, the members below exist */
+        const char *libidn;       /* human readable string */
+
+        /* when 'age' is CURLVERSION_FOURTH or higher (>= 7.16.1), the members
+           below exist */
+        int iconv_ver_num;       /* '_libiconv_version' if iconv support enabled */
+
+        const char *libssh_version; /* human readable string */
+
+        /* when 'age' is CURLVERSION_FIFTH or higher (>= 7.57.0), the members
+           below exist */
+        unsigned int brotli_ver_num; /* Numeric Brotli version
+                                        (MAJOR << 24) | (MINOR << 12) | PATCH */
+        const char *brotli_version; /* human readable string. */
+
+        /* when 'age' is CURLVERSION_SIXTH or higher (>= 7.66.0), the members
+           below exist */
+        unsigned int nghttp2_ver_num; /* Numeric nghttp2 version
+                                         (MAJOR << 16) | (MINOR << 8) | PATCH */
+        const char *nghttp2_version; /* human readable string. */
+
+        const char *quic_version;    /* human readable quic (+ HTTP/3) library +
+                                        version or NULL */
+
+        /* when 'age' is CURLVERSION_SEVENTH or higher (>= 7.70.0), the members
+           below exist */
+        const char *cainfo;          /* the built-in default CURLOPT_CAINFO, might
+                                        be NULL */
+        const char *capath;          /* the built-in default CURLOPT_CAPATH, might
+                                        be NULL */
+    };
+
+    struct curl_version_info_data *curl_version_info(int age);
+]])
+
+local info = ffi.C.curl_version_info(7)
+local test = tap.test('curl-features')
+test:plan(2)
+
+if test:ok(info.ssl_version ~= nil, 'Curl built with SSL support') then
+    test:diag('ssl_version: ' .. ffi.string(info.ssl_version))
+end
+if test:ok(info.libz_version ~= nil, 'Curl built with LIBZ') then
+    test:diag('libz_version: ' .. ffi.string(info.libz_version))
+end
+
+os.exit(test:check() and 0 or 1)
diff --git a/static-build/test/static-build/exports.test.lua b/static-build/test/static-build/exports.test.lua
new file mode 100755
index 000000000..63dc163a9
--- /dev/null
+++ b/static-build/test/static-build/exports.test.lua
@@ -0,0 +1,148 @@
+#!/usr/bin/env tarantool
+
+local tap = require('tap')
+local ffi = require('ffi')
+ffi.cdef([[
+    void *dlsym(void *handle, const char *symbol);
+]])
+
+local test = tap.test('exports')
+
+
+local RTLD_DEFAULT
+-- See `man 3 dlsym`:
+-- RTLD_DEFAULT
+--   Find  the  first occurrence of the desired symbol using the default
+--   shared object search order.  The search will include global symbols
+--   in the executable and its dependencies, as well as symbols in shared
+--   objects that were dynamically loaded with the RTLD_GLOBAL flag.
+if jit.os == "OSX" then
+    RTLD_DEFAULT = ffi.cast("void *", -2LL)
+else
+    RTLD_DEFAULT = ffi.cast("void *", 0LL)
+end
+
+local function check_symbol(sym)
+    test:ok(ffi.C.dlsym(RTLD_DEFAULT, sym) ~= nil, ('Symbol %q found'):format(sym))
+end
+
+local check_symbols = {
+    -- FFI
+
+    'guava',
+    'base64_decode',
+    'base64_encode',
+    'SHA1internal',
+    'random_bytes',
+    'fiber_time',
+    'ibuf_create',
+    'ibuf_destroy',
+    'port_destroy',
+    'csv_create',
+    'csv_destroy',
+    'title_get',
+    'title_update',
+    'tnt_iconv',
+    'tnt_iconv_open',
+    'tnt_iconv_close',
+    'exception_get_int',
+    'exception_get_string',
+
+    'tarantool_lua_ibuf',
+    'uuid_nil',
+    'tt_uuid_create',
+    'tt_uuid_str',
+    'tt_uuid_is_equal',
+    'tt_uuid_is_nil',
+    'tt_uuid_bswap',
+    'tt_uuid_from_string',
+    'log_level',
+    'log_format',
+    'uri_parse',
+    'uri_format',
+    'PMurHash32',
+    'PMurHash32_Process',
+    'PMurHash32_Result',
+    'crc32_calc',
+    'mp_encode_double',
+    'mp_encode_float',
+    'mp_encode_decimal',
+    'mp_decode_double',
+    'mp_decode_float',
+    'mp_decode_extl',
+    'mp_sizeof_decimal',
+    'decimal_unpack',
+
+    'log_type',
+    'say_set_log_level',
+    'say_logrotate',
+    'say_set_log_format',
+    'tarantool_uptime',
+    'tarantool_exit',
+    'log_pid',
+    'space_by_id',
+    'space_run_triggers',
+    'space_bsize',
+    'box_schema_version',
+
+    'crypto_EVP_MD_CTX_new',
+    'crypto_EVP_MD_CTX_free',
+    'crypto_HMAC_CTX_new',
+    'crypto_HMAC_CTX_free',
+    'crypto_stream_new',
+    'crypto_stream_begin',
+    'crypto_stream_append',
+    'crypto_stream_commit',
+    'crypto_stream_delete',
+
+    -- Module API
+
+    '_say',
+    'swim_cfg',
+    'swim_quit',
+    'fiber_new',
+    'fiber_cancel',
+    'coio_wait',
+    'coio_close',
+    'coio_call',
+    'coio_getaddrinfo',
+    'luaT_call',
+    'box_txn',
+    'box_select',
+    'clock_realtime',
+    'string_strip_helper',
+
+    -- Lua / LuaJIT
+
+    'lua_newstate',
+    'lua_close',
+    'luaL_loadstring',
+    'luaJIT_profile_start',
+    'luaJIT_profile_stop',
+    'luaJIT_profile_dumpstack',
+
+    'ERR_error_string',
+    'ERR_get_error',
+
+    'EVP_get_digestbyname',
+    'EVP_get_cipherbyname',
+    'EVP_CIPHER_CTX_new',
+    'EVP_CIPHER_CTX_free',
+    'EVP_CIPHER_block_size',
+    'HMAC_Init_ex',
+    'HMAC_Update',
+    'HMAC_Final',
+
+    'ZSTD_compress',
+    'ZSTD_decompress',
+    'ZSTD_free',
+    'ZSTD_malloc',
+    'ZSTD_versionString',
+}
+
+test:plan(#check_symbols)
+for _, sym in ipairs(check_symbols) do
+    check_symbol(sym)
+end
+
+os.exit(test:check() and 0 or 1)
diff --git a/static-build/test/static-build/suite.ini b/static-build/test/static-build/suite.ini
new file mode 100644
index 000000000..4da3d5d2f
--- /dev/null
+++ b/static-build/test/static-build/suite.ini
@@ -0,0 +1,6 @@
+[default]
+core = app
+description = Static build tests
+script = box.lua
+is_parallel = True
+use_unix_sockets_iproto = True
diff --git a/static-build/test/static-build/traceback.test.lua b/static-build/test/static-build/traceback.test.lua
new file mode 100755
index 000000000..32e1ed8b5
--- /dev/null
+++ b/static-build/test/static-build/traceback.test.lua
@@ -0,0 +1,15 @@
+#!/usr/bin/env tarantool
+
+local tap = require('tap')
+local fiber = require('fiber')
+
+local test = tap.test('traceback')
+test:plan(1)
+
+local info = fiber.info()[fiber.id()]
+test:ok(info.backtrace ~= nil, 'fiber.info() has backtrace')
+for _, l in pairs(info.backtrace or {}) do
+    test:diag('%s: %s', next(l))
+end
+
+os.exit(test:check() and 0 or 1)
diff --git a/static-build/test/test-run.py b/static-build/test/test-run.py
new file mode 120000
index 000000000..02187cdc5
--- /dev/null
+++ b/static-build/test/test-run.py
@@ -0,0 +1 @@
+../../test-run/test-run.py
\ No newline at end of file
-- 
2.26.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Tarantool-patches] [PATCH] build: refactor static build process
  2020-06-22 18:16 [Tarantool-patches] [PATCH] build: refactor static build process HustonMmmavr
@ 2020-07-27 22:41 ` Alexander Turenko
  2020-08-05 17:08   ` Mavr Huston
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Turenko @ 2020-07-27 22:41 UTC (permalink / raw)
  To: HustonMmmavr; +Cc: tarantool-patches, yaroslav.dynnikov

It is not review in fact: the patch is not so small and I need to start
several discussions here and there to dive into the changes deeply and
finally provide thorough review.

So, please consider the comments below not as 'you should do X and Y to
pass the review', but as questions from a curious person.

WBR, Alexander Turenko.

> Refactored static build process to use static-build/CMakeLists.txt
> instead of Dockerfile.staticbuild (this allows to support static
> build on macOS). Following third-party dependencies for static build
> are installed via cmake `ExternalProject_Add`:
>   - OpenSSL
>   - Zlib
>   - Ncurses
>   - Readline
>   - Unwind

How about libicu? I guess it is not part of Mac OS system itself.

> 
> * Added support static build for macOS
> * Prevented linking tarantool binary with system libcurses.dylib at
>   macOS by setting flag `CURSES_NEED_NCURSES` to TRUE at file
>   cmake/FindReadline.cmake

First, it is set for both Linux and Max OS without any comment in the
code.

Second, it is unclear what is bad with linking against libcurses.dylib.
The only way to find a reason is to try and got some fail. Please,
clarify it.

> * Fixed `CONFIGURE_COMMAND` while building bundled libcurl for staic
>   build at file cmake/BuildLibCURL.cmake:

Typo: staic.

>     - disable building shared libcurl libraries (by setting
>       `--disable-shared` option)

Is it necessary? I had a plan to use .so to grab a symbol list to
export.

> * Added new gitlab.ci jobs to test new style static build:
>   - static_build_no_deps_linux
>   - static_build_no_deps_osx_15

'no_deps' is suffix for make targets, which do not depend on
'deps_debian' or 'deps_buster_clang_8'. A CI job may either use a docker
image, where all those dependencies are already installed, or install
dependencies each time (which is slower). In any way there is no reason
to name a CI job as 'no_deps'.

Can we add a Linux/clang job to better understand what is Mac OS
specific problem and what is related to clang itself?

> +# New static build

Nit: I'll become the only static build after your patch, so I don't see
a reason to highlight the fact the it is the new one.

> +test_static_build_no_deps_linux:
> +	cd static-build && cmake . && make -j && ctest -V
> +	cd test && /usr/bin/python test-run.py --force \
> +		--builddir ${PWD}/static-build/tarantool-prefix/src/tarantool-build $(TEST_RUN_EXTRA_PARAMS)

To be honest, I don't find from where tarantool-prefix appears. Some
ExternalProject_Add() default?

BTW, I personally prefer to have separate workdir and destdir: not
workdir inside destdir (example: emerge in Gentoo organizes build files
in the similar way). And I also feel the name 'dest' (borrowed from
DESTDIR, which is usual GNU Make variable name) more descriptive, then
'prefix'. 'prefix' is how you want to use it ('to prefix other
variables'), but 'destination directory' is what the directory is. You
can see how everything is organized in cmake/BuildLibCURL.cmake.

(It is just my preferences, but maybe it'll look meaningful for you too.
I don't insist.)

> +test_osx_no_deps: build_osx
> +	# Init macOS test env
> +	${INIT_TEST_ENV_OSX}; \

The comment just repeats the variable name. It is useless.

> +	# Init macOS test env
> +	${INIT_TEST_ENV_OSX}; \

Same as above, the comment just repeats the variable name.

>      if (BUILD_STATIC)
> -        set(LIBZ_LIB_NAME libz.a)
> +        find_library(LIBZ_LIBRARY NAMES libz.a)
>      else()
> -        set(LIBZ_LIB_NAME z)
> +        find_library(LIBZ_LIBRARY NAMES z)
>      endif()
> -    find_library(LIBZ_LIBRARY NAMES ${LIBZ_LIB_NAME})

The code block does exactly same before and after the change: so there
is no need to change it.

> +if(BUILD_STATIC AND NOT TARGET_OS_DARWIN)
>      set(UNWIND_LIB_NAME libunwind.a)
>  else()
>      set(UNWIND_LIB_NAME unwind)

A comment (like in static-build/CMakeLists.txt) or some link to the
existing comment should be here, it is not obvious why we should link
against libunwind dynamically on Mac OS.

> -if(BUILD_STATIC)
> +if(BUILD_STATIC AND NOT TARGET_OS_DARWIN)
>      # Static linking for c++ routines
>      add_compile_flags("C;CXX" "-static-libstdc++")
>  endif()

There should a clear reason for this change (say, it does not work with
symptoms X and Y) and a reason why it is okay on Mac OS (say, this
runtime exist on any Mac OS system, even without developer tool, and ABI
is stable). Please, comment those moments. Otherwise, if we'll want to
change it in a future, we'll not know what may become broken and what
need to be verified.

> +find_program(C_COMPILER gcc)
> +find_program(CXX_COMPILER g++)
> +set(CMAKE_C_COMPILER ${C_COMPILER})
> +set(CMAKE_CXX_COMPILER ${CXX_COMPILER})

It is intersting. Do you want to use gcc even on Mac OS? Why don't just
use a default system compiler?

> +#
> +# ICONV
> +#
> +if (NOT APPLE)

Nit: It is easier to read a condition

 | if (NOT <..FOO..>)
 |     <..AAA..>
 | else()
 |     <..BBB..>
 | endif()

when it is written as:

 | if (<..FOO..>)
 |     <..BBB..>
 | else()
 |     <..AAA..>
 | endif()

> +#
> +# Unwind
> +#
> +if (APPLE)
> +    # On macOS libunwind is a part of MacOSX.sdk
> +    # So we need to find library and header and
> +    # copy it locally

Is this SDK always available on a target system? Or it assumes some
developments tools to be installed? I would clarify it in the README, if
so.

> +    add_custom_target(unwind DEPENDS ${UNWIND_DEPENDENCIES})
> +    set_target_properties(unwind
> +        PROPERTIES _EP_INSTALL_DIR ${UNWIND_INSTALL_PREFIX}
> +    )

What is _EP_INSTALL_DIR? I don't see anything about in in the CMake
documentation ([1]). If it is uses some undocumented CMake feature, then
there should be a comment.

[1]: https://cmake.org/cmake/help/latest/manual/cmake-properties.7.html

> +ExternalProject_Add(tarantool
> +    DEPENDS ${TARANTOOL_DEPENDS}
> +    SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..
> +    LIST_SEPARATOR :
> +    CMAKE_ARGS
> +        # Override LOCALSTATEDIR to avoid cmake "special" cases:
> +        # https://cmake.org/cmake/help/v3.4/module/GNUInstallDirs.html#special-cases
> +        -DCMAKE_INSTALL_LOCALSTATEDIR=<INSTALL_DIR>/var

To be honest, I don't understand what will going wrong if we'll not set
the variable.

> +        -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
> +        -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
> +        -DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=FALSE

So find_*() will search only in ${CMAKE_PREFIX_PATH} directories? Now I
got why you need to copy system's libunwind.dylib into a local
directory.

It gives you more control what parts of a system may be linked
dynamically into the executable, so I think it is good approach.

> +        -DOPENSSL_USE_STATIC_LIBS=TRUE
> +        -DCMAKE_BUILD_TYPE=Debug

Maybe allow to redefine those options? However it seems it is possible
using -DCMAKE_TARANTOOL_ARGS=<...>. I think it would be more convenient to
accept just, say, -DCMAKE_BUILD_TYPE=RelWithDebInfo. Either way you'll
choose, please, document it is static-build/README.md.

> +        -DBUILD_STATIC=TRUE
> +        -DENABLE_DIST=TRUE
> +        -DENABLE_BACKTRACE=TRUE
> +        -DPACKAGE:STRING=${PACKAGE_NAME}

Nit: Other variables are set without a type.

> +        -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
> +        -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
> +        ${CMAKE_TARANTOOL_ARGS}
> +    BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -j

AFAIR, ${MAKE} should keep -j value (it is used in
cmake/BuildLibCURL.cmake). Does not ${CMAKE_MAKE_PROGRAM} do?

> +## Prerequisites
> +
> +CentOS:
> +
> +```bash
> +yum install -y \
> +    git perl gcc cmake make gcc-c++ libstdc++-static autoconf automake libtool \
> +    python-msgpack python-yaml python-argparse python-six python-gevent
> +```
> +

I would mention Mac OS requirements. Even if it is 'any Mac OS system',
it is great thing to highlight.

> +local check_symbols = {
> +    -- FFI
> +
> +    'guava',
> +    'base64_decode',
> +    'base64_encode',
> +    'SHA1internal',
> +    'random_bytes',
> +    'fiber_time',
> +    'ibuf_create',
> +    'ibuf_destroy',
> +    'port_destroy',
> +    'csv_create',
> +    'csv_destroy',
> +    'title_get',
> +    'title_update',
> +    'tnt_iconv',
> +    'tnt_iconv_open',
> +    'tnt_iconv_close',
> +    'exception_get_int',
> +    'exception_get_string',
> +
> +    'tarantool_lua_ibuf',
> +    'uuid_nil',
> +    'tt_uuid_create',
> +    'tt_uuid_str',
> +    'tt_uuid_is_equal',
> +    'tt_uuid_is_nil',
> +    'tt_uuid_bswap',
> +    'tt_uuid_from_string',
> +    'log_level',
> +    'log_format',
> +    'uri_parse',
> +    'uri_format',
> +    'PMurHash32',
> +    'PMurHash32_Process',
> +    'PMurHash32_Result',
> +    'crc32_calc',
> +    'mp_encode_double',
> +    'mp_encode_float',
> +    'mp_encode_decimal',
> +    'mp_decode_double',
> +    'mp_decode_float',
> +    'mp_decode_extl',
> +    'mp_sizeof_decimal',
> +    'decimal_unpack',
> +
> +    'log_type',
> +    'say_set_log_level',
> +    'say_logrotate',
> +    'say_set_log_format',
> +    'tarantool_uptime',
> +    'tarantool_exit',
> +    'log_pid',
> +    'space_by_id',
> +    'space_run_triggers',
> +    'space_bsize',
> +    'box_schema_version',
> +
> +    'crypto_EVP_MD_CTX_new',
> +    'crypto_EVP_MD_CTX_free',
> +    'crypto_HMAC_CTX_new',
> +    'crypto_HMAC_CTX_free',
> +    'crypto_stream_new',
> +    'crypto_stream_begin',
> +    'crypto_stream_append',
> +    'crypto_stream_commit',
> +    'crypto_stream_delete',
> +
> +    -- Module API
> +
> +    '_say',
> +    'swim_cfg',
> +    'swim_quit',
> +    'fiber_new',
> +    'fiber_cancel',
> +    'coio_wait',
> +    'coio_close',
> +    'coio_call',
> +    'coio_getaddrinfo',
> +    'luaT_call',
> +    'box_txn',
> +    'box_select',
> +    'clock_realtime',
> +    'string_strip_helper',
> +
> +    -- Lua / LuaJIT
> +
> +    'lua_newstate',
> +    'lua_close',
> +    'luaL_loadstring',
> +    'luaJIT_profile_start',
> +    'luaJIT_profile_stop',
> +    'luaJIT_profile_dumpstack',
> +
> +    'ERR_error_string',
> +    'ERR_get_error',
> +
> +    'EVP_get_digestbyname',
> +    'EVP_get_cipherbyname',
> +    'EVP_CIPHER_CTX_new',
> +    'EVP_CIPHER_CTX_free',
> +    'EVP_CIPHER_block_size',
> +    'HMAC_Init_ex',
> +    'HMAC_Update',
> +    'HMAC_Final',
> +
> +    'ZSTD_compress',
> +    'ZSTD_decompress',
> +    'ZSTD_free',
> +    'ZSTD_malloc',
> +    'ZSTD_versionString',
> +}

The list is based on src/exports.h (and old extra/exports)? Or it is
requirements of some set of external modules? Please, clarify.

> diff --git a/static-build/test/static-build/suite.ini b/static-build/test/static-build/suite.ini
> new file mode 100644
> index 000000000..4da3d5d2f
> --- /dev/null
> +++ b/static-build/test/static-build/suite.ini
> @@ -0,0 +1,6 @@
> +[default]
> +core = app
> +description = Static build tests
> +script = box.lua
> +is_parallel = True
> +use_unix_sockets_iproto = True

'use_unix_sockets_iproto' will not affect anything, because of two
reasons:

- It does not work for 'core = app' test (see [1]). Just was not
  implemented for them. I don't recommend to enable it for 'core = app'
  test suites prematurely, because a test-run update may break your
  tests in the case.
- You don't use 'LISTEN' environment variable.

But you may be interested in use_unix_sockets option (but take care to
max usix socket path limit).

[1]: https://github.com/tarantool/test-run/issues/141#issuecomment-618401440

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Tarantool-patches] [PATCH] build: refactor static build process
  2020-07-27 22:41 ` Alexander Turenko
@ 2020-08-05 17:08   ` Mavr Huston
  2020-08-06 13:32     ` Alexandr Barulev
  2020-08-25 13:21     ` Alexander Turenko
  0 siblings, 2 replies; 6+ messages in thread
From: Mavr Huston @ 2020-08-05 17:08 UTC (permalink / raw)
  To: Alexander Turenko; +Cc: tarantool-patches, yaroslav.dynnikov

[-- Attachment #1: Type: text/plain, Size: 13910 bytes --]

Hi, thanks for the review!

libicu installs as ExternalProject_Add too, its missed in commit message;

Problem with curses and ncurses was on macOS and linux, because libcurses
is an entire copy of libncurses, and tarantool links with system
libcurses instead of libncurses installed as tarantool dependency, but
module FindCurses.cmkae provides workaround for this problem -
CURSES_NEED_NCURSES flag.- to use ncurses instead of curses. (i will fix
this part at commit message)

About disable-shred flag, used at libcurl building - we want to link only
with
static libraries, so we prevent creating unused .so.

I've renamed static_build_no_deps_* jobs after review to
static_build_cmake_*

Also about such path tarantool-prefix/* - it's a cmake ExternalProject_Add()
default path (i've also added comment at .travis.mk)

Useless comments "Init macOS test env" deleted.

>      if (BUILD_STATIC)
> -        set(LIBZ_LIB_NAME libz.a)
> +        find_library(LIBZ_LIBRARY NAMES libz.a)
>      else()
> -        set(LIBZ_LIB_NAME z)
> +        find_library(LIBZ_LIBRARY NAMES z)
>      endif()
> -    find_library(LIBZ_LIBRARY NAMES ${LIBZ_LIB_NAME})
Here we simplified code, by deleting useless variable.

I've added commentaries to cmake/compiler.cmake about libunwind on macOS
and about ignoring flag -static-libstdc++ on macOS

I've fixed static-build for using system compiler:  gcc/g++ on linux
and clang/clang++ on macOS

I've refactored IF (NOT APPLE) condition to IF (APPLE) at
static-build/CMakeLists.txt

I've mentioned macOS dependencies at static-build/README.md xcode-tools and
others, also I've added example with CMAKE_TARANTOOL_ARGS.

Added commentaries about _EP_INSTALL_DIR at static-build/CMakeLists.txt

Also deleted unused use_unix_sockets_iproto = True

Also deleted curl-features.test.lua, because after rebase on master it
fails,
due to missing curl_version_info symbol at tarantool binary. This symbol
lost
after #807c7fa584f21ee955b2a14623d70f7510a3650d (build: update curl
submodule
to 7.71.1 version )


After pass the review I'll squash this changes to base commit and update
commit
message.

Here is a diff of changes:
=====================================

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5ec5dd9b9..c9aef3dc7 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -534,14 +534,14 @@ static_build:
   script:
     - ${GITLAB_MAKE} test_static_build

-static_build_no_deps_linux:
+static_build_cmake_linux:
   <<: *docker_test_definition
   script:
-    - ${GITLAB_MAKE} test_static_build_no_deps_linux
+    - ${GITLAB_MAKE} test_static_build_cmake_linux

-static_build_no_deps_osx_15:
+static_build_cmake_osx_15:
   stage: test
   tags:
     - osx_15
   script:
-    - ${GITLAB_MAKE} test_static_build_no_deps_osx
+    - ${GITLAB_MAKE} test_static_build_cmake_osx
diff --git a/.travis.mk b/.travis.mk
index 64862348f..482672429 100644
--- a/.travis.mk
+++ b/.travis.mk
@@ -149,8 +149,8 @@ test_static_build: deps_debian_static
  CMAKE_EXTRA_PARAMS=-DBUILD_STATIC=ON make -f .travis.mk
test_debian_no_deps

 # New static build
-
-test_static_build_no_deps_linux:
+# builddir used in this target - is a default build path from cmake
ExternalProject_Add()
+test_static_build_cmake_linux:
  cd static-build && cmake . && make -j && ctest -V
  cd test && /usr/bin/python test-run.py --force \
  --builddir ${PWD}/static-build/tarantool-prefix/src/tarantool-build
$(TEST_RUN_EXTRA_PARAMS)
@@ -218,7 +218,6 @@ INIT_TEST_ENV_OSX=\
  rm -rf /tmp/tnt

 test_osx_no_deps: build_osx
- # Init macOS test env
  ${INIT_TEST_ENV_OSX}; \
  cd test && ./test-run.py --vardir /tmp/tnt --force
$(TEST_RUN_EXTRA_PARAMS)

@@ -233,9 +232,9 @@ base_deps_osx:
  brew install --force ${STATIC_OSX_PKGS} || brew upgrade ${STATIC_OSX_PKGS}
  pip install --force-reinstall -r test-run/requirements.txt

-test_static_build_no_deps_osx: base_deps_osx
+# builddir used in this target - is a default build path from cmake
ExternalProject_Add()
+test_static_build_cmake_osx: base_deps_osx
  cd static-build && cmake . && make -j && ctest -V
- # Init macOS test env
  ${INIT_TEST_ENV_OSX}; \
  cd test && ./test-run.py --vardir /tmp/tnt \
  --builddir ${PWD}/static-build/tarantool-prefix/src/tarantool-build \
diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake
index 8422181d6..afe480679 100644
--- a/cmake/FindReadline.cmake
+++ b/cmake/FindReadline.cmake
@@ -14,6 +14,14 @@ if(BUILD_STATIC)
     if (NOT CURSES_INFO_LIBRARY)
         set(CURSES_INFO_LIBRARY "")
     endif()
+
+    # From Modules/FindCurses.cmake:
+    # Set ``CURSES_NEED_NCURSES`` to ``TRUE`` before the
+    # ``find_package(Curses)`` call if NCurses functionality is required.
+    # This flag is set for linking with required library (installed
+    # via static-build/CMakeLists.txt). If this variable won't be set
+    # then tarantool binary links with system library curses which is an
+    # entire copy of ncurses
     set(CURSES_NEED_NCURSES TRUE)
 endif()

diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake
index 14f1e1186..db2ae6227 100644
--- a/cmake/compiler.cmake
+++ b/cmake/compiler.cmake
@@ -131,6 +131,8 @@ set(CMAKE_REQUIRED_INCLUDES "")
 if(BUILD_STATIC AND NOT TARGET_OS_DARWIN)
     set(UNWIND_LIB_NAME libunwind.a)
 else()
+    # libunwind can't be compiled on macOS.
+    # But there exists libunwind.dylib as a part of MacOSSDK
     set(UNWIND_LIB_NAME unwind)
 endif()
 find_library(UNWIND_LIBRARY PATH_SUFFIXES system NAMES ${UNWIND_LIB_NAME})
@@ -192,6 +194,9 @@ if (ENABLE_BACKTRACE)
     find_package_message(UNWIND_LIBRARIES "Found unwind"
"${UNWIND_LIBRARIES}")
 endif()

+# On macOS there is no '-static-libstdc++' flag and it's use will
+# raise following error:
+# error: argument unused during compilation: '-static-libstdc++'
 if(BUILD_STATIC AND NOT TARGET_OS_DARWIN)
     # Static linking for c++ routines
     add_compile_flags("C;CXX" "-static-libstdc++")
diff --git a/static-build/CMakeLists.txt b/static-build/CMakeLists.txt
index 86582af0a..53ceb609c 100644
--- a/static-build/CMakeLists.txt
+++ b/static-build/CMakeLists.txt
@@ -9,11 +9,18 @@ set(NCURSES_VERSION 6.2)
 set(READLINE_VERSION 8.0)
 set(UNWIND_VERSION 1.3-rc1)

-find_program(C_COMPILER gcc)
-find_program(CXX_COMPILER g++)
+if (APPLE)
+    find_program(C_COMPILER clang)
+    find_program(CXX_COMPILER clang++)
+else()
+    find_program(C_COMPILER gcc)
+    find_program(CXX_COMPILER g++)
+endif()
 set(CMAKE_C_COMPILER ${C_COMPILER})
 set(CMAKE_CXX_COMPILER ${CXX_COMPILER})

+# Install all libraries required by tarantool at current build dir
+
 #
 # OpenSSL
 #
@@ -80,7 +87,18 @@ ExternalProject_Add(readline
 #
 # ICONV
 #
-if (NOT APPLE)
+if (APPLE)
+    ExternalProject_Add(iconv
+        URL https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
+        CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
+            <SOURCE_DIR>/configure
+            --prefix=<INSTALL_DIR>
+            --disable-shared
+            --enable-static
+            --with-gnu-ld
+        STEP_TARGETS download
+    )
+else()
     # In linux iconv is embedded into glibc
     # So we find system header and copy it locally
     find_path(ICONV_INCLUDE_DIR iconv.h)
@@ -101,20 +119,11 @@ if (NOT APPLE)
     add_custom_target(iconv
         DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/iconv-prefix/include/iconv.h"
     )
+    # This is a hack for further getting install directory of library
+    # by ExternalProject_Get_Property
     set_target_properties(iconv
         PROPERTIES _EP_INSTALL_DIR ${ICONV_INSTALL_PREFIX}
     )
-else()
-    ExternalProject_Add(iconv
-        URL https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
-        CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
-            <SOURCE_DIR>/configure
-            --prefix=<INSTALL_DIR>
-            --disable-shared
-            --enable-static
-            --with-gnu-ld
-        STEP_TARGETS download
-    )
 endif()

 #
@@ -162,6 +171,8 @@ if (APPLE)
     endif()

     add_custom_target(unwind DEPENDS ${UNWIND_DEPENDENCIES})
+    # This is a hack for further getting install directory of library
+    # by ExternalProject_Get_Property
     set_target_properties(unwind
         PROPERTIES _EP_INSTALL_DIR ${UNWIND_INSTALL_PREFIX}
     )
@@ -178,6 +189,8 @@ else()
     )
 endif()

+# Get install directories of builded libraries for building
+# tarantool with custon CMAKE_PREFIX_PATH
 foreach(PROJ openssl icu zlib ncurses readline iconv unwind)
     ExternalProject_Get_Property(${PROJ} install_dir)
     set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}:${install_dir})
@@ -197,16 +210,14 @@ ExternalProject_Add(tarantool
         -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
         -DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=FALSE
         -DOPENSSL_USE_STATIC_LIBS=TRUE
-        -DCMAKE_BUILD_TYPE=Debug
         -DBUILD_STATIC=TRUE
         -DENABLE_DIST=TRUE
         -DENABLE_BACKTRACE=TRUE
-        -DPACKAGE:STRING=${PACKAGE_NAME}
         -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
         -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
         ${CMAKE_TARANTOOL_ARGS}
-    BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -j
     STEP_TARGETS build
+    BUILD_COMMAND $(MAKE)
 )

 enable_testing()
diff --git a/static-build/README.md b/static-build/README.md
index 29fe085c3..0019e963f 100644
--- a/static-build/README.md
+++ b/static-build/README.md
@@ -13,6 +13,24 @@ yum install -y \
     python-msgpack python-yaml python-argparse python-six python-gevent
 ```

+MacOS:
+
+Before you start please install default Xcode Tools by Apple:
+
+```
+sudo xcode-select --install
+sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
+```
+
+Install brew using command from
+[Homebrew repository instructions](https://github.com/Homebrew/inst)
+
+After that run next script:
+
+```bash
+  brew install autoconf automake libtool cmake
file://$${PWD}/tools/brew_taps/tntpython2.rbs
+  pip install --force-reinstall -r test-run/requirements.txt
+```

 ### Usage

@@ -21,3 +39,20 @@ cmake .
 make -j
 ctest -V
 ```
+
+## Customize your build
+
+If you want to customise build, you need to set `CMAKE_TARANTOOL_ARGS`
variable
+
+### Usage
+
+There is three types of `CMAKE_BUILD_TYPE`:
+* Debug - default
+* Release
+* RelWithDebInfo
+
+And you want to build tarantool with RelWithDebInfo:
+
+```bash
+cmake -DCMAKE_TARANTOOL_ARGS="-DCMAKE_BUILD_TYPE=RelWithDebInfo" .
+```
diff --git a/static-build/test/static-build/curl-features.test.lua
b/static-build/test/static-build/curl-features.test.lua
deleted file mode 100755
index 57b1c4306..000000000
--- a/static-build/test/static-build/curl-features.test.lua
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/env tarantool
-
-local tap = require('tap')
-local ffi = require('ffi')
-ffi.cdef([[
-    struct curl_version_info_data {
-        int age;                  /* see description below */
-        const char *version;      /* human readable string */
-        unsigned int version_num; /* numeric representation */
-        const char *host;         /* human readable string */
-        int features;             /* bitmask, see below */
-        char *ssl_version;        /* human readable string */
-        long ssl_version_num;     /* not used, always zero */
-        const char *libz_version; /* human readable string */
-        const char * const *protocols; /* protocols */
-
-        /* when 'age' is CURLVERSION_SECOND or higher, the members below
exist */
-        const char *ares;         /* human readable string */
-        int ares_num;             /* number */
-
-        /* when 'age' is CURLVERSION_THIRD or higher, the members below
exist */
-        const char *libidn;       /* human readable string */
-
-        /* when 'age' is CURLVERSION_FOURTH or higher (>= 7.16.1), the
members
-           below exist */
-        int iconv_ver_num;       /* '_libiconv_version' if iconv support
enabled */
-
-        const char *libssh_version; /* human readable string */
-
-        /* when 'age' is CURLVERSION_FIFTH or higher (>= 7.57.0), the
members
-           below exist */
-        unsigned int brotli_ver_num; /* Numeric Brotli version
-                                        (MAJOR << 24) | (MINOR << 12) |
PATCH */
-        const char *brotli_version; /* human readable string. */
-
-        /* when 'age' is CURLVERSION_SIXTH or higher (>= 7.66.0), the
members
-           below exist */
-        unsigned int nghttp2_ver_num; /* Numeric nghttp2 version
-                                         (MAJOR << 16) | (MINOR << 8) |
PATCH */
-        const char *nghttp2_version; /* human readable string. */
-
-        const char *quic_version;    /* human readable quic (+ HTTP/3)
library +
-                                        version or NULL */
-
-        /* when 'age' is CURLVERSION_SEVENTH or higher (>= 7.70.0), the
members
-           below exist */
-        const char *cainfo;          /* the built-in default
CURLOPT_CAINFO, might
-                                        be NULL */
-        const char *capath;          /* the built-in default
CURLOPT_CAPATH, might
-                                        be NULL */
-    };
-
-    struct curl_version_info_data *curl_version_info(int age);
-]])
-
-local info = ffi.C.curl_version_info(7)
-local test = tap.test('curl-features')
-test:plan(2)
-
-if test:ok(info.ssl_version ~= nil, 'Curl built with SSL support') then
-    test:diag('ssl_version: ' .. ffi.string(info.ssl_version))
-end
-if test:ok(info.libz_version ~= nil, 'Curl built with LIBZ') then
-    test:diag('libz_version: ' .. ffi.string(info.libz_version))
-end
-
-os.exit(test:check() and 0 or 1)
diff --git a/static-build/test/static-build/suite.ini
b/static-build/test/static-build/suite.ini
index 4da3d5d2f..92e349466 100644
--- a/static-build/test/static-build/suite.ini
+++ b/static-build/test/static-build/suite.ini
@@ -3,4 +3,3 @@ core = app
 description = Static build tests
 script = box.lua
 is_parallel = True
-use_unix_sockets_iproto = True

[-- Attachment #2: Type: text/html, Size: 16632 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Tarantool-patches] [PATCH] build: refactor static build process
  2020-08-05 17:08   ` Mavr Huston
@ 2020-08-06 13:32     ` Alexandr Barulev
  2020-08-24  8:44       ` Alexandr Barulev
  2020-08-25 13:21     ` Alexander Turenko
  1 sibling, 1 reply; 6+ messages in thread
From: Alexandr Barulev @ 2020-08-06 13:32 UTC (permalink / raw)
  To: Alexander Turenko; +Cc: tarantool-patches, yaroslav.dynnikov

[-- Attachment #1: Type: text/plain, Size: 15401 bytes --]

I’ve squashed commit and changed it’s message;
Also I’ve sended diff at previous answer

https://github.com/tarantool/tarantool/tree/rosik/refactor-static-build

ср, 5 авг. 2020 г. в 20:08, Mavr Huston <huston.mavr@gmail.com>:

> Hi, thanks for the review!
>
> libicu installs as ExternalProject_Add too, its missed in commit message;
>
> Problem with curses and ncurses was on macOS and linux, because libcurses
> is an entire copy of libncurses, and tarantool links with system
> libcurses instead of libncurses installed as tarantool dependency, but
> module FindCurses.cmkae provides workaround for this problem -
> CURSES_NEED_NCURSES flag.- to use ncurses instead of curses. (i will fix
> this part at commit message)
>
> About disable-shred flag, used at libcurl building - we want to link only
> with
> static libraries, so we prevent creating unused .so.
>
> I've renamed static_build_no_deps_* jobs after review to
> static_build_cmake_*
>
> Also about such path tarantool-prefix/* - it's a cmake
> ExternalProject_Add()
> default path (i've also added comment at .travis.mk)
>
> Useless comments "Init macOS test env" deleted.
>
> >      if (BUILD_STATIC)
> > -        set(LIBZ_LIB_NAME libz.a)
> > +        find_library(LIBZ_LIBRARY NAMES libz.a)
> >      else()
> > -        set(LIBZ_LIB_NAME z)
> > +        find_library(LIBZ_LIBRARY NAMES z)
> >      endif()
> > -    find_library(LIBZ_LIBRARY NAMES ${LIBZ_LIB_NAME})
> Here we simplified code, by deleting useless variable.
>
> I've added commentaries to cmake/compiler.cmake about libunwind on macOS
> and about ignoring flag -static-libstdc++ on macOS
>
> I've fixed static-build for using system compiler:  gcc/g++ on linux
> and clang/clang++ on macOS
>
> I've refactored IF (NOT APPLE) condition to IF (APPLE) at
> static-build/CMakeLists.txt
>
> I've mentioned macOS dependencies at static-build/README.md xcode-tools and
> others, also I've added example with CMAKE_TARANTOOL_ARGS.
>
> Added commentaries about _EP_INSTALL_DIR at static-build/CMakeLists.txt
>
> Also deleted unused use_unix_sockets_iproto = True
>
> Also deleted curl-features.test.lua, because after rebase on master it
> fails,
> due to missing curl_version_info symbol at tarantool binary. This symbol
> lost
> after #807c7fa584f21ee955b2a14623d70f7510a3650d (build: update curl
> submodule
> to 7.71.1 version )
>
>
> After pass the review I'll squash this changes to base commit and update
> commit
> message.
>
> Here is a diff of changes:
> =====================================
>
> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> index 5ec5dd9b9..c9aef3dc7 100644
> --- a/.gitlab-ci.yml
> +++ b/.gitlab-ci.yml
> @@ -534,14 +534,14 @@ static_build:
>    script:
>      - ${GITLAB_MAKE} test_static_build
>
> -static_build_no_deps_linux:
> +static_build_cmake_linux:
>    <<: *docker_test_definition
>    script:
> -    - ${GITLAB_MAKE} test_static_build_no_deps_linux
> +    - ${GITLAB_MAKE} test_static_build_cmake_linux
>
> -static_build_no_deps_osx_15:
> +static_build_cmake_osx_15:
>    stage: test
>    tags:
>      - osx_15
>    script:
> -    - ${GITLAB_MAKE} test_static_build_no_deps_osx
> +    - ${GITLAB_MAKE} test_static_build_cmake_osx
> diff --git a/.travis.mk b/.travis.mk
> index 64862348f..482672429 100644
> --- a/.travis.mk
> +++ b/.travis.mk
> @@ -149,8 +149,8 @@ test_static_build: deps_debian_static
>   CMAKE_EXTRA_PARAMS=-DBUILD_STATIC=ON make -f .travis.mk
> test_debian_no_deps
>
>  # New static build
> -
> -test_static_build_no_deps_linux:
> +# builddir used in this target - is a default build path from cmake
> ExternalProject_Add()
> +test_static_build_cmake_linux:
>   cd static-build && cmake . && make -j && ctest -V
>   cd test && /usr/bin/python test-run.py --force \
>   --builddir ${PWD}/static-build/tarantool-prefix/src/tarantool-build
> $(TEST_RUN_EXTRA_PARAMS)
> @@ -218,7 +218,6 @@ INIT_TEST_ENV_OSX=\
>   rm -rf /tmp/tnt
>
>  test_osx_no_deps: build_osx
> - # Init macOS test env
>   ${INIT_TEST_ENV_OSX}; \
>   cd test && ./test-run.py --vardir /tmp/tnt --force
> $(TEST_RUN_EXTRA_PARAMS)
>
> @@ -233,9 +232,9 @@ base_deps_osx:
>   brew install --force ${STATIC_OSX_PKGS} || brew upgrade
> ${STATIC_OSX_PKGS}
>   pip install --force-reinstall -r test-run/requirements.txt
>
> -test_static_build_no_deps_osx: base_deps_osx
> +# builddir used in this target - is a default build path from cmake
> ExternalProject_Add()
> +test_static_build_cmake_osx: base_deps_osx
>   cd static-build && cmake . && make -j && ctest -V
> - # Init macOS test env
>   ${INIT_TEST_ENV_OSX}; \
>   cd test && ./test-run.py --vardir /tmp/tnt \
>   --builddir ${PWD}/static-build/tarantool-prefix/src/tarantool-build \
> diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake
> index 8422181d6..afe480679 100644
> --- a/cmake/FindReadline.cmake
> +++ b/cmake/FindReadline.cmake
> @@ -14,6 +14,14 @@ if(BUILD_STATIC)
>      if (NOT CURSES_INFO_LIBRARY)
>          set(CURSES_INFO_LIBRARY "")
>      endif()
> +
> +    # From Modules/FindCurses.cmake:
> +    # Set ``CURSES_NEED_NCURSES`` to ``TRUE`` before the
> +    # ``find_package(Curses)`` call if NCurses functionality is required.
> +    # This flag is set for linking with required library (installed
> +    # via static-build/CMakeLists.txt). If this variable won't be set
> +    # then tarantool binary links with system library curses which is an
> +    # entire copy of ncurses
>      set(CURSES_NEED_NCURSES TRUE)
>  endif()
>
> diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake
> index 14f1e1186..db2ae6227 100644
> --- a/cmake/compiler.cmake
> +++ b/cmake/compiler.cmake
> @@ -131,6 +131,8 @@ set(CMAKE_REQUIRED_INCLUDES "")
>  if(BUILD_STATIC AND NOT TARGET_OS_DARWIN)
>      set(UNWIND_LIB_NAME libunwind.a)
>  else()
> +    # libunwind can't be compiled on macOS.
> +    # But there exists libunwind.dylib as a part of MacOSSDK
>      set(UNWIND_LIB_NAME unwind)
>  endif()
>  find_library(UNWIND_LIBRARY PATH_SUFFIXES system NAMES ${UNWIND_LIB_NAME})
> @@ -192,6 +194,9 @@ if (ENABLE_BACKTRACE)
>      find_package_message(UNWIND_LIBRARIES "Found unwind"
> "${UNWIND_LIBRARIES}")
>  endif()
>
> +# On macOS there is no '-static-libstdc++' flag and it's use will
> +# raise following error:
> +# error: argument unused during compilation: '-static-libstdc++'
>  if(BUILD_STATIC AND NOT TARGET_OS_DARWIN)
>      # Static linking for c++ routines
>      add_compile_flags("C;CXX" "-static-libstdc++")
> diff --git a/static-build/CMakeLists.txt b/static-build/CMakeLists.txt
> index 86582af0a..53ceb609c 100644
> --- a/static-build/CMakeLists.txt
> +++ b/static-build/CMakeLists.txt
> @@ -9,11 +9,18 @@ set(NCURSES_VERSION 6.2)
>  set(READLINE_VERSION 8.0)
>  set(UNWIND_VERSION 1.3-rc1)
>
> -find_program(C_COMPILER gcc)
> -find_program(CXX_COMPILER g++)
> +if (APPLE)
> +    find_program(C_COMPILER clang)
> +    find_program(CXX_COMPILER clang++)
> +else()
> +    find_program(C_COMPILER gcc)
> +    find_program(CXX_COMPILER g++)
> +endif()
>  set(CMAKE_C_COMPILER ${C_COMPILER})
>  set(CMAKE_CXX_COMPILER ${CXX_COMPILER})
>
> +# Install all libraries required by tarantool at current build dir
> +
>  #
>  # OpenSSL
>  #
> @@ -80,7 +87,18 @@ ExternalProject_Add(readline
>  #
>  # ICONV
>  #
> -if (NOT APPLE)
> +if (APPLE)
> +    ExternalProject_Add(iconv
> +        URL https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
> +        CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
> +            <SOURCE_DIR>/configure
> +            --prefix=<INSTALL_DIR>
> +            --disable-shared
> +            --enable-static
> +            --with-gnu-ld
> +        STEP_TARGETS download
> +    )
> +else()
>      # In linux iconv is embedded into glibc
>      # So we find system header and copy it locally
>      find_path(ICONV_INCLUDE_DIR iconv.h)
> @@ -101,20 +119,11 @@ if (NOT APPLE)
>      add_custom_target(iconv
>          DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/iconv-prefix/include/iconv.h"
>      )
> +    # This is a hack for further getting install directory of library
> +    # by ExternalProject_Get_Property
>      set_target_properties(iconv
>          PROPERTIES _EP_INSTALL_DIR ${ICONV_INSTALL_PREFIX}
>      )
> -else()
> -    ExternalProject_Add(iconv
> -        URL https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
> -        CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
> -            <SOURCE_DIR>/configure
> -            --prefix=<INSTALL_DIR>
> -            --disable-shared
> -            --enable-static
> -            --with-gnu-ld
> -        STEP_TARGETS download
> -    )
>  endif()
>
>  #
> @@ -162,6 +171,8 @@ if (APPLE)
>      endif()
>
>      add_custom_target(unwind DEPENDS ${UNWIND_DEPENDENCIES})
> +    # This is a hack for further getting install directory of library
> +    # by ExternalProject_Get_Property
>      set_target_properties(unwind
>          PROPERTIES _EP_INSTALL_DIR ${UNWIND_INSTALL_PREFIX}
>      )
> @@ -178,6 +189,8 @@ else()
>      )
>  endif()
>
> +# Get install directories of builded libraries for building
> +# tarantool with custon CMAKE_PREFIX_PATH
>  foreach(PROJ openssl icu zlib ncurses readline iconv unwind)
>      ExternalProject_Get_Property(${PROJ} install_dir)
>      set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}:${install_dir})
> @@ -197,16 +210,14 @@ ExternalProject_Add(tarantool
>          -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
>          -DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=FALSE
>          -DOPENSSL_USE_STATIC_LIBS=TRUE
> -        -DCMAKE_BUILD_TYPE=Debug
>          -DBUILD_STATIC=TRUE
>          -DENABLE_DIST=TRUE
>          -DENABLE_BACKTRACE=TRUE
> -        -DPACKAGE:STRING=${PACKAGE_NAME}
>          -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
>          -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
>          ${CMAKE_TARANTOOL_ARGS}
> -    BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -j
>      STEP_TARGETS build
> +    BUILD_COMMAND $(MAKE)
>  )
>
>  enable_testing()
> diff --git a/static-build/README.md b/static-build/README.md
> index 29fe085c3..0019e963f 100644
> --- a/static-build/README.md
> +++ b/static-build/README.md
> @@ -13,6 +13,24 @@ yum install -y \
>      python-msgpack python-yaml python-argparse python-six python-gevent
>  ```
>
> +MacOS:
> +
> +Before you start please install default Xcode Tools by Apple:
> +
> +```
> +sudo xcode-select --install
> +sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
> +```
> +
> +Install brew using command from
> +[Homebrew repository instructions](https://github.com/Homebrew/inst)
> +
> +After that run next script:
> +
> +```bash
> +  brew install autoconf automake libtool cmake
> file://$${PWD}/tools/brew_taps/tntpython2.rbs
> +  pip install --force-reinstall -r test-run/requirements.txt
> +```
>
>  ### Usage
>
> @@ -21,3 +39,20 @@ cmake .
>  make -j
>  ctest -V
>  ```
> +
> +## Customize your build
> +
> +If you want to customise build, you need to set `CMAKE_TARANTOOL_ARGS`
> variable
> +
> +### Usage
> +
> +There is three types of `CMAKE_BUILD_TYPE`:
> +* Debug - default
> +* Release
> +* RelWithDebInfo
> +
> +And you want to build tarantool with RelWithDebInfo:
> +
> +```bash
> +cmake -DCMAKE_TARANTOOL_ARGS="-DCMAKE_BUILD_TYPE=RelWithDebInfo" .
> +```
> diff --git a/static-build/test/static-build/curl-features.test.lua
> b/static-build/test/static-build/curl-features.test.lua
> deleted file mode 100755
> index 57b1c4306..000000000
> --- a/static-build/test/static-build/curl-features.test.lua
> +++ /dev/null
> @@ -1,67 +0,0 @@
> -#!/usr/bin/env tarantool
> -
> -local tap = require('tap')
> -local ffi = require('ffi')
> -ffi.cdef([[
> -    struct curl_version_info_data {
> -        int age;                  /* see description below */
> -        const char *version;      /* human readable string */
> -        unsigned int version_num; /* numeric representation */
> -        const char *host;         /* human readable string */
> -        int features;             /* bitmask, see below */
> -        char *ssl_version;        /* human readable string */
> -        long ssl_version_num;     /* not used, always zero */
> -        const char *libz_version; /* human readable string */
> -        const char * const *protocols; /* protocols */
> -
> -        /* when 'age' is CURLVERSION_SECOND or higher, the members below
> exist */
> -        const char *ares;         /* human readable string */
> -        int ares_num;             /* number */
> -
> -        /* when 'age' is CURLVERSION_THIRD or higher, the members below
> exist */
> -        const char *libidn;       /* human readable string */
> -
> -        /* when 'age' is CURLVERSION_FOURTH or higher (>= 7.16.1), the
> members
> -           below exist */
> -        int iconv_ver_num;       /* '_libiconv_version' if iconv support
> enabled */
> -
> -        const char *libssh_version; /* human readable string */
> -
> -        /* when 'age' is CURLVERSION_FIFTH or higher (>= 7.57.0), the
> members
> -           below exist */
> -        unsigned int brotli_ver_num; /* Numeric Brotli version
> -                                        (MAJOR << 24) | (MINOR << 12) |
> PATCH */
> -        const char *brotli_version; /* human readable string. */
> -
> -        /* when 'age' is CURLVERSION_SIXTH or higher (>= 7.66.0), the
> members
> -           below exist */
> -        unsigned int nghttp2_ver_num; /* Numeric nghttp2 version
> -                                         (MAJOR << 16) | (MINOR << 8) |
> PATCH */
> -        const char *nghttp2_version; /* human readable string. */
> -
> -        const char *quic_version;    /* human readable quic (+ HTTP/3)
> library +
> -                                        version or NULL */
> -
> -        /* when 'age' is CURLVERSION_SEVENTH or higher (>= 7.70.0), the
> members
> -           below exist */
> -        const char *cainfo;          /* the built-in default
> CURLOPT_CAINFO, might
> -                                        be NULL */
> -        const char *capath;          /* the built-in default
> CURLOPT_CAPATH, might
> -                                        be NULL */
> -    };
> -
> -    struct curl_version_info_data *curl_version_info(int age);
> -]])
> -
> -local info = ffi.C.curl_version_info(7)
> -local test = tap.test('curl-features')
> -test:plan(2)
> -
> -if test:ok(info.ssl_version ~= nil, 'Curl built with SSL support') then
> -    test:diag('ssl_version: ' .. ffi.string(info.ssl_version))
> -end
> -if test:ok(info.libz_version ~= nil, 'Curl built with LIBZ') then
> -    test:diag('libz_version: ' .. ffi.string(info.libz_version))
> -end
> -
> -os.exit(test:check() and 0 or 1)
> diff --git a/static-build/test/static-build/suite.ini
> b/static-build/test/static-build/suite.ini
> index 4da3d5d2f..92e349466 100644
> --- a/static-build/test/static-build/suite.ini
> +++ b/static-build/test/static-build/suite.ini
> @@ -3,4 +3,3 @@ core = app
>  description = Static build tests
>  script = box.lua
>  is_parallel = True
> -use_unix_sockets_iproto = True
>

[-- Attachment #2: Type: text/html, Size: 17393 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Tarantool-patches] [PATCH] build: refactor static build process
  2020-08-06 13:32     ` Alexandr Barulev
@ 2020-08-24  8:44       ` Alexandr Barulev
  0 siblings, 0 replies; 6+ messages in thread
From: Alexandr Barulev @ 2020-08-24  8:44 UTC (permalink / raw)
  To: Alexander Turenko; +Cc: tarantool-patches, yaroslav.dynnikov

[-- Attachment #1: Type: text/plain, Size: 16497 bytes --]

I've modified this patch: disabled building libunwind with minidebuginfo
to prevent linking libunwind with liblzma.
Here is a diff:

diff --git a/static-build/CMakeLists.txt b/static-build/CMakeLists.txt
index 53ceb609c..d90a642e6 100644
--- a/static-build/CMakeLists.txt
+++ b/static-build/CMakeLists.txt
@@ -185,6 +185,7 @@ else()
             --prefix=<INSTALL_DIR>
             --disable-shared
             --enable-static
+            --disable-minidebuginfo # to prevent linking with liblzma
         STEP_TARGETS download
     )
 endif()

чт, 6 авг. 2020 г. в 16:32, Alexandr Barulev <huston.mavr@gmail.com>:

> I’ve squashed commit and changed it’s message;
> Also I’ve sended diff at previous answer
>
> https://github.com/tarantool/tarantool/tree/rosik/refactor-static-build
>
> ср, 5 авг. 2020 г. в 20:08, Mavr Huston <huston.mavr@gmail.com>:
>
>> Hi, thanks for the review!
>>
>> libicu installs as ExternalProject_Add too, its missed in commit message;
>>
>> Problem with curses and ncurses was on macOS and linux, because libcurses
>> is an entire copy of libncurses, and tarantool links with system
>> libcurses instead of libncurses installed as tarantool dependency, but
>> module FindCurses.cmkae provides workaround for this problem -
>> CURSES_NEED_NCURSES flag.- to use ncurses instead of curses. (i will fix
>> this part at commit message)
>>
>> About disable-shred flag, used at libcurl building - we want to link only
>> with
>> static libraries, so we prevent creating unused .so.
>>
>> I've renamed static_build_no_deps_* jobs after review to
>> static_build_cmake_*
>>
>> Also about such path tarantool-prefix/* - it's a cmake
>> ExternalProject_Add()
>> default path (i've also added comment at .travis.mk)
>>
>> Useless comments "Init macOS test env" deleted.
>>
>> >      if (BUILD_STATIC)
>> > -        set(LIBZ_LIB_NAME libz.a)
>> > +        find_library(LIBZ_LIBRARY NAMES libz.a)
>> >      else()
>> > -        set(LIBZ_LIB_NAME z)
>> > +        find_library(LIBZ_LIBRARY NAMES z)
>> >      endif()
>> > -    find_library(LIBZ_LIBRARY NAMES ${LIBZ_LIB_NAME})
>> Here we simplified code, by deleting useless variable.
>>
>> I've added commentaries to cmake/compiler.cmake about libunwind on macOS
>> and about ignoring flag -static-libstdc++ on macOS
>>
>> I've fixed static-build for using system compiler:  gcc/g++ on linux
>> and clang/clang++ on macOS
>>
>> I've refactored IF (NOT APPLE) condition to IF (APPLE) at
>> static-build/CMakeLists.txt
>>
>> I've mentioned macOS dependencies at static-build/README.md xcode-tools
>> and
>> others, also I've added example with CMAKE_TARANTOOL_ARGS.
>>
>> Added commentaries about _EP_INSTALL_DIR at static-build/CMakeLists.txt
>>
>> Also deleted unused use_unix_sockets_iproto = True
>>
>> Also deleted curl-features.test.lua, because after rebase on master it
>> fails,
>> due to missing curl_version_info symbol at tarantool binary. This symbol
>> lost
>> after #807c7fa584f21ee955b2a14623d70f7510a3650d (build: update curl
>> submodule
>> to 7.71.1 version )
>>
>>
>> After pass the review I'll squash this changes to base commit and update
>> commit
>> message.
>>
>> Here is a diff of changes:
>> =====================================
>>
>> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
>> index 5ec5dd9b9..c9aef3dc7 100644
>> --- a/.gitlab-ci.yml
>> +++ b/.gitlab-ci.yml
>> @@ -534,14 +534,14 @@ static_build:
>>    script:
>>      - ${GITLAB_MAKE} test_static_build
>>
>> -static_build_no_deps_linux:
>> +static_build_cmake_linux:
>>    <<: *docker_test_definition
>>    script:
>> -    - ${GITLAB_MAKE} test_static_build_no_deps_linux
>> +    - ${GITLAB_MAKE} test_static_build_cmake_linux
>>
>> -static_build_no_deps_osx_15:
>> +static_build_cmake_osx_15:
>>    stage: test
>>    tags:
>>      - osx_15
>>    script:
>> -    - ${GITLAB_MAKE} test_static_build_no_deps_osx
>> +    - ${GITLAB_MAKE} test_static_build_cmake_osx
>> diff --git a/.travis.mk b/.travis.mk
>> index 64862348f..482672429 100644
>> --- a/.travis.mk
>> +++ b/.travis.mk
>> @@ -149,8 +149,8 @@ test_static_build: deps_debian_static
>>   CMAKE_EXTRA_PARAMS=-DBUILD_STATIC=ON make -f .travis.mk
>> test_debian_no_deps
>>
>>  # New static build
>> -
>> -test_static_build_no_deps_linux:
>> +# builddir used in this target - is a default build path from cmake
>> ExternalProject_Add()
>> +test_static_build_cmake_linux:
>>   cd static-build && cmake . && make -j && ctest -V
>>   cd test && /usr/bin/python test-run.py --force \
>>   --builddir ${PWD}/static-build/tarantool-prefix/src/tarantool-build
>> $(TEST_RUN_EXTRA_PARAMS)
>> @@ -218,7 +218,6 @@ INIT_TEST_ENV_OSX=\
>>   rm -rf /tmp/tnt
>>
>>  test_osx_no_deps: build_osx
>> - # Init macOS test env
>>   ${INIT_TEST_ENV_OSX}; \
>>   cd test && ./test-run.py --vardir /tmp/tnt --force
>> $(TEST_RUN_EXTRA_PARAMS)
>>
>> @@ -233,9 +232,9 @@ base_deps_osx:
>>   brew install --force ${STATIC_OSX_PKGS} || brew upgrade
>> ${STATIC_OSX_PKGS}
>>   pip install --force-reinstall -r test-run/requirements.txt
>>
>> -test_static_build_no_deps_osx: base_deps_osx
>> +# builddir used in this target - is a default build path from cmake
>> ExternalProject_Add()
>> +test_static_build_cmake_osx: base_deps_osx
>>   cd static-build && cmake . && make -j && ctest -V
>> - # Init macOS test env
>>   ${INIT_TEST_ENV_OSX}; \
>>   cd test && ./test-run.py --vardir /tmp/tnt \
>>   --builddir ${PWD}/static-build/tarantool-prefix/src/tarantool-build \
>> diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake
>> index 8422181d6..afe480679 100644
>> --- a/cmake/FindReadline.cmake
>> +++ b/cmake/FindReadline.cmake
>> @@ -14,6 +14,14 @@ if(BUILD_STATIC)
>>      if (NOT CURSES_INFO_LIBRARY)
>>          set(CURSES_INFO_LIBRARY "")
>>      endif()
>> +
>> +    # From Modules/FindCurses.cmake:
>> +    # Set ``CURSES_NEED_NCURSES`` to ``TRUE`` before the
>> +    # ``find_package(Curses)`` call if NCurses functionality is required.
>> +    # This flag is set for linking with required library (installed
>> +    # via static-build/CMakeLists.txt). If this variable won't be set
>> +    # then tarantool binary links with system library curses which is an
>> +    # entire copy of ncurses
>>      set(CURSES_NEED_NCURSES TRUE)
>>  endif()
>>
>> diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake
>> index 14f1e1186..db2ae6227 100644
>> --- a/cmake/compiler.cmake
>> +++ b/cmake/compiler.cmake
>> @@ -131,6 +131,8 @@ set(CMAKE_REQUIRED_INCLUDES "")
>>  if(BUILD_STATIC AND NOT TARGET_OS_DARWIN)
>>      set(UNWIND_LIB_NAME libunwind.a)
>>  else()
>> +    # libunwind can't be compiled on macOS.
>> +    # But there exists libunwind.dylib as a part of MacOSSDK
>>      set(UNWIND_LIB_NAME unwind)
>>  endif()
>>  find_library(UNWIND_LIBRARY PATH_SUFFIXES system NAMES
>> ${UNWIND_LIB_NAME})
>> @@ -192,6 +194,9 @@ if (ENABLE_BACKTRACE)
>>      find_package_message(UNWIND_LIBRARIES "Found unwind"
>> "${UNWIND_LIBRARIES}")
>>  endif()
>>
>> +# On macOS there is no '-static-libstdc++' flag and it's use will
>> +# raise following error:
>> +# error: argument unused during compilation: '-static-libstdc++'
>>  if(BUILD_STATIC AND NOT TARGET_OS_DARWIN)
>>      # Static linking for c++ routines
>>      add_compile_flags("C;CXX" "-static-libstdc++")
>> diff --git a/static-build/CMakeLists.txt b/static-build/CMakeLists.txt
>> index 86582af0a..53ceb609c 100644
>> --- a/static-build/CMakeLists.txt
>> +++ b/static-build/CMakeLists.txt
>> @@ -9,11 +9,18 @@ set(NCURSES_VERSION 6.2)
>>  set(READLINE_VERSION 8.0)
>>  set(UNWIND_VERSION 1.3-rc1)
>>
>> -find_program(C_COMPILER gcc)
>> -find_program(CXX_COMPILER g++)
>> +if (APPLE)
>> +    find_program(C_COMPILER clang)
>> +    find_program(CXX_COMPILER clang++)
>> +else()
>> +    find_program(C_COMPILER gcc)
>> +    find_program(CXX_COMPILER g++)
>> +endif()
>>  set(CMAKE_C_COMPILER ${C_COMPILER})
>>  set(CMAKE_CXX_COMPILER ${CXX_COMPILER})
>>
>> +# Install all libraries required by tarantool at current build dir
>> +
>>  #
>>  # OpenSSL
>>  #
>> @@ -80,7 +87,18 @@ ExternalProject_Add(readline
>>  #
>>  # ICONV
>>  #
>> -if (NOT APPLE)
>> +if (APPLE)
>> +    ExternalProject_Add(iconv
>> +        URL https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
>> +        CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
>> +            <SOURCE_DIR>/configure
>> +            --prefix=<INSTALL_DIR>
>> +            --disable-shared
>> +            --enable-static
>> +            --with-gnu-ld
>> +        STEP_TARGETS download
>> +    )
>> +else()
>>      # In linux iconv is embedded into glibc
>>      # So we find system header and copy it locally
>>      find_path(ICONV_INCLUDE_DIR iconv.h)
>> @@ -101,20 +119,11 @@ if (NOT APPLE)
>>      add_custom_target(iconv
>>          DEPENDS
>> "${CMAKE_CURRENT_BINARY_DIR}/iconv-prefix/include/iconv.h"
>>      )
>> +    # This is a hack for further getting install directory of library
>> +    # by ExternalProject_Get_Property
>>      set_target_properties(iconv
>>          PROPERTIES _EP_INSTALL_DIR ${ICONV_INSTALL_PREFIX}
>>      )
>> -else()
>> -    ExternalProject_Add(iconv
>> -        URL https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
>> -        CONFIGURE_COMMAND CC=${CMAKE_C_COMPILER}
>> -            <SOURCE_DIR>/configure
>> -            --prefix=<INSTALL_DIR>
>> -            --disable-shared
>> -            --enable-static
>> -            --with-gnu-ld
>> -        STEP_TARGETS download
>> -    )
>>  endif()
>>
>>  #
>> @@ -162,6 +171,8 @@ if (APPLE)
>>      endif()
>>
>>      add_custom_target(unwind DEPENDS ${UNWIND_DEPENDENCIES})
>> +    # This is a hack for further getting install directory of library
>> +    # by ExternalProject_Get_Property
>>      set_target_properties(unwind
>>          PROPERTIES _EP_INSTALL_DIR ${UNWIND_INSTALL_PREFIX}
>>      )
>> @@ -178,6 +189,8 @@ else()
>>      )
>>  endif()
>>
>> +# Get install directories of builded libraries for building
>> +# tarantool with custon CMAKE_PREFIX_PATH
>>  foreach(PROJ openssl icu zlib ncurses readline iconv unwind)
>>      ExternalProject_Get_Property(${PROJ} install_dir)
>>      set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}:${install_dir})
>> @@ -197,16 +210,14 @@ ExternalProject_Add(tarantool
>>          -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
>>          -DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=FALSE
>>          -DOPENSSL_USE_STATIC_LIBS=TRUE
>> -        -DCMAKE_BUILD_TYPE=Debug
>>          -DBUILD_STATIC=TRUE
>>          -DENABLE_DIST=TRUE
>>          -DENABLE_BACKTRACE=TRUE
>> -        -DPACKAGE:STRING=${PACKAGE_NAME}
>>          -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
>>          -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
>>          ${CMAKE_TARANTOOL_ARGS}
>> -    BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} -j
>>      STEP_TARGETS build
>> +    BUILD_COMMAND $(MAKE)
>>  )
>>
>>  enable_testing()
>> diff --git a/static-build/README.md b/static-build/README.md
>> index 29fe085c3..0019e963f 100644
>> --- a/static-build/README.md
>> +++ b/static-build/README.md
>> @@ -13,6 +13,24 @@ yum install -y \
>>      python-msgpack python-yaml python-argparse python-six python-gevent
>>  ```
>>
>> +MacOS:
>> +
>> +Before you start please install default Xcode Tools by Apple:
>> +
>> +```
>> +sudo xcode-select --install
>> +sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
>> +```
>> +
>> +Install brew using command from
>> +[Homebrew repository instructions](https://github.com/Homebrew/inst)
>> +
>> +After that run next script:
>> +
>> +```bash
>> +  brew install autoconf automake libtool cmake
>> file://$${PWD}/tools/brew_taps/tntpython2.rbs
>> +  pip install --force-reinstall -r test-run/requirements.txt
>> +```
>>
>>  ### Usage
>>
>> @@ -21,3 +39,20 @@ cmake .
>>  make -j
>>  ctest -V
>>  ```
>> +
>> +## Customize your build
>> +
>> +If you want to customise build, you need to set `CMAKE_TARANTOOL_ARGS`
>> variable
>> +
>> +### Usage
>> +
>> +There is three types of `CMAKE_BUILD_TYPE`:
>> +* Debug - default
>> +* Release
>> +* RelWithDebInfo
>> +
>> +And you want to build tarantool with RelWithDebInfo:
>> +
>> +```bash
>> +cmake -DCMAKE_TARANTOOL_ARGS="-DCMAKE_BUILD_TYPE=RelWithDebInfo" .
>> +```
>> diff --git a/static-build/test/static-build/curl-features.test.lua
>> b/static-build/test/static-build/curl-features.test.lua
>> deleted file mode 100755
>> index 57b1c4306..000000000
>> --- a/static-build/test/static-build/curl-features.test.lua
>> +++ /dev/null
>> @@ -1,67 +0,0 @@
>> -#!/usr/bin/env tarantool
>> -
>> -local tap = require('tap')
>> -local ffi = require('ffi')
>> -ffi.cdef([[
>> -    struct curl_version_info_data {
>> -        int age;                  /* see description below */
>> -        const char *version;      /* human readable string */
>> -        unsigned int version_num; /* numeric representation */
>> -        const char *host;         /* human readable string */
>> -        int features;             /* bitmask, see below */
>> -        char *ssl_version;        /* human readable string */
>> -        long ssl_version_num;     /* not used, always zero */
>> -        const char *libz_version; /* human readable string */
>> -        const char * const *protocols; /* protocols */
>> -
>> -        /* when 'age' is CURLVERSION_SECOND or higher, the members below
>> exist */
>> -        const char *ares;         /* human readable string */
>> -        int ares_num;             /* number */
>> -
>> -        /* when 'age' is CURLVERSION_THIRD or higher, the members below
>> exist */
>> -        const char *libidn;       /* human readable string */
>> -
>> -        /* when 'age' is CURLVERSION_FOURTH or higher (>= 7.16.1), the
>> members
>> -           below exist */
>> -        int iconv_ver_num;       /* '_libiconv_version' if iconv support
>> enabled */
>> -
>> -        const char *libssh_version; /* human readable string */
>> -
>> -        /* when 'age' is CURLVERSION_FIFTH or higher (>= 7.57.0), the
>> members
>> -           below exist */
>> -        unsigned int brotli_ver_num; /* Numeric Brotli version
>> -                                        (MAJOR << 24) | (MINOR << 12) |
>> PATCH */
>> -        const char *brotli_version; /* human readable string. */
>> -
>> -        /* when 'age' is CURLVERSION_SIXTH or higher (>= 7.66.0), the
>> members
>> -           below exist */
>> -        unsigned int nghttp2_ver_num; /* Numeric nghttp2 version
>> -                                         (MAJOR << 16) | (MINOR << 8) |
>> PATCH */
>> -        const char *nghttp2_version; /* human readable string. */
>> -
>> -        const char *quic_version;    /* human readable quic (+ HTTP/3)
>> library +
>> -                                        version or NULL */
>> -
>> -        /* when 'age' is CURLVERSION_SEVENTH or higher (>= 7.70.0), the
>> members
>> -           below exist */
>> -        const char *cainfo;          /* the built-in default
>> CURLOPT_CAINFO, might
>> -                                        be NULL */
>> -        const char *capath;          /* the built-in default
>> CURLOPT_CAPATH, might
>> -                                        be NULL */
>> -    };
>> -
>> -    struct curl_version_info_data *curl_version_info(int age);
>> -]])
>> -
>> -local info = ffi.C.curl_version_info(7)
>> -local test = tap.test('curl-features')
>> -test:plan(2)
>> -
>> -if test:ok(info.ssl_version ~= nil, 'Curl built with SSL support') then
>> -    test:diag('ssl_version: ' .. ffi.string(info.ssl_version))
>> -end
>> -if test:ok(info.libz_version ~= nil, 'Curl built with LIBZ') then
>> -    test:diag('libz_version: ' .. ffi.string(info.libz_version))
>> -end
>> -
>> -os.exit(test:check() and 0 or 1)
>> diff --git a/static-build/test/static-build/suite.ini
>> b/static-build/test/static-build/suite.ini
>> index 4da3d5d2f..92e349466 100644
>> --- a/static-build/test/static-build/suite.ini
>> +++ b/static-build/test/static-build/suite.ini
>> @@ -3,4 +3,3 @@ core = app
>>  description = Static build tests
>>  script = box.lua
>>  is_parallel = True
>> -use_unix_sockets_iproto = True
>>
>

[-- Attachment #2: Type: text/html, Size: 18442 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Tarantool-patches] [PATCH] build: refactor static build process
  2020-08-05 17:08   ` Mavr Huston
  2020-08-06 13:32     ` Alexandr Barulev
@ 2020-08-25 13:21     ` Alexander Turenko
  1 sibling, 0 replies; 6+ messages in thread
From: Alexander Turenko @ 2020-08-25 13:21 UTC (permalink / raw)
  To: Mavr Huston; +Cc: tarantool-patches, yaroslav.dynnikov

Thanks for fixes and added comments!

> diff --git a/static-build/CMakeLists.txt b/static-build/CMakeLists.txt
> index 86582af0a..53ceb609c 100644
> --- a/static-build/CMakeLists.txt
> +++ b/static-build/CMakeLists.txt
> @@ -9,11 +9,18 @@ set(NCURSES_VERSION 6.2)
>  set(READLINE_VERSION 8.0)
>  set(UNWIND_VERSION 1.3-rc1)
> 
> -find_program(C_COMPILER gcc)
> -find_program(CXX_COMPILER g++)
> +if (APPLE)
> +    find_program(C_COMPILER clang)
> +    find_program(CXX_COMPILER clang++)
> +else()
> +    find_program(C_COMPILER gcc)
> +    find_program(CXX_COMPILER g++)
> +endif()

How about just don't set it at all?

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-08-25 13:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22 18:16 [Tarantool-patches] [PATCH] build: refactor static build process HustonMmmavr
2020-07-27 22:41 ` Alexander Turenko
2020-08-05 17:08   ` Mavr Huston
2020-08-06 13:32     ` Alexandr Barulev
2020-08-24  8:44       ` Alexandr Barulev
2020-08-25 13:21     ` Alexander Turenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox