From 2da8b112b2316cf1f4391c35cf50cd64ce0befdb Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Wed, 18 Dec 2024 00:01:24 +0100 Subject: [PATCH] CI: windows get boost via vcpkg --- .github/workflows/build.yml | 18 ++++++++++++++++++ server/CMakeLists.txt | 13 +++++++++++-- server/src/utils/sha1.cpp | 8 ++++++-- server/vcpkg-configuration.json | 14 ++++++++++++++ server/vcpkg.json | 10 ++++++++++ 5 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 server/vcpkg-configuration.json create mode 100644 server/vcpkg.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d3341a4..4467a4bb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -164,6 +164,8 @@ jobs: build-server: name: server ${{matrix.config.name}} runs-on: ${{matrix.config.os}} + env: + VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" strategy: fail-fast: false matrix: @@ -285,6 +287,22 @@ jobs: with: submodules: recursive + - name: Export GitHub Actions cache environment variables + uses: actions/github-script@v7 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + + - name: Set VCPKG_ROOT + uses: actions/github-script@v7 + with: + script: | + if(core.isWindows) + { + core.exportVariable('VCPKG_ROOT', process.env.VCPKG_INSTALLATION_ROOT || ''); + } + # Ubuntu only: - name: apt update if: startswith(matrix.config.os, 'ubuntu') diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 7a102800..25e6367a 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 3.15) include(../shared/traintastic.cmake) project(traintastic-server VERSION ${TRAINTASTIC_VERSION} DESCRIPTION "Traintastic server") include(GNUInstallDirs) @@ -194,6 +194,15 @@ file(GLOB TEST_SOURCES set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DENABLE_LOG_DEBUG") +### VCPKG +if(DEFINED ENV{VCPKG_ROOT}) + message(STATUS "Using VCPKG (VCPKG_ROOT=$ENV{VCPKG_ROOT})") + if(WIN32) + set(VCPKG_TARGET_TRIPLET "x64-windows-static-md") + endif() + include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) +endif() + ### OPTIONS ### if(NO_LOCALHOST_ONLY_SETTING) @@ -285,7 +294,7 @@ if(WIN32 AND NOT MSVC) endif() # boost -if(LINUX) +if(LINUX OR WIN32) find_package(Boost 1.81 REQUIRED COMPONENTS program_options) target_include_directories(traintastic-server SYSTEM PRIVATE ${Boost_INCLUDE_DIRS}) diff --git a/server/src/utils/sha1.cpp b/server/src/utils/sha1.cpp index b370f76f..829ae38c 100644 --- a/server/src/utils/sha1.cpp +++ b/server/src/utils/sha1.cpp @@ -29,7 +29,9 @@ Sha1::Digest Sha1::of(const std::string& value) boost::uuids::detail::sha1 sha1; sha1.process_bytes(value.c_str(), value.size()); Digest digest; - sha1.get_digest(digest.m_hash); + boost::uuids::detail::sha1::digest_type tmp; + sha1.get_digest(tmp); + std::memcpy(digest.m_hash, tmp, sizeof(tmp)); // FIXME: get rid of this copy return digest; } @@ -51,6 +53,8 @@ Sha1::Digest Sha1::of(const std::filesystem::path& filename) return Digest::null(); Digest digest; - sha1.get_digest(digest.m_hash); + boost::uuids::detail::sha1::digest_type tmp; + sha1.get_digest(tmp); + std::memcpy(digest.m_hash, tmp, sizeof(tmp)); // FIXME: get rid of this copy return digest; } diff --git a/server/vcpkg-configuration.json b/server/vcpkg-configuration.json new file mode 100644 index 00000000..d43be883 --- /dev/null +++ b/server/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "b322364f06308bdd24823f9d8f03fe0cc86fd46f", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} diff --git a/server/vcpkg.json b/server/vcpkg.json new file mode 100644 index 00000000..0999d1da --- /dev/null +++ b/server/vcpkg.json @@ -0,0 +1,10 @@ +{ + "dependencies": [ + "boost-asio", + "boost-beast", + "boost-program-options", + "boost-random", + "boost-signals2", + "boost-uuid" + ] +}