From 88062a618cc69dfb09385aa15cc742dfe96b81ca Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 17 Nov 2023 21:14:30 -0400 Subject: [PATCH] Fix GitHub Actions Signed-off-by: Juan Cruz Viotti --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 6 ++++++ cmake/VCPKG.cmake | 18 ++++++++++++++++++ config.cmake.in | 1 + src/http/CMakeLists.txt | 2 +- .../include/sourcemeta/hydra/http_status.h | 10 +++++++++- src/http/stream_curl.cc | 5 ----- vcpkg.json | 3 +++ 8 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 cmake/VCPKG.cmake create mode 100644 vcpkg.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9f03af7..9e07a4ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: steps: - name: Install dependencies (GNU/Linux) if: runner.os == 'linux' - run: sudo apt-get install --yes clang-format + run: sudo apt-get install --yes clang-format libcurl4-openssl-dev # See https://github.com/actions/runner-images/issues/8659 - name: Workaround Clang issue (GNU/Linux) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1081996a..5e3d4ce0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,10 @@ cmake_minimum_required(VERSION 3.24) + +# Needs to happen before the first call to "project()". +if(WIN32) + include(cmake/VCPKG.cmake) +endif() + project(hydra VERSION 0.0.1 LANGUAGES CXX DESCRIPTION "A convenience networking library for modern C++") list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") diff --git a/cmake/VCPKG.cmake b/cmake/VCPKG.cmake new file mode 100644 index 00000000..de921ec9 --- /dev/null +++ b/cmake/VCPKG.cmake @@ -0,0 +1,18 @@ +# TODO: Move this to Noa +if(DEFINED ENV{VCPKG_ROOT}) + set(VCPKG_CMAKE_TOOLCHAIN $ENV{VCPKG_ROOT}) + cmake_path(APPEND VCPKG_CMAKE_TOOLCHAIN scripts buildsystems vcpkg.cmake) +else() + # Attempt to find vcpkg from standard locations + # Useful for GitHub Actions, which does not set VCPKG_ROOT + find_file(VCPKG_CMAKE_TOOLCHAIN + NAMES scripts/buildsystems/vcpkg.cmake + PATHS C:/src/vcpkg C:/dev/vcpkg C:/vcpkg + NO_DEFAULT_PATH) +endif() +if(EXISTS "${VCPKG_CMAKE_TOOLCHAIN}") + message(STATUS "Using VCPKG toolchain: ${VCPKG_CMAKE_TOOLCHAIN}") + set(CMAKE_TOOLCHAIN_FILE "${VCPKG_CMAKE_TOOLCHAIN}" CACHE STRING "VCPKG toolchain file") +else() + message(FATAL_ERROR "Could NOT find VCPKG") +endif() diff --git a/config.cmake.in b/config.cmake.in index 6de59708..a8e9d6d7 100644 --- a/config.cmake.in +++ b/config.cmake.in @@ -8,5 +8,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") find_package(Threads REQUIRED) endif() +find_package(CURL REQUIRED) include("${CMAKE_CURRENT_LIST_DIR}/sourcemeta_hydra_http.cmake") check_required_components("@PROJECT_NAME@") diff --git a/src/http/CMakeLists.txt b/src/http/CMakeLists.txt index 45f9cb20..21767ab5 100644 --- a/src/http/CMakeLists.txt +++ b/src/http/CMakeLists.txt @@ -25,7 +25,7 @@ set_target_properties(sourcemeta_hydra_http PROPERTIES EXPORT_NAME hydra::http FOLDER "Hydra/HTTP") -target_link_libraries(sourcemeta_hydra_http PRIVATE curl) +target_link_libraries(sourcemeta_hydra_http PRIVATE CURL::libcurl) include(GenerateExportHeader) generate_export_header(sourcemeta_hydra_http diff --git a/src/http/include/sourcemeta/hydra/http_status.h b/src/http/include/sourcemeta/hydra/http_status.h index 85a93d46..780f0a1a 100644 --- a/src/http/include/sourcemeta/hydra/http_status.h +++ b/src/http/include/sourcemeta/hydra/http_status.h @@ -1,6 +1,12 @@ #ifndef SOURCEMETA_HYDRA_HTTP_STATUS_H #define SOURCEMETA_HYDRA_HTTP_STATUS_H +#if defined(__EMSCRIPTEN__) || defined(__Unikraft__) +#define SOURCEMETA_HYDRA_HTTP_EXPORT +#else +#include "http_export.h" +#endif + #include // std::uint16_t #include // std::ostream @@ -81,7 +87,9 @@ enum class Status : std::uint16_t { NETWORK_AUTHENTICATION_REQUIRED = 511 }; -auto operator<<(std::ostream &stream, const Status value) -> std::ostream &; +auto SOURCEMETA_HYDRA_HTTP_EXPORT operator<<(std::ostream &stream, + const Status value) + -> std::ostream &; } // namespace sourcemeta::hydra::http diff --git a/src/http/stream_curl.cc b/src/http/stream_curl.cc index 78b559fa..e5ea86cc 100644 --- a/src/http/stream_curl.cc +++ b/src/http/stream_curl.cc @@ -254,11 +254,6 @@ auto Stream::send() -> std::future { handle_curl(curl_easy_setopt(this->internal->handle, CURLOPT_HTTPHEADER, this->internal->headers)); - // This tells libcurl the maximum time any cached certificate store it has in - // memory may be kept and reused for new connections. - handle_curl(curl_easy_setopt(this->internal->handle, CURLOPT_CA_CACHE_TIMEOUT, - 604800L)); - handle_curl(curl_easy_setopt(this->internal->handle, CURLOPT_WRITEFUNCTION, callback_on_body)); handle_curl( diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 00000000..8383b07e --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,3 @@ +{ + "dependencies": [ "curl" ] +}