From d5c805dd4108a147984d2bd4b920b9323f1fe38a Mon Sep 17 00:00:00 2001 From: Alexande B Date: Sat, 13 Nov 2021 08:27:58 +0100 Subject: [PATCH] #1648 building dependencies with vcpkg (skip ci) --- .github/workflows/centos7.yml | 4 +- .github/workflows/centos8-ossl.yml | 2 +- .github/workflows/centos8.yml | 2 +- .github/workflows/debian9.yml | 2 +- .github/workflows/macos.yml | 2 +- .github/workflows/ubuntu.yml | 62 +++++++++++--------- .github/workflows/windows-msys2.yml | 2 +- ci/build_package_deb.sh | 16 ++++++ ci/main.sh | 22 ++++++-- cmake/Modules/FindBotan2.cmake | 2 + src/examples/CMakeLists.txt | 87 ++++------------------------- src/lib/CMakeLists.txt | 16 ++++++ 12 files changed, 106 insertions(+), 113 deletions(-) create mode 100755 ci/build_package_deb.sh diff --git a/.github/workflows/centos7.yml b/.github/workflows/centos7.yml index b2d763aaba..37b33d98c7 100644 --- a/.github/workflows/centos7.yml +++ b/.github/workflows/centos7.yml @@ -29,7 +29,7 @@ env: jobs: tests: runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: false container: image: ${{ matrix.env.IMAGE }} timeout-minutes: 70 @@ -127,7 +127,7 @@ jobs: [ $(grep -c rnp_version_string_full exports) == "1" ] pkgconfig-cmake-target: runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: false container: image: centos:7 timeout-minutes: 10 diff --git a/.github/workflows/centos8-ossl.yml b/.github/workflows/centos8-ossl.yml index c7623a8f6d..71d05fc7ee 100644 --- a/.github/workflows/centos8-ossl.yml +++ b/.github/workflows/centos8-ossl.yml @@ -28,7 +28,7 @@ env: jobs: tests: runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: false container: image: ${{ matrix.env.IMAGE }} timeout-minutes: 70 diff --git a/.github/workflows/centos8.yml b/.github/workflows/centos8.yml index 48ed045330..d25db003ea 100644 --- a/.github/workflows/centos8.yml +++ b/.github/workflows/centos8.yml @@ -28,7 +28,7 @@ env: jobs: tests: runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: false container: image: ${{ matrix.env.IMAGE }} timeout-minutes: 70 diff --git a/.github/workflows/debian9.yml b/.github/workflows/debian9.yml index c8636bcf03..c291006be5 100644 --- a/.github/workflows/debian9.yml +++ b/.github/workflows/debian9.yml @@ -33,7 +33,7 @@ jobs: tests: name: ${{ matrix.env.IMAGE }} [CC ${{ matrix.env.CC }}; GnuPG stable] runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: false container: image: ${{ matrix.env.IMAGE }} timeout-minutes: 120 diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index d37d537471..134a91db14 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -36,7 +36,7 @@ jobs: CXX: g++ - CC: clang CXX: clang++ - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: false env: ${{ matrix.env }} timeout-minutes: 250 steps: diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 5271e04b63..78104c554b 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -22,11 +22,14 @@ env: BUILD_MODE: normal GPG_VERSION: stable USE_STATIC_DEPENDENCIES: yes + VCPKG_ROOT: '/usr/local/share/vcpkg' jobs: tests: - name: ${{ matrix.os }} [CC ${{ matrix.env.CC }}; GnuPG stable] + name: ${{ matrix.triplet }} ${{ matrix.build_type }} ${{ matrix.env.CC }}; GnuPG stable runs-on: ${{ matrix.os }} + if: "!contains(github.event.head_commit.message, 'skip ci')" + timeout-minutes: 50 strategy: fail-fast: false matrix: @@ -36,43 +39,48 @@ jobs: CXX: g++ - CC: clang CXX: clang++ - if: "!contains(github.event.head_commit.message, 'skip ci')" + triplet: [x64-linux, x64-linux-dynamic] + build_type: [Release, Debug] env: ${{ matrix.env }} - timeout-minutes: 50 steps: - uses: actions/checkout@v2 with: fetch-depth: 1 - - name: Setup environment - run: | + + - run: | . ci/gha/setup-env.inc.sh ci/install_noncacheable_dependencies.sh - - name: Cache - id: cache + + - if: matrix.triplet == 'x64-linux-dynamic' + run: | + cp ${{ env.VCPKG_ROOT }}/triplets/x64-linux.cmake ${{ env.VCPKG_ROOT }}/triplets/x64-linux-dynamic.cmake + sed -i -- 's/static/dynamic/g' ${{ env.VCPKG_ROOT }}/triplets/x64-linux-dynamic.cmake + + - id: vcpkg-cache uses: actions/cache@v2 with: - path: ${{ env.CACHE_DIR }} - key: ${{ github.workflow }}-${{ runner.os }}-${{ env.BUILD_MODE }}-${{ matrix.env.CC }}-gpg-${{ env.GPG_VERSION }}-${{ hashFiles('ci/**') }}-${{ hashFiles('.github/workflows/**') }} - - name: Build cache - if: steps.cache.outputs.cache-hit != 'true' - run: | - set -x - ci/install_cacheable_dependencies.sh - - name: tests - run: | - set -x - ci/run.sh - - name: Package - run: | - set -x - cd ${LOCAL_BUILDS}/rnp-build - cpack -G DEB -D CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS="${BOTAN_INSTALL}/lib;${JSONC_INSTALL}/lib;${GPG_INSTALL}/lib" + path: ${{ env.VCPKG_ROOT }}/installed + key: vcpkg-${{ matrix.os }}-${{ hashFiles('vcpkg.txt') }}-${{ matrix.triplet }} + + - if: steps.vcpkg-cache.outputs.cache-hit != 'true' + run: vcpkg install --triplet ${{ matrix.triplet }} $(cat vcpkg.txt) + + - run: ci/run.sh + env: + BUILD_TYPE: ${{ matrix.build_type }} + VCPKG_TRIPLET: ${{ matrix.triplet }} + + - run: ci/build_package_deb.sh + env: + BUILD_TYPE: ${{ matrix.build_type }} + VCPKG_TRIPLET: ${{ matrix.triplet }} + cmake-offline-googletest-src: env: GTEST_SOURCES: /usr/src/googletest RNP_TESTS: rnp_tests runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: false timeout-minutes: 30 steps: - uses: actions/checkout@v2 @@ -106,7 +114,7 @@ jobs: DOWNLOAD_GTEST: Off RNP_TESTS: rnp_tests runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: false timeout-minutes: 50 steps: - uses: actions/checkout@v2 @@ -149,7 +157,7 @@ jobs: DOWNLOAD_RUBYRNP: Off RNP_TESTS: rnp_tests.hash_test_success runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: false timeout-minutes: 50 steps: - uses: actions/checkout@v2 @@ -179,7 +187,7 @@ jobs: ! ls -la src/tests/ | grep 'ruby' > /dev/null version-cmake-up-to-date: runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: false timeout-minutes: 10 steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/windows-msys2.yml b/.github/workflows/windows-msys2.yml index b3140b8cac..c1c35557e9 100644 --- a/.github/workflows/windows-msys2.yml +++ b/.github/workflows/windows-msys2.yml @@ -26,7 +26,7 @@ jobs: tests: name: ${{ matrix.os }} msys2 [CC ${{ matrix.env.CC }}; GnuPG stable] runs-on: ${{ matrix.os }} - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: false timeout-minutes: 70 strategy: fail-fast: false diff --git a/ci/build_package_deb.sh b/ci/build_package_deb.sh new file mode 100755 index 0000000000..65d7030b20 --- /dev/null +++ b/ci/build_package_deb.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euxo pipefail + +main() { + pushd "${LOCAL_BUILDS}/rnp-build" + local build_type_subdir + if [[ "${BUILD_TYPE}" == "Debug" ]]; then + build_type_subdir="/debug" + else + build_type_subdir="" + fi + cpack -G DEB -D CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS="${VCPKG_ROOT}/installed/${VCPKG_TRIPLET}${build_type_subdir}/lib" + popd +} + +main "$@" diff --git a/ci/main.sh b/ci/main.sh index 355d06efab..17e2996f5f 100755 --- a/ci/main.sh +++ b/ci/main.sh @@ -13,6 +13,7 @@ set -eux : "${DIST_VERSION:=}" : "${SKIP_TESTS:=0}" +: "${BUILD_TYPE:=Release}" prepare_build_prerequisites() { CMAKE=cmake @@ -32,11 +33,19 @@ prepare_build_prerequisites() { prepare_test_env() { prepare_build_tool_env - export LD_LIBRARY_PATH="${GPG_INSTALL}/lib:${BOTAN_INSTALL}/lib:${JSONC_INSTALL}/lib:${RNP_INSTALL}/lib:$LD_LIBRARY_PATH" + if [[ "${BUILD_TYPE}" == "Debug" ]]; then + build_type_subdir="/debug" + else + build_type_subdir="" + fi + + lib_path="${VCPKG_ROOT}/installed/${VCPKG_TRIPLET}${build_type_subdir}/lib" + + export LD_LIBRARY_PATH="${lib_path}" # update dll search path for windows if [[ "${OS}" = "msys" ]]; then - export PATH="${LOCAL_BUILDS}/rnp-build/lib:${LOCAL_BUILDS}/rnp-build/bin:${LOCAL_BUILDS}/rnp-build/src/lib:${BOTAN_INSTALL}/bin:$PATH" + export PATH="${lib_path}:$PATH" fi } @@ -81,11 +90,16 @@ main() { pushd "${LOCAL_BUILDS}/rnp-build" cmakeopts=( - -DCMAKE_BUILD_TYPE=Release # RelWithDebInfo -- DebInfo commented out to speed up recurring CI runs. + -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" # RelWithDebInfo -- DebInfo commented out to speed up recurring CI runs. -DBUILD_SHARED_LIBS=yes -DCMAKE_INSTALL_PREFIX="${RNP_INSTALL}" - -DCMAKE_PREFIX_PATH="${BOTAN_INSTALL};${JSONC_INSTALL};${GPG_INSTALL}" ) + + [ -n "${VCPKG_TRIPLET:-}" ] && [ -n "${VCPKG_ROOT:-}" ] && { + cmakeopts+=(-DVCPKG_TARGET_TRIPLET="${VCPKG_TRIPLET}") + cmakeopts+=(-DCMAKE_TOOLCHAIN_FILE="${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") + } + [[ ${SKIP_TESTS} = 1 ]] && cmakeopts+=(-DBUILD_TESTING=OFF) [[ "${BUILD_MODE}" = "coverage" ]] && cmakeopts+=(-DENABLE_COVERAGE=yes) [[ "${BUILD_MODE}" = "sanitize" ]] && cmakeopts+=(-DENABLE_SANITIZERS=yes) diff --git a/cmake/Modules/FindBotan2.cmake b/cmake/Modules/FindBotan2.cmake index 2708491947..f5c783111f 100644 --- a/cmake/Modules/FindBotan2.cmake +++ b/cmake/Modules/FindBotan2.cmake @@ -116,6 +116,8 @@ if (BOTAN2_FOUND AND NOT TARGET Botan2::Botan2) PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${BOTAN2_INCLUDE_DIRS}" ) + # https://gitlab.kitware.com/cmake/cmake/-/issues/15052 + file(MAKE_DIRECTORY ${BOTAN2_INCLUDE_DIRS}) endif() # set the required libraries for the target if (EXISTS "${BOTAN2_LIBRARY}") diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index 122b1e4417..b0140f7f55 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -44,83 +44,20 @@ if(MSVC) ) endif() -add_executable(generate generate.c) +foreach(exe_name generate encrypt decrypt sign verify dump) + add_executable(${exe_name} ${exe_name}.c) -target_include_directories(generate - PRIVATE - "${PROJECT_SOURCE_DIR}/src" - "${PROJECT_SOURCE_DIR}/src/lib" -) - -target_link_libraries(generate - PRIVATE - librnp -) - -add_executable(encrypt encrypt.c) - -target_include_directories(encrypt - PRIVATE - "${PROJECT_SOURCE_DIR}/src" - "${PROJECT_SOURCE_DIR}/src/lib" -) - -target_link_libraries(encrypt - PRIVATE - librnp -) - -add_executable(decrypt decrypt.c) - -target_include_directories(decrypt - PRIVATE - "${PROJECT_SOURCE_DIR}/src" - "${PROJECT_SOURCE_DIR}/src/lib" -) - -target_link_libraries(decrypt - PRIVATE - librnp -) - -add_executable(sign sign.c) - -target_include_directories(sign - PRIVATE - "${PROJECT_SOURCE_DIR}/src" - "${PROJECT_SOURCE_DIR}/src/lib" -) - -target_link_libraries(sign - PRIVATE - librnp -) - -add_executable(verify verify.c) - -target_include_directories(verify - PRIVATE - "${PROJECT_SOURCE_DIR}/src" - "${PROJECT_SOURCE_DIR}/src/lib" -) - -target_link_libraries(verify - PRIVATE - librnp -) - -add_executable(dump dump.c) - -target_include_directories(dump - PRIVATE - "${PROJECT_SOURCE_DIR}/src" - "${PROJECT_SOURCE_DIR}/src/lib" -) + target_include_directories(${exe_name} + PRIVATE + "${PROJECT_SOURCE_DIR}/src" + "${PROJECT_SOURCE_DIR}/src/lib" + ) -target_link_libraries(dump - PRIVATE - librnp -) + target_link_libraries(${exe_name} + PRIVATE + librnp + ) +endforeach() if(MSVC) target_include_directories(dump diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index e31990cf06..58b55b0925 100755 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -259,6 +259,22 @@ else() add_library(librnp-static ALIAS librnp) endif() +if (BOTAN2_LIBRARY MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$") + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") + # /usr/bin/ld: libbotan-2.a(src_lib_utils_thread_utils_thread_pool.o): + # in function `std::thread::thread( + # void (Botan::Thread_Pool::*&&)(), Botan::Thread_Pool*&&)': + # /usr/include/c++/9/thread:126: undefined reference to `pthread_create' + # target_link_options(librnp-obj INTERFACE -pthread) + if (BUILD_SHARED_LIBS) + target_link_options(librnp-static INTERFACE -pthread) + target_link_options(librnp PRIVATE -pthread) + else() + target_link_options(librnp INTERFACE -pthread) + endif() + endif() +endif() + foreach (prop LINK_LIBRARIES INTERFACE_LINK_LIBRARIES INCLUDE_DIRECTORIES INTERFACE_INCLUDE_DIRECTORIES) get_target_property(val librnp-obj ${prop}) set_property(TARGET librnp PROPERTY ${prop} ${val})