From 2ce592e4afa53653993c741634ac45f2948b0d16 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 26 Dec 2019 08:01:29 -0500 Subject: [PATCH 1/7] static link with docs --- Makefile | 12 ++++++++++++ cmake/unix.cmake | 2 +- llarp/CMakeLists.txt | 4 ++-- readme.md | 11 +++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d663fe4dc..f9be65e99 100644 --- a/Makefile +++ b/Makefile @@ -45,6 +45,9 @@ SHADOW_OPTS ?= LIBUV_VERSION ?= v1.30.1 LIBUV_PREFIX = $(BUILD_ROOT)/libuv +LIBCURL_VERSION ?= curl-7_67_0 +LIBCURL_PREFIX = $(BUILD_ROOT)/curl + TESTNET_ROOT=/tmp/lokinet_testnet_tmp TESTNET_CONF=$(TESTNET_ROOT)/supervisor.conf TESTNET_LOG=$(TESTNET_ROOT)/testnet.log @@ -212,7 +215,16 @@ $(TEST_EXE): debug test: $(TEST_EXE) test x$(CROSS) = xOFF && $(TEST_EXE) || test x$(CROSS) = xON +static-configure: $(LIBUV_PREFIX) $(LIBCURL_PREFIX) + (test x$(TOOLCHAIN) = x && $(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Release -DSTATIC_LINK=ON -DRELEASE_MOTTO="$(shell cat motto.txt)" -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)' -DLIBUV_ROOT='$(LIBUV_PREFIX)' -DLIBCURL_ROOT='$(LIBCURL_PREFIX)' ) || (test x$(TOOLCHAIN) != x && $(CONFIG_CMD) -DCMAKE_BUILD_TYPE=Release -DSTATIC_LINK=ON -DRELEASE_MOTTO="$(shell cat motto.txt)" -DCMAKE_C_FLAGS='$(CFLAGS)' -DCMAKE_CXX_FLAGS='$(CXXFLAGS)' -DLIBUV_ROOT='$(LIBUV_PREFIX)' -DLIBCURL_ROOT='$(LIBCURL_PREFIX)' -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN) -DNATIVE_BUILD=OFF ) + +static: static-configure + $(MAKE) -C '$(BUILD_ROOT)' + cp $(EXE) $(REPO)/lokinet-static +$(LIBCURL_PREFIX): + mkdir -p $(BUILD_ROOT) + git clone -b "$(LIBCURL_VERSION)" https://github.com/curl/curl "$(LIBCURL_PREFIX)" $(LIBUV_PREFIX): mkdir -p $(BUILD_ROOT) diff --git a/cmake/unix.cmake b/cmake/unix.cmake index 7b2d0c7f9..a579f855d 100644 --- a/cmake/unix.cmake +++ b/cmake/unix.cmake @@ -18,7 +18,7 @@ if(NOT IOS AND NOT ANDROID AND NOT WIN32) set(CURL_CA_PATH none) message(STATUS "using local curl: ${LIBCURL_ROOT}") add_subdirectory(${LIBCURL_ROOT}) - set(CURL_INCLUDE_DIRS ${LIBCURL_ROOT}/include) + set(CURL_INCLUDE_DIR ${LIBCURL_ROOT}/include) set(CURL_LIBRARIES libcurl) set(CURL_FOUND TRUE) else() diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 483bd2c47..96ec52b6f 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -63,7 +63,7 @@ add_library(${UTIL_LIB} STATIC ${LIB_UTIL_SRC}) add_dependencies(${UTIL_LIB} genversion) -target_include_directories(${UTIL_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include) +target_include_directories(${UTIL_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include ${CURL_INCLUDE_DIR}) if(ANDROID) set(LOG_LIB log) endif() @@ -253,7 +253,7 @@ if(TESTNET) endif() add_library(${STATIC_LIB} STATIC ${LIB_SRC}) -target_include_directories(${STATIC_LIB} PUBLIC ${CURL_INCLUDE_DIRS}) +target_include_directories(${STATIC_LIB} PUBLIC ${CURL_INCLUDE_DIR}) target_link_libraries(${STATIC_LIB} PUBLIC cxxopts ${ABYSS_LIB} ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOGRAPHY_LIB} ${CURL_LIBRARIES}) if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") diff --git a/readme.md b/readme.md index df83bfa02..dec688a0a 100644 --- a/readme.md +++ b/readme.md @@ -93,6 +93,17 @@ alternatively make a debian package with: this puts the built packages in `../` + +#### Static Linux + +static native optimized: + + $ make static STATIC_LINK=ON DOWNLOAD_SODIUM=ON + +cross compile fully static armhf (rpi 2 and up) + + $ make static STATIC_LINK=ON TOOLCHAIN=contrib/cross/armhf.toolchain.cmake CROSS=ON DOWNLOAD_SODIUM=ON NATIVE_BUILD=OFF + ### MacOS build: From 7ffc786bcec7bf87034a7c36cdee172728d5b2a3 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 26 Dec 2019 08:43:34 -0500 Subject: [PATCH 2/7] fix up docs --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index dec688a0a..4c389b50e 100644 --- a/readme.md +++ b/readme.md @@ -102,7 +102,7 @@ static native optimized: cross compile fully static armhf (rpi 2 and up) - $ make static STATIC_LINK=ON TOOLCHAIN=contrib/cross/armhf.toolchain.cmake CROSS=ON DOWNLOAD_SODIUM=ON NATIVE_BUILD=OFF + $ make static STATIC_LINK=ON DOWNLOAD_SODIUM=ON TOOLCHAIN=contrib/cross/armhf.toolchain.cmake ### MacOS From 80cbddde7b5c54eed86ed554ecb3a4839e155db3 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 26 Dec 2019 13:06:02 -0500 Subject: [PATCH 3/7] fixups for review --- cmake/unix.cmake | 2 +- llarp/CMakeLists.txt | 4 ++-- readme.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/unix.cmake b/cmake/unix.cmake index a579f855d..7b2d0c7f9 100644 --- a/cmake/unix.cmake +++ b/cmake/unix.cmake @@ -18,7 +18,7 @@ if(NOT IOS AND NOT ANDROID AND NOT WIN32) set(CURL_CA_PATH none) message(STATUS "using local curl: ${LIBCURL_ROOT}") add_subdirectory(${LIBCURL_ROOT}) - set(CURL_INCLUDE_DIR ${LIBCURL_ROOT}/include) + set(CURL_INCLUDE_DIRS ${LIBCURL_ROOT}/include) set(CURL_LIBRARIES libcurl) set(CURL_FOUND TRUE) else() diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 96ec52b6f..05bf7d979 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -63,7 +63,7 @@ add_library(${UTIL_LIB} STATIC ${LIB_UTIL_SRC}) add_dependencies(${UTIL_LIB} genversion) -target_include_directories(${UTIL_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include ${CURL_INCLUDE_DIR}) +target_include_directories(${UTIL_LIB} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include ${CURL_INCLUDE_DIRS}) if(ANDROID) set(LOG_LIB log) endif() @@ -253,7 +253,7 @@ if(TESTNET) endif() add_library(${STATIC_LIB} STATIC ${LIB_SRC}) -target_include_directories(${STATIC_LIB} PUBLIC ${CURL_INCLUDE_DIR}) +target_include_directories(${STATIC_LIB} PUBLIC ${CURL_INCLUDE_DIRS}) target_link_libraries(${STATIC_LIB} PUBLIC cxxopts ${ABYSS_LIB} ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOGRAPHY_LIB} ${CURL_LIBRARIES}) if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") diff --git a/readme.md b/readme.md index 4c389b50e..9a82e8628 100644 --- a/readme.md +++ b/readme.md @@ -98,7 +98,7 @@ this puts the built packages in `../` static native optimized: - $ make static STATIC_LINK=ON DOWNLOAD_SODIUM=ON + $ make static STATIC_LINK=ON cross compile fully static armhf (rpi 2 and up) From 77213d7fa45d714bf77162e5f5e56c18daf336e6 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 26 Dec 2019 13:06:30 -0500 Subject: [PATCH 4/7] add hashpinned curl tarball for static build --- Makefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f9be65e99..0ad4bc737 100644 --- a/Makefile +++ b/Makefile @@ -45,8 +45,10 @@ SHADOW_OPTS ?= LIBUV_VERSION ?= v1.30.1 LIBUV_PREFIX = $(BUILD_ROOT)/libuv -LIBCURL_VERSION ?= curl-7_67_0 LIBCURL_PREFIX = $(BUILD_ROOT)/curl +LIBCURL_VERSION = 7.67.0 +LIBCURL_URL = https://github.com/curl/curl/releases/download/curl-7_67_0/curl-7.67.0.tar.xz +LIBCURL_SHA256 = f5d2e7320379338c3952dcc7566a140abb49edb575f9f99272455785c40e536c TESTNET_ROOT=/tmp/lokinet_testnet_tmp TESTNET_CONF=$(TESTNET_ROOT)/supervisor.conf @@ -223,8 +225,11 @@ static: static-configure cp $(EXE) $(REPO)/lokinet-static $(LIBCURL_PREFIX): - mkdir -p $(BUILD_ROOT) - git clone -b "$(LIBCURL_VERSION)" https://github.com/curl/curl "$(LIBCURL_PREFIX)" + mkdir -p '$(BUILD_ROOT)' + wget '$(LIBCURL_URL)' -O '$(BUILD_ROOT)/curl.tar.xz' + bash -c 'sha256sum -c <<<"$(LIBCURL_SHA256) $(BUILD_ROOT)/curl.tar.xz"' + tar -xJf '$(BUILD_ROOT)/curl.tar.xz' -C '$(BUILD_ROOT)' + mv '$(BUILD_ROOT)/curl-$(LIBCURL_VERSION)' '$(LIBCURL_PREFIX)' $(LIBUV_PREFIX): mkdir -p $(BUILD_ROOT) From 336a74869537af547073a8518c4e8a10b59b1318 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 26 Dec 2019 14:21:28 -0500 Subject: [PATCH 5/7] make it build in normal mode too --- cmake/unix.cmake | 4 +++- llarp/CMakeLists.txt | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/unix.cmake b/cmake/unix.cmake index 7b2d0c7f9..d13aa4cec 100644 --- a/cmake/unix.cmake +++ b/cmake/unix.cmake @@ -20,9 +20,11 @@ if(NOT IOS AND NOT ANDROID AND NOT WIN32) add_subdirectory(${LIBCURL_ROOT}) set(CURL_INCLUDE_DIRS ${LIBCURL_ROOT}/include) set(CURL_LIBRARIES libcurl) + set(CURL_LIB ${CURL_LIBRARIES}) set(CURL_FOUND TRUE) else() - find_package(CURL REQUIRED) + include(FindCURL) + set(CURL_LIB CURL::libcurl) endif() endif() diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 05bf7d979..81c492a84 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -69,8 +69,7 @@ if(ANDROID) endif() target_link_libraries(${UTIL_LIB} PUBLIC ${CRYPTOGRAPHY_LIB} ${LOG_LIB}) - -target_link_libraries_system(${UTIL_LIB} absl::synchronization absl::hash absl::container nlohmann_json::nlohmann_json) +target_link_libraries_system(${UTIL_LIB} absl::synchronization absl::hash absl::container nlohmann_json::nlohmann_json ${CURL_LIB}) # cut back on fluff if (NOT WIN32) From fde0ca374f5a971c6db37d46169235193f977794 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 26 Dec 2019 14:56:17 -0500 Subject: [PATCH 6/7] i hate curl --- cmake/unix.cmake | 4 +--- llarp/CMakeLists.txt | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cmake/unix.cmake b/cmake/unix.cmake index d13aa4cec..a0412d551 100644 --- a/cmake/unix.cmake +++ b/cmake/unix.cmake @@ -20,11 +20,9 @@ if(NOT IOS AND NOT ANDROID AND NOT WIN32) add_subdirectory(${LIBCURL_ROOT}) set(CURL_INCLUDE_DIRS ${LIBCURL_ROOT}/include) set(CURL_LIBRARIES libcurl) - set(CURL_LIB ${CURL_LIBRARIES}) set(CURL_FOUND TRUE) else() - include(FindCURL) - set(CURL_LIB CURL::libcurl) + set(CURL_LIBRARIES "-lcurl") endif() endif() diff --git a/llarp/CMakeLists.txt b/llarp/CMakeLists.txt index 81c492a84..9eb2b7801 100644 --- a/llarp/CMakeLists.txt +++ b/llarp/CMakeLists.txt @@ -68,8 +68,8 @@ if(ANDROID) set(LOG_LIB log) endif() -target_link_libraries(${UTIL_LIB} PUBLIC ${CRYPTOGRAPHY_LIB} ${LOG_LIB}) -target_link_libraries_system(${UTIL_LIB} absl::synchronization absl::hash absl::container nlohmann_json::nlohmann_json ${CURL_LIB}) +target_link_libraries(${UTIL_LIB} PUBLIC ${CRYPTOGRAPHY_LIB} ${LOG_LIB} ${CURL_LIBRARIES}) +target_link_libraries_system(${UTIL_LIB} absl::synchronization absl::hash absl::container nlohmann_json::nlohmann_json) # cut back on fluff if (NOT WIN32) @@ -253,7 +253,7 @@ endif() add_library(${STATIC_LIB} STATIC ${LIB_SRC}) target_include_directories(${STATIC_LIB} PUBLIC ${CURL_INCLUDE_DIRS}) -target_link_libraries(${STATIC_LIB} PUBLIC cxxopts ${ABYSS_LIB} ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOGRAPHY_LIB} ${CURL_LIBRARIES}) +target_link_libraries(${STATIC_LIB} PUBLIC cxxopts ${ABYSS_LIB} ${PLATFORM_LIB} ${UTIL_LIB} ${CRYPTOGRAPHY_LIB}) if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") target_include_directories(${PLATFORM_LIB} SYSTEM PUBLIC /usr/local/include) From da5eb913e921d1e3cce00a0bb8811cb4f57383e9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 26 Dec 2019 15:01:05 -0500 Subject: [PATCH 7/7] use proper cmake call --- cmake/unix.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/unix.cmake b/cmake/unix.cmake index a0412d551..2de048cb5 100644 --- a/cmake/unix.cmake +++ b/cmake/unix.cmake @@ -22,7 +22,7 @@ if(NOT IOS AND NOT ANDROID AND NOT WIN32) set(CURL_LIBRARIES libcurl) set(CURL_FOUND TRUE) else() - set(CURL_LIBRARIES "-lcurl") + include(FindCURL) endif() endif()