Skip to content

Commit

Permalink
Tests for builds with system sexpp library
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Jun 28, 2023
1 parent c877171 commit 9206d03
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 31 deletions.
69 changes: 50 additions & 19 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
mkdir -p "build/Testing/Temporary"
cp "cmake/CTestCostData.txt" "build/Testing/Temporary"
export PATH="$PWD/build/src/lib:$PATH"
ctest --parallel ${{ env.CORES }} --test-dir build -C Debug --output-on-failure
ctest --parallel ${{ env.CORES }} --test-dir build --output-on-failure
cmake-offline-googletest-src:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:
mkdir -p "build/Testing/Temporary"
cp "cmake/CTestCostData.txt" "build/Testing/Temporary"
export PATH="$PWD/build/src/lib:$PATH"
ctest --parallel ${{ env.CORES }} --test-dir build -C Debug --output-on-failure
ctest --parallel ${{ env.CORES }} --test-dir build --output-on-failure
- name: Check googletest
run: |
Expand Down Expand Up @@ -198,7 +198,7 @@ jobs:
mkdir -p "build/Testing/Temporary"
cp "cmake/CTestCostData.txt" "build/Testing/Temporary"
export PATH="$PWD/build/src/lib:$PATH"
ctest --parallel ${{ env.CORES }} --test-dir build -C Debug --output-on-failure
ctest --parallel ${{ env.CORES }} --test-dir build --output-on-failure
- name: Check googletest
run: |
Expand All @@ -207,40 +207,71 @@ jobs:
[ ! -d "build/src/tests/googletest-src" ]
cmake-system-sexpp:
name: system-sexpp, sexpp shared libs ${{ matrix.sexpp_shared_libs }}, rnp shared libs ${{ matrix.rnp_shared_libs }}
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
sexpp_shared_libs: [ 'on', 'off' ]
rnp_shared_libs: ['on', 'off']

steps:
- name: Checkout
- name: Install dependencies
run: |
sudo apt-get -y update
sudo apt-get -y install cmake libjson-c-dev libbotan-2-dev asciidoctor
- name: Checkout sexpp
uses: actions/checkout@v3
with:
fetch-depth: 1
submodules: true
repository: rnpgp/sexpp
path: sexpp

- name: Install dependencies
- name: Configure sexpp
run: |
sudo apt-get -y update
sudo apt-get -y install cmake libjson-c-dev libbotan-2-dev asciidoctor googletest
echo CORES="$(nproc --all)" >> $GITHUB_ENV
cmake -S sexpp -B sexpp/build \
-DCMAKE_BUILD_TYPE=Release \
-DDOWNLOAD_GTEST=OFF \
-DWITH_SEXP_TESTS=OFF \
-DBUILD_SHARED_LIBS=${{ matrix.sexpp_shared_libs}}
- name: Build sexpp
run: cmake --build sexpp/build --parallel ${{ env.CORES }}

- name: Install sexpp
run: sudo cmake --install sexpp/build

- name: Clean sexpp
run: rm -rf sexpp

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
submodules: false

- name: Configure
run: |
echo CORES="$(nproc --all)" >> $GITHUB_ENV
cmake -B build -DBUILD_SHARED_LIBS=ON \
-DCRYPTO_BACKEND=botan \
-DDOWNLOAD_GTEST=OFF \
-DSYSTEM_SEXPP=ON \
-DCMAKE_BUILD_TYPE=Release .
cmake -B build \
-DBUILD_SHARED_LIBS=${{ matrix.rnp_shared_libs }} \
-DCRYPTO_BACKEND=botan \
-DDOWNLOAD_GTEST=ON \
-DSYSTEM_LIBSEXPP=ON \
-DCMAKE_BUILD_TYPE=Release .
- name: Build
run: cmake --build build --parallel ${{ env.CORES }}

- name: Test
run: |
mkdir -p "build/Testing/Temporary"
cp "cmake/CTestCostData.txt" "build/Testing/Temporary"
export PATH="$PWD/build/src/lib:$PATH"
ctest --parallel ${{ env.CORES }} --test-dir build -C Debug --output-on-failure
ctest --parallel ${{ env.CORES }} --test-dir build -R rnp_tests --output-on-failure
package-source:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"
Expand Down
31 changes: 24 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ option(ENABLE_COVERAGE "Enable code coverage testing.")
option(ENABLE_SANITIZERS "Enable ASan and other sanitizers.")
option(ENABLE_FUZZERS "Enable fuzz targets.")
option(DOWNLOAD_GTEST "Download Googletest" On)
option(SYSTEM_LIBSEXP "Use system sexp library" OFF)
option(SYSTEM_LIBSEXPP "Use system sexpp library" OFF)

# crypto components
function(tristate_feature_auto NAME DESCRIPTION)
Expand Down Expand Up @@ -184,19 +184,36 @@ if (ENABLE_FUZZERS)
endif()
add_subdirectory(src/common)

if (SYSTEM_LIBSEXP)
find_package(PkgConfig)
pkg_check_modules(REQUIRED sexpp>=0.8.5)
else (SYSTEM_LIBSEXP)
# force static libsexpp
if (SYSTEM_LIBSEXPP)
find_package(PkgConfig QUIET)
pkg_check_modules(SEXPP sexpp>=0.8.7 REQUIRED)
find_library(SEXPP_LIBRARY
NAMES
"libsexpp"
"sexpp"
HINTS
"${SEXPP_LIBRARY_DIRS}"
)
add_library(sexpp UNKNOWN IMPORTED)
set_target_properties(sexpp
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SEXPP_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${SEXPP_LIBRARY}"
)
else (SYSTEM_LIBSEXPP)
# If we use system libsexpp is not used we build sexpp static library
# If librnp is shared, libsexpp.a is a transient artifact which is hidden from
# the end user.
# If librnp is static we install libsexpp.a aside
set(SAVED_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF)
set(WITH_SEXP_CLI OFF)
set(WITH_SEXP_TESTS OFF)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME development)
add_subdirectory(src/libsexpp EXCLUDE_FROM_ALL)
set(BUILD_SHARED_LIBS ${SAVED_BUILD_SHARED_LIBS})
endif (SYSTEM_LIBSEXP)
endif (SYSTEM_LIBSEXPP)

add_subdirectory(src/lib)
add_subdirectory(src/rnp)
Expand Down
21 changes: 16 additions & 5 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ target_include_directories(librnp-obj
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/src"
"${SEXPP_INCLUDE_DIRS}"
)
target_link_libraries(librnp-obj PRIVATE JSON-C::JSON-C)
if (CRYPTO_BACKEND_BOTAN)
Expand Down Expand Up @@ -431,8 +432,8 @@ endif()
# On Unix like systems we will build/install/pack either shared library librnp.so or static librnp.a
# On Windows we will build/install/pack either dynamic and import libraries rnp.dll, rnp.lib or static library rnp-static.lib

# If a client application uses shared rnp library, sexp is statically linked to librnp.so and libsexp.a is not installed
# If a client application uses static rnp library, it still needs libsexp.a and it is installed
# If a client application uses shared rnp library, sexpp is statically linked to librnp.so and libsexpp.a is not installed
# If a client application uses static rnp library, it still needs libsexpp.a and it is installed

if (BUILD_SHARED_LIBS)
install(TARGETS librnp
Expand All @@ -455,13 +456,23 @@ if (BUILD_SHARED_LIBS)
)
endif(WIN32)
else(BUILD_SHARED_LIBS)
# static libraries only
install(TARGETS librnp sexpp
# static libraries
# install libsexpp unless system-installed libsexpp is used
if (SYSTEM_LIBSEXPP)
install(TARGETS librnp
EXPORT rnp-targets
ARCHIVE
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT development
)
else (SYSTEM_LIBSEXPP)
install(TARGETS librnp sexpp
EXPORT rnp-targets
ARCHIVE
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT development
)
)
endif (SYSTEM_LIBSEXPP)
endif(BUILD_SHARED_LIBS)

# install headers
Expand Down
1 change: 1 addition & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ target_include_directories(rnp_tests
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/src/lib"
"${BOTAN_INCLUDE_DIRS}"
"${SEXPP_INCLUDE_DIRS}"
)
target_link_libraries(rnp_tests
PRIVATE
Expand Down

0 comments on commit 9206d03

Please sign in to comment.