[tarantool-patches] [PATCH v1 1/1][WIP] app: statically link curl 7.65.03
imeevma at tarantool.org
imeevma at tarantool.org
Wed Aug 7 20:10:31 MSK 2019
After this patch curl will be statically linked in case
ENABLE_BUNDLED_LIBCURL option is set. This option is set by
default.
Closes #4318
@TarantoolBot document
Title: additional requirements
Due to building curl from sources, new requirements were added:
autoconf, automake, libtool, zlib.
---
https://github.com/tarantool/tarantool/issues/4318
https://github.com/tarantool/tarantool/tree/imeevma/gh-4318-link-libcurl-statically
---
Currently this patch is not complete since there is some problem
in building Tarantool in some systems, for example Debian and OSX.
---
.gitmodules | 4 ++++
.travis.mk | 4 ++--
CMakeLists.txt | 12 ++++++++++--
cmake/BuildLibCURL.cmake | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
rpm/tarantool.spec | 2 +-
src/CMakeLists.txt | 3 +++
test/unit/CMakeLists.txt | 7 +++++++
third_party/curl | 1 +
8 files changed, 78 insertions(+), 5 deletions(-)
create mode 100644 cmake/BuildLibCURL.cmake
create mode 160000 third_party/curl
diff --git a/.gitmodules b/.gitmodules
index 1062f73..e34ec37 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -37,3 +37,7 @@
[submodule "third_party/serpent"]
path = third_party/serpent
url = https://github.com/tarantool/serpent.git
+[submodule "third_party/curl"]
+ path = third_party/curl
+ url = https://github.com/curl/curl.git
+ ignore = dirty
diff --git a/.travis.mk b/.travis.mk
index c0c23b6..ef49430 100644
--- a/.travis.mk
+++ b/.travis.mk
@@ -117,7 +117,7 @@ test_asan_debian: deps_debian deps_buster_clang_8 test_asan_debian_no_deps
deps_osx:
brew update
- brew install openssl readline curl icu4c libiconv --force
+ brew install openssl readline curl icu4c libiconv autoconf automake libtool --force
python2 -V || brew install python2 --force
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py >get-pip.py
python get-pip.py --user
@@ -155,7 +155,7 @@ deps_freebsd:
readline ncurses libyaml openssl curl libunwind icu \
python27 py27-pip py27-setuptools py27-daemon \
py27-yaml py27-argparse py27-six py27-gevent \
- gdb bash
+ gdb bash autoconf automake libtool
build_freebsd:
cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_WERROR=ON ${CMAKE_EXTRA_PARAMS}
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bfb15ef..4292784 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -334,8 +334,15 @@ endif()
#
# Curl
#
-set(CURL_FIND_REQUIRED ON)
-find_package(CURL)
+option(ENABLE_BUNDLED_LIBCURL "Enable building of the bundled libcurl" ON)
+if (ENABLE_BUNDLED_LIBCURL)
+ include(BuildLibCURL)
+ curl_build()
+ add_dependencies(build_bundled_libs curl)
+else()
+ set(CURL_FIND_REQUIRED ON)
+ find_package(CURL)
+endif()
#
# ReadLine
@@ -525,6 +532,7 @@ set(options PACKAGE VERSION BUILD C_COMPILER CXX_COMPILER C_FLAGS CXX_FLAGS
ENABLE_BACKTRACE
ENABLE_DOC
ENABLE_DIST
+ ENABLE_BUNDLED_LIBCURL
ENABLE_BUNDLED_LIBYAML
ENABLE_BUNDLED_MSGPUCK)
foreach(option IN LISTS options)
diff --git a/cmake/BuildLibCURL.cmake b/cmake/BuildLibCURL.cmake
new file mode 100644
index 0000000..1e4342c
--- /dev/null
+++ b/cmake/BuildLibCURL.cmake
@@ -0,0 +1,50 @@
+#
+# A macro to build the bundled libcurl
+macro(curl_build)
+ set(LIBCURL_SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/curl)
+ set(LIBCURL_STATIC_LIB ${LIBCURL_SOURCE_DIR}/build/lib/libcurl.a)
+ set(LIBCURL_BUILD_OPTIONS --enable-static --enable-shared --with-zlib --with-ssl --prefix=${LIBCURL_SOURCE_DIR}/build)
+ set(LIBCURL_CONFIGURE ./buildconf && ./configure ${LIBCURL_BUILD_OPTIONS})
+
+ find_library(LIBZ_LIBRARY NAMES z)
+ if("${LIBZ_LIBRARY}" STREQUAL "LIBZ_LIBRARY-NOTFOUND")
+ message (FATAL_ERROR "Unable to find zlib")
+ endif()
+
+ include(ExternalProject)
+ ExternalProject_Add(
+ libcurl
+ SOURCE_DIR ${LIBCURL_SOURCE_DIR}
+ PREFIX ${LIBCURL_SOURCE_DIR}
+ CONFIGURE_COMMAND ${LIBCURL_CONFIGURE}
+ BUILD_COMMAND $(MAKE)
+ INSTALL_COMMAND make install
+ BINARY_DIR ${LIBCURL_SOURCE_DIR}
+ )
+
+ set(CURL_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/third_party/curl/build/include)
+ set(CURL_LIBRARIES ${PROJECT_SOURCE_DIR}/third_party/curl/build/lib/libcurl.a)
+ set(CURL_LIBRARIES ${CURL_LIBRARIES} ${LIBZ_LIBRARY})
+
+ find_library(NGHTTP2_LIBRARY NAMES nghttp2)
+ find_library(PTHREAD_LIBRARY NAMES pthread)
+ find_library(DL_LIBRARY NAMES dl)
+
+ if(NOT "${NGHTTP2_LIBRARY}" STREQUAL "NGHTTP2_LIBRARY-NOTFOUND")
+ set(CURL_LIBRARIES ${CURL_LIBRARIES} ${NGHTTP2_LIBRARY})
+ endif()
+ if(NOT "${PTHREAD_LIBRARY}" STREQUAL "PTHREAD_LIBRARY-NOTFOUND")
+ set(CURL_LIBRARIES ${CURL_LIBRARIES} ${PTHREAD_LIBRARY})
+ endif()
+ if(NOT "${DL_LIBRARY}" STREQUAL "DL_LIBRARY-NOTFOUND")
+ set(CURL_LIBRARIES ${CURL_LIBRARIES} ${DL_LIBRARY})
+ endif()
+
+ add_library(curl STATIC IMPORTED GLOBAL)
+ set_target_properties(curl PROPERTIES IMPORTED_LOCATION ${LIBCURL_STATIC_LIB})
+ add_dependencies(curl libcurl)
+ unset(LIBCURL_CONFIGURE)
+ unset(LIBCURL_BUILD_OPTIONS)
+ unset(LIBCURL_STATIC_LIB)
+ unset(LIBCURL_SOURCE_DIR)
+endmacro(curl_build)
diff --git a/rpm/tarantool.spec b/rpm/tarantool.spec
index 002df26..06e3ef6 100644
--- a/rpm/tarantool.spec
+++ b/rpm/tarantool.spec
@@ -84,7 +84,7 @@ Requires: /etc/services
# Deps for built-in package manager
# https://github.com/tarantool/tarantool/issues/2612
Requires: openssl
-Requires: curl
+Requires: zlib
%if (0%{?fedora} >= 22 || 0%{?rhel} >= 8)
# RHEL <= 7 doesn't support Recommends:
Recommends: tarantool-devel
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index acd719e..92e966b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -168,6 +168,9 @@ endif()
set_source_files_compile_flags(${server_sources})
add_library(server STATIC ${server_sources})
+if (ENABLE_BUNDLED_LIBCURL)
+ add_dependencies(server curl)
+endif()
target_link_libraries(server core coll http_parser bit uri uuid swim swim_udp
swim_ev crypto)
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 73ee0a9..5da3bcd 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -10,6 +10,7 @@ include_directories(${PROJECT_BINARY_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/src/box)
include_directories(${CMAKE_SOURCE_DIR}/third_party)
include_directories(${ICU_INCLUDE_DIRS})
+include_directories(${CURL_INCLUDE_DIRS})
add_library(unit STATIC unit.c)
@@ -141,10 +142,16 @@ target_link_libraries(histogram.test stat unit)
add_executable(ratelimit.test ratelimit.c)
target_link_libraries(ratelimit.test unit)
add_executable(luaT_tuple_new.test luaT_tuple_new.c)
+if (ENABLE_BUNDLED_LIBCURL)
+ add_dependencies(luaT_tuple_new.test curl)
+endif()
target_link_libraries(luaT_tuple_new.test unit box server core misc
${CURL_LIBRARIES} ${LIBYAML_LIBRARIES} ${READLINE_LIBRARIES}
${ICU_LIBRARIES} ${LUAJIT_LIBRARIES})
add_executable(luaL_iterator.test luaL_iterator.c)
+if (ENABLE_BUNDLED_LIBCURL)
+ add_dependencies(luaL_iterator.test curl)
+endif()
target_link_libraries(luaL_iterator.test unit server coll core misc
${CURL_LIBRARIES} ${LIBYAML_LIBRARIES} ${READLINE_LIBRARIES}
${ICU_LIBRARIES} ${LUAJIT_LIBRARIES} dl)
diff --git a/third_party/curl b/third_party/curl
new file mode 160000
index 0000000..aa73eb4
--- /dev/null
+++ b/third_party/curl
@@ -0,0 +1 @@
+Subproject commit aa73eb47bc8583070734696b25b34ad54c2c1f5e
--
2.7.4
More information about the Tarantool-patches
mailing list