From 5ec2c10cd39bc2c0e9d858ab20f6eda4a3777760 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 22:25:51 +0200 Subject: [PATCH 01/36] Add CI workflow for build and test automation --- .github/workflows/build-test-check.yml | 97 ++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 .github/workflows/build-test-check.yml diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml new file mode 100644 index 0000000..2acb8c1 --- /dev/null +++ b/.github/workflows/build-test-check.yml @@ -0,0 +1,97 @@ +name: CI Build and Test + +on: + pull_request: + branches: [ main, develop ] + +jobs: + build-and-test: + strategy: + matrix: + config: + - name: "Release Static" + build_type: "Release" + conan_profile: "Release" + cmake_preset: "unix-rel-ninja" + shared: false + - name: "Release Shared" + build_type: "Release" + conan_profile: "Release" + cmake_preset: "unix-rel-ninja" # Will be modified for shared + shared: true + - name: "Debug Static" + build_type: "Debug" + conan_profile: "Debug" + cmake_preset: "unix-deb-ninja" + shared: false + - name: "Debug Shared" + build_type: "Debug" + conan_profile: "Debug" + cmake_preset: "unix-deb-ninja" # Will be modified for shared + shared: true + + runs-on: ubuntu-latest + name: ${{ matrix.config.name }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y ninja-build clang-17 clang++-17 + + - name: Install Conan + run: | + python -m pip install --upgrade pip + pip install conan + + - name: Configure Conan + run: | + conan profile detect --force + + - name: Install dependencies with Conan + run: | + conan install . -s build_type=${{ matrix.config.conan_profile }} -of=conan/${{ matrix.config.build_type == 'Debug' && 'debug' || 'release' }} --build=missing + + - name: Set up CMake preset name + id: cmake_preset + run: | + if [ "${{ matrix.config.shared }}" = "true" ]; then + # For shared builds, we need to use the shared presets (though they don't exist in the current config) + # We'll use the regular presets and override BUILD_SHARED_LIBS + echo "preset=${{ matrix.config.cmake_preset }}" >> $GITHUB_OUTPUT + echo "shared_flag=-DBUILD_SHARED_LIBS=ON" >> $GITHUB_OUTPUT + else + echo "preset=${{ matrix.config.cmake_preset }}" >> $GITHUB_OUTPUT + echo "shared_flag=-DBUILD_SHARED_LIBS=OFF" >> $GITHUB_OUTPUT + fi + + - name: Configure CMake + run: | + cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} + + - name: Build project + run: | + cmake --build --preset ${{ matrix.config.build_type == 'Debug' && 'unix-deb-ninja' || 'unix-rel-ninja' }} + + - name: Run tests + run: | + cd build/${{ matrix.config.cmake_preset }} + ctest --output-on-failure --parallel $(nproc) + + - name: Upload build artifacts (on failure) + if: failure() + uses: actions/upload-artifact@v4 + with: + name: build-logs-${{ matrix.config.name }} + path: | + build/ + !build/**/CMakeFiles/ + retention-days: 7 \ No newline at end of file From 9abb4ed6e17dc82bc12b3bba7729adb7c622c221 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 22:30:56 +0200 Subject: [PATCH 02/36] Refactor CI workflow to comment out unused build configurations and improve CMake configuration step --- .github/workflows/build-test-check.yml | 38 +++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 2acb8c1..bdbb57c 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -9,26 +9,26 @@ jobs: strategy: matrix: config: - - name: "Release Static" - build_type: "Release" - conan_profile: "Release" - cmake_preset: "unix-rel-ninja" - shared: false + # - name: "Release Static" + # build_type: "Release" + # conan_profile: "Release" + # cmake_preset: "unix-rel-ninja" + # shared: false - name: "Release Shared" build_type: "Release" conan_profile: "Release" cmake_preset: "unix-rel-ninja" # Will be modified for shared shared: true - - name: "Debug Static" - build_type: "Debug" - conan_profile: "Debug" - cmake_preset: "unix-deb-ninja" - shared: false - - name: "Debug Shared" - build_type: "Debug" - conan_profile: "Debug" - cmake_preset: "unix-deb-ninja" # Will be modified for shared - shared: true + # - name: "Debug Static" + # build_type: "Debug" + # conan_profile: "Debug" + # cmake_preset: "unix-deb-ninja" + # shared: false + # - name: "Debug Shared" + # build_type: "Debug" + # conan_profile: "Debug" + # cmake_preset: "unix-deb-ninja" # Will be modified for shared + # shared: true runs-on: ubuntu-latest name: ${{ matrix.config.name }} @@ -75,7 +75,13 @@ jobs: - name: Configure CMake run: | - cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} + # Add the conan toolchain file for all builds + if [ "${{ matrix.config.build_type }}" = "Debug" ]; then + TOOLCHAIN_FILE="${{ github.workspace }}/conan/debug/build/generators/conan_toolchain.cmake" + else + TOOLCHAIN_FILE="${{ github.workspace }}/conan/release/build/generators/conan_toolchain.cmake" + fi + cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" - name: Build project run: | From 81df32f232c049f5ec20127a1b855a8eb2b70ca6 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 22:48:00 +0200 Subject: [PATCH 03/36] Update task labels and add new build configurations for server and tests in CMake and VSCode --- .vscode/tasks.json | 50 ++++++++++++++++++++++++++++++++++++++++++---- CMakePresets.json | 21 ++++++++++++------- README.md | 3 +++ 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index bd55ffb..6812b4e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,7 +2,7 @@ "version": "2.0.0", "tasks": [ { - "label": "Run Server (Static)", + "label": "Run Server Debug (Static)", "type": "shell", "command": "./bankid_server.exe", "options": { @@ -12,7 +12,7 @@ "isBackground": true }, { - "label": "Run Server (Shared)", + "label": "Run Server Debug (Shared)", "type": "shell", "command": "./bankid_server.exe", "group": "test", @@ -22,7 +22,27 @@ "isBackground": true }, { - "label": "Run Tests (Static)", + "label": "Run Server Release (Static)", + "type": "shell", + "command": "./bankid_server.exe", + "options": { + "cwd": "${workspaceFolder}/build/vs2022-rel/server/Release" + }, + "group": "test", + "isBackground": true + }, + { + "label": "Run Server Release (Shared)", + "type": "shell", + "command": "./bankid_server.exe", + "group": "test", + "options": { + "cwd": "${workspaceFolder}/build/vs2022-rel-shared/server/Release" + }, + "isBackground": true + }, + { + "label": "Run Tests Debug (Static)", "type": "shell", "command": "./bankid_tests.exe", "options": { @@ -33,7 +53,7 @@ "problemMatcher": [] }, { - "label": "Run Tests (Shared)", + "label": "Run Tests Debug (Shared)", "type": "shell", "command": "./bankid_tests.exe", "options": { @@ -43,5 +63,27 @@ "dependsOn": "Build Tests (Shared)", "problemMatcher": [] }, + { + "label": "Run Tests Release (Static)", + "type": "shell", + "command": "./bankid_tests.exe", + "options": { + "cwd": "${workspaceFolder}/build/vs2022-rel/tests/Release" + }, + "group": "test", + "dependsOn": "Build Tests", + "problemMatcher": [] + }, + { + "label": "Run Tests Release (Shared)", + "type": "shell", + "command": "./bankid_tests.exe", + "options": { + "cwd": "${workspaceFolder}/build/vs2022-rel-shared/tests/Release" + }, + "group": "test", + "dependsOn": "Build Tests (Shared)", + "problemMatcher": [] + } ] } diff --git a/CMakePresets.json b/CMakePresets.json index bcd5289..f6990bf 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,12 +2,19 @@ "version": 2, "configurePresets": [ { - "name": "conan-deb", + "name": "conan-dev", "hidden": true, "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/conan/debug/build/generators/conan_toolchain.cmake" } }, + { + "name": "conan-deb-real", + "hidden": true, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/conan/release/build/generators/conan_toolchain.cmake" + } + }, { "name": "rel", "hidden": true, @@ -106,7 +113,7 @@ "name": "unix-deb", "displayName": "Unix Make Debug", "binaryDir": "${sourceDir}/build/unix-deb", - "inherits": ["unix-make", "deb", "conan-deb"], + "inherits": ["unix-make", "deb", "conan-dev"], "cacheVariables": { "CMAKE_CXX_FLAGS": "-O0 --coverage -g -fsanitize=address", "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb/install" @@ -116,7 +123,7 @@ "name": "unix-deb-ninja", "displayName": "Unix Ninja Clang Debug", "binaryDir": "${sourceDir}/build/unix-deb-ninja", - "inherits": ["unix-ninja", "deb", "conan-deb"], + "inherits": ["unix-ninja", "deb", "conan-dev"], "cacheVariables": { "CMAKE_CXX_FLAGS": "-O0 --coverage -g -fsanitize=address", "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb-ninja/install" @@ -135,7 +142,7 @@ "name": "vs2022-rel", "displayName": "Visual Studio 2022 Release", "binaryDir": "${sourceDir}/build/vs2022-rel", - "inherits": ["vs2022", "rel"], + "inherits": ["vs2022", "rel", "conan-deb-real"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-rel/install" } @@ -144,7 +151,7 @@ "name": "vs2022-deb", "displayName": "Visual Studio 2022 Debug", "binaryDir": "${sourceDir}/build/vs2022-deb", - "inherits": ["vs2022", "deb", "conan-deb"], + "inherits": ["vs2022", "deb", "conan-dev"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-deb/install" } @@ -153,7 +160,7 @@ "name": "vs2022-rel-shared", "displayName": "Visual Studio 2022 Release Shared", "binaryDir": "${sourceDir}/build/vs2022-rel-shared", - "inherits": ["vs2022-shared", "rel"], + "inherits": ["vs2022-shared", "rel", "conan-deb-real"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-rel/install" } @@ -162,7 +169,7 @@ "name": "vs2022-deb-shared", "displayName": "Visual Studio 2022 Debug Shared", "binaryDir": "${sourceDir}/build/vs2022-deb-shared", - "inherits": ["vs2022-shared", "deb", "conan-deb"], + "inherits": ["vs2022-shared", "deb", "conan-dev"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-rel/install" } diff --git a/README.md b/README.md index 6a4c927..183e03d 100644 --- a/README.md +++ b/README.md @@ -726,6 +726,9 @@ We welcome contributions to improve the BankID C++ library! Here's how you can h # Install dependencies conan install . -s build_type=Debug -of=conan/debug --build=missing + + # For release build + conan install . -s build_type=Release -of=conan/release --build=missing ``` 3. **Build and Test** From 074f4cc2b88e32423ca4b5186417cc91e05be878 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 22:57:12 +0200 Subject: [PATCH 04/36] Fix toolchain file paths in CI workflow and update system dependencies installation --- .github/workflows/build-test-check.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index bdbb57c..413bfbc 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -45,7 +45,7 @@ jobs: - name: Install system dependencies run: | sudo apt-get update - sudo apt-get install -y ninja-build clang-17 clang++-17 + sudo apt-get install -y ninja-build ninja clang-17 clang++-17 - name: Install Conan run: | @@ -77,9 +77,9 @@ jobs: run: | # Add the conan toolchain file for all builds if [ "${{ matrix.config.build_type }}" = "Debug" ]; then - TOOLCHAIN_FILE="${{ github.workspace }}/conan/debug/build/generators/conan_toolchain.cmake" + TOOLCHAIN_FILE="${{ github.workspace }}/bankid-cpp/conan/debug/build/generators/conan_toolchain.cmake" else - TOOLCHAIN_FILE="${{ github.workspace }}/conan/release/build/generators/conan_toolchain.cmake" + TOOLCHAIN_FILE="${{ github.workspace }}/bankid-cpp/conan/release/build/generators/conan_toolchain.cmake" fi cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" From bb7aedd52ecbc2096c85d2f6e83525ff8d32e985 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 22:59:01 +0200 Subject: [PATCH 05/36] Fix installation command for system dependencies in CI workflow --- .github/workflows/build-test-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 413bfbc..d790912 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -45,7 +45,7 @@ jobs: - name: Install system dependencies run: | sudo apt-get update - sudo apt-get install -y ninja-build ninja clang-17 clang++-17 + sudo apt-get install -y ninja-build clang-17 clang++-17 - name: Install Conan run: | From adc6d2143a5a1d40a9078dbd3e7f230629a1f175 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 23:03:37 +0200 Subject: [PATCH 06/36] Add build configurations for Release and Debug in CI workflow --- .github/workflows/build-test-check.yml | 37 +++++++++++++++----------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index d790912..c9d2cb8 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -9,26 +9,26 @@ jobs: strategy: matrix: config: - # - name: "Release Static" - # build_type: "Release" - # conan_profile: "Release" - # cmake_preset: "unix-rel-ninja" - # shared: false + - name: "Release Static" + build_type: "Release" + conan_profile: "Release" + cmake_preset: "unix-rel-ninja" + shared: false - name: "Release Shared" build_type: "Release" conan_profile: "Release" cmake_preset: "unix-rel-ninja" # Will be modified for shared shared: true - # - name: "Debug Static" - # build_type: "Debug" - # conan_profile: "Debug" - # cmake_preset: "unix-deb-ninja" - # shared: false - # - name: "Debug Shared" - # build_type: "Debug" - # conan_profile: "Debug" - # cmake_preset: "unix-deb-ninja" # Will be modified for shared - # shared: true + - name: "Debug Static" + build_type: "Debug" + conan_profile: "Debug" + cmake_preset: "unix-deb-ninja" + shared: false + - name: "Debug Shared" + build_type: "Debug" + conan_profile: "Debug" + cmake_preset: "unix-deb-ninja" # Will be modified for shared + shared: true runs-on: ubuntu-latest name: ${{ matrix.config.name }} @@ -46,6 +46,9 @@ jobs: run: | sudo apt-get update sudo apt-get install -y ninja-build clang-17 clang++-17 + # Verify ninja is installed and accessible + which ninja + ninja --version - name: Install Conan run: | @@ -81,7 +84,9 @@ jobs: else TOOLCHAIN_FILE="${{ github.workspace }}/bankid-cpp/conan/release/build/generators/conan_toolchain.cmake" fi - cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" + # Ensure ninja is in PATH and set CMAKE_MAKE_PROGRAM explicitly + export PATH="/usr/bin:$PATH" + cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja - name: Build project run: | From d87242ca09dab93b2b22afaae3b4affc3bc7f20c Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 23:17:43 +0200 Subject: [PATCH 07/36] Rename conan-dev to conan-deb-dev and update inherits for Unix and Visual Studio presets in CMake configuration --- CMakePresets.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index f6990bf..922b1c9 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,7 +2,7 @@ "version": 2, "configurePresets": [ { - "name": "conan-dev", + "name": "conan-deb-dev", "hidden": true, "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/conan/debug/build/generators/conan_toolchain.cmake" @@ -86,7 +86,7 @@ "name": "unix-rel", "displayName": "Unix Make Release", "binaryDir": "${sourceDir}/build/unix-rel", - "inherits": ["unix-make", "rel"], + "inherits": ["unix-make", "rel", "conan-deb-real"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-rel/install" } @@ -95,7 +95,7 @@ "name": "unix-rel-ninja", "displayName": "Unix Ninja Clang Release", "binaryDir": "${sourceDir}/build/unix-rel-ninja", - "inherits": ["unix-ninja", "rel"], + "inherits": ["unix-ninja", "rel", "conan-deb-real"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-rel-ninja/install" } @@ -104,7 +104,7 @@ "name": "unix-rel-shared", "displayName": "Unix Make Release Shared", "binaryDir": "${sourceDir}/build/unix-rel-shared", - "inherits": ["unix-shared", "unix-rel"], + "inherits": ["unix-shared", "unix-rel", "conan-deb-real"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-rel-shared/install" } @@ -113,7 +113,7 @@ "name": "unix-deb", "displayName": "Unix Make Debug", "binaryDir": "${sourceDir}/build/unix-deb", - "inherits": ["unix-make", "deb", "conan-dev"], + "inherits": ["unix-make", "deb", "conan-deb-dev"], "cacheVariables": { "CMAKE_CXX_FLAGS": "-O0 --coverage -g -fsanitize=address", "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb/install" @@ -123,7 +123,7 @@ "name": "unix-deb-ninja", "displayName": "Unix Ninja Clang Debug", "binaryDir": "${sourceDir}/build/unix-deb-ninja", - "inherits": ["unix-ninja", "deb", "conan-dev"], + "inherits": ["unix-ninja", "deb", "conan-deb-dev"], "cacheVariables": { "CMAKE_CXX_FLAGS": "-O0 --coverage -g -fsanitize=address", "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb-ninja/install" @@ -133,7 +133,7 @@ "name": "unix-deb-shared", "displayName": "Unix Make Debug Shared", "binaryDir": "${sourceDir}/build/unix-deb-shared", - "inherits": ["unix-shared", "unix-deb"], + "inherits": ["unix-shared", "unix-deb", "conan-deb-dev"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb-shared/install" } @@ -151,7 +151,7 @@ "name": "vs2022-deb", "displayName": "Visual Studio 2022 Debug", "binaryDir": "${sourceDir}/build/vs2022-deb", - "inherits": ["vs2022", "deb", "conan-dev"], + "inherits": ["vs2022", "deb", "conan-deb-dev"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-deb/install" } @@ -169,7 +169,7 @@ "name": "vs2022-deb-shared", "displayName": "Visual Studio 2022 Debug Shared", "binaryDir": "${sourceDir}/build/vs2022-deb-shared", - "inherits": ["vs2022-shared", "deb", "conan-dev"], + "inherits": ["vs2022-shared", "deb", "conan-deb-dev"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-rel/install" } From 9859a96941504147828ce3f4cb392eb71cf5a0b4 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 23:25:00 +0200 Subject: [PATCH 08/36] Refactor CI workflow and CMake configuration: comment out unused build configurations and update toolchain file paths --- .github/workflows/build-test-check.yml | 34 +++++++++++++------------- .vscode/tasks.json | 22 ----------------- CMakeLists.txt | 2 +- 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index c9d2cb8..e8e91a6 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -14,21 +14,21 @@ jobs: conan_profile: "Release" cmake_preset: "unix-rel-ninja" shared: false - - name: "Release Shared" - build_type: "Release" - conan_profile: "Release" - cmake_preset: "unix-rel-ninja" # Will be modified for shared - shared: true - - name: "Debug Static" - build_type: "Debug" - conan_profile: "Debug" - cmake_preset: "unix-deb-ninja" - shared: false - - name: "Debug Shared" - build_type: "Debug" - conan_profile: "Debug" - cmake_preset: "unix-deb-ninja" # Will be modified for shared - shared: true + # - name: "Release Shared" + # build_type: "Release" + # conan_profile: "Release" + # cmake_preset: "unix-rel-ninja" # Will be modified for shared + # shared: true + # - name: "Debug Static" + # build_type: "Debug" + # conan_profile: "Debug" + # cmake_preset: "unix-deb-ninja" + # shared: false + # - name: "Debug Shared" + # build_type: "Debug" + # conan_profile: "Debug" + # cmake_preset: "unix-deb-ninja" # Will be modified for shared + # shared: true runs-on: ubuntu-latest name: ${{ matrix.config.name }} @@ -80,9 +80,9 @@ jobs: run: | # Add the conan toolchain file for all builds if [ "${{ matrix.config.build_type }}" = "Debug" ]; then - TOOLCHAIN_FILE="${{ github.workspace }}/bankid-cpp/conan/debug/build/generators/conan_toolchain.cmake" + TOOLCHAIN_FILE="${{ github.workspace }}/bankid-cpp/conan/debug/build/Debug/generators/conan_toolchain.cmake" else - TOOLCHAIN_FILE="${{ github.workspace }}/bankid-cpp/conan/release/build/generators/conan_toolchain.cmake" + TOOLCHAIN_FILE="${{ github.workspace }}/bankid-cpp/conan/release/build/Release/generators/conan_toolchain.cmake" fi # Ensure ninja is in PATH and set CMAKE_MAKE_PROGRAM explicitly export PATH="/usr/bin:$PATH" diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 6812b4e..4798f9b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -63,27 +63,5 @@ "dependsOn": "Build Tests (Shared)", "problemMatcher": [] }, - { - "label": "Run Tests Release (Static)", - "type": "shell", - "command": "./bankid_tests.exe", - "options": { - "cwd": "${workspaceFolder}/build/vs2022-rel/tests/Release" - }, - "group": "test", - "dependsOn": "Build Tests", - "problemMatcher": [] - }, - { - "label": "Run Tests Release (Shared)", - "type": "shell", - "command": "./bankid_tests.exe", - "options": { - "cwd": "${workspaceFolder}/build/vs2022-rel-shared/tests/Release" - }, - "group": "test", - "dependsOn": "Build Tests (Shared)", - "problemMatcher": [] - } ] } diff --git a/CMakeLists.txt b/CMakeLists.txt index 62b07f9..07385e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ endif() option(BUILD_SHARED_LIBS "Build shared library" Off) -option(BUILD_TESTS "Build tests" On) +# option(BUILD_TESTS "Build tests" On) add_subdirectory(bankid) add_subdirectory(server) From 39153bd8e339238f4c4eb0c6aba6d7bf3ca4c901 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 23:31:02 +0200 Subject: [PATCH 09/36] Fix toolchain file paths in CI workflow to remove unnecessary directory references --- .github/workflows/build-test-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index e8e91a6..b12d4a4 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -80,9 +80,9 @@ jobs: run: | # Add the conan toolchain file for all builds if [ "${{ matrix.config.build_type }}" = "Debug" ]; then - TOOLCHAIN_FILE="${{ github.workspace }}/bankid-cpp/conan/debug/build/Debug/generators/conan_toolchain.cmake" + TOOLCHAIN_FILE="${{ github.workspace }}/conan/debug/build/generators/conan_toolchain.cmake" else - TOOLCHAIN_FILE="${{ github.workspace }}/bankid-cpp/conan/release/build/Release/generators/conan_toolchain.cmake" + TOOLCHAIN_FILE="${{ github.workspace }}/conan/release/build/generators/conan_toolchain.cmake" fi # Ensure ninja is in PATH and set CMAKE_MAKE_PROGRAM explicitly export PATH="/usr/bin:$PATH" From 7fee4ade09ea4ff739cda2765eb43bc2f84ad117 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 23:36:22 +0200 Subject: [PATCH 10/36] Remove conan toolchain file configuration from CMake setup in CI workflow --- .github/workflows/build-test-check.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index b12d4a4..9b8c057 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -78,15 +78,8 @@ jobs: - name: Configure CMake run: | - # Add the conan toolchain file for all builds - if [ "${{ matrix.config.build_type }}" = "Debug" ]; then - TOOLCHAIN_FILE="${{ github.workspace }}/conan/debug/build/generators/conan_toolchain.cmake" - else - TOOLCHAIN_FILE="${{ github.workspace }}/conan/release/build/generators/conan_toolchain.cmake" - fi - # Ensure ninja is in PATH and set CMAKE_MAKE_PROGRAM explicitly export PATH="/usr/bin:$PATH" - cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja + cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja - name: Build project run: | From a44074422464ee539b820dbd839812559cd31ae0 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 23:44:52 +0200 Subject: [PATCH 11/36] Update CMake presets: rename conan-deb configurations and add CMakeUserPresets.json --- CMakePresets.json | 38 ++++++++++++++++++++++++++------------ CMakeUserPresets.json | 9 +++++++++ 2 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 CMakeUserPresets.json diff --git a/CMakePresets.json b/CMakePresets.json index 922b1c9..dbe6e71 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,19 +2,33 @@ "version": 2, "configurePresets": [ { - "name": "conan-deb-dev", + "name": "conan-deb", "hidden": true, "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/conan/debug/build/generators/conan_toolchain.cmake" } }, { - "name": "conan-deb-real", + "name": "conan-deb-unix", + "hidden": true, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/conan/debug/build/Debug/generators/conan_toolchain.cmake" + } + }, + { + "name": "conan-rel", "hidden": true, "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/conan/release/build/generators/conan_toolchain.cmake" } }, + { + "name": "conan-rel-unix", + "hidden": true, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/conan/release/build/Release/generators/conan_toolchain.cmake" + } + }, { "name": "rel", "hidden": true, @@ -86,7 +100,7 @@ "name": "unix-rel", "displayName": "Unix Make Release", "binaryDir": "${sourceDir}/build/unix-rel", - "inherits": ["unix-make", "rel", "conan-deb-real"], + "inherits": ["unix-make", "rel", "conan-rel-unix"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-rel/install" } @@ -95,7 +109,7 @@ "name": "unix-rel-ninja", "displayName": "Unix Ninja Clang Release", "binaryDir": "${sourceDir}/build/unix-rel-ninja", - "inherits": ["unix-ninja", "rel", "conan-deb-real"], + "inherits": ["unix-ninja", "rel", "conan-rel-unix"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-rel-ninja/install" } @@ -104,7 +118,7 @@ "name": "unix-rel-shared", "displayName": "Unix Make Release Shared", "binaryDir": "${sourceDir}/build/unix-rel-shared", - "inherits": ["unix-shared", "unix-rel", "conan-deb-real"], + "inherits": ["unix-shared", "unix-rel", "conan-rel-unix"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-rel-shared/install" } @@ -113,7 +127,7 @@ "name": "unix-deb", "displayName": "Unix Make Debug", "binaryDir": "${sourceDir}/build/unix-deb", - "inherits": ["unix-make", "deb", "conan-deb-dev"], + "inherits": ["unix-make", "deb", "conan-deb-unix"], "cacheVariables": { "CMAKE_CXX_FLAGS": "-O0 --coverage -g -fsanitize=address", "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb/install" @@ -123,7 +137,7 @@ "name": "unix-deb-ninja", "displayName": "Unix Ninja Clang Debug", "binaryDir": "${sourceDir}/build/unix-deb-ninja", - "inherits": ["unix-ninja", "deb", "conan-deb-dev"], + "inherits": ["unix-ninja", "deb", "conan-deb-unix"], "cacheVariables": { "CMAKE_CXX_FLAGS": "-O0 --coverage -g -fsanitize=address", "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb-ninja/install" @@ -133,7 +147,7 @@ "name": "unix-deb-shared", "displayName": "Unix Make Debug Shared", "binaryDir": "${sourceDir}/build/unix-deb-shared", - "inherits": ["unix-shared", "unix-deb", "conan-deb-dev"], + "inherits": ["unix-shared", "unix-deb", "conan-deb-unix"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb-shared/install" } @@ -142,7 +156,7 @@ "name": "vs2022-rel", "displayName": "Visual Studio 2022 Release", "binaryDir": "${sourceDir}/build/vs2022-rel", - "inherits": ["vs2022", "rel", "conan-deb-real"], + "inherits": ["vs2022", "rel", "conan-rel"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-rel/install" } @@ -151,7 +165,7 @@ "name": "vs2022-deb", "displayName": "Visual Studio 2022 Debug", "binaryDir": "${sourceDir}/build/vs2022-deb", - "inherits": ["vs2022", "deb", "conan-deb-dev"], + "inherits": ["vs2022", "deb", "conan-deb"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-deb/install" } @@ -160,7 +174,7 @@ "name": "vs2022-rel-shared", "displayName": "Visual Studio 2022 Release Shared", "binaryDir": "${sourceDir}/build/vs2022-rel-shared", - "inherits": ["vs2022-shared", "rel", "conan-deb-real"], + "inherits": ["vs2022-shared", "rel", "conan-rel"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-rel/install" } @@ -169,7 +183,7 @@ "name": "vs2022-deb-shared", "displayName": "Visual Studio 2022 Debug Shared", "binaryDir": "${sourceDir}/build/vs2022-deb-shared", - "inherits": ["vs2022-shared", "deb", "conan-deb-dev"], + "inherits": ["vs2022-shared", "deb", "conan-deb"], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-rel/install" } diff --git a/CMakeUserPresets.json b/CMakeUserPresets.json new file mode 100644 index 0000000..173b4e8 --- /dev/null +++ b/CMakeUserPresets.json @@ -0,0 +1,9 @@ +{ + "version": 4, + "vendor": { + "conan": {} + }, + "include": [ + "conan/release/build/generators/CMakePresets.json" + ] +} \ No newline at end of file From 1e6764c0b4b858d0f6bcf617de3305541c550992 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Fri, 25 Jul 2025 23:59:03 +0200 Subject: [PATCH 12/36] Enhance CI workflow: add missing dependencies and set C++ standard flags in CMake configuration --- .github/workflows/build-test-check.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 9b8c057..92eb2f6 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -45,10 +45,12 @@ jobs: - name: Install system dependencies run: | sudo apt-get update - sudo apt-get install -y ninja-build clang-17 clang++-17 + sudo apt-get install -y ninja-build clang-17 clang++-17 libc++-17-dev libc++abi-17-dev # Verify ninja is installed and accessible which ninja ninja --version + clang++-17 --version + echo | clang++-17 -dM -E -std=c++23 - | grep __cplusplus - name: Install Conan run: | @@ -79,11 +81,12 @@ jobs: - name: Configure CMake run: | export PATH="/usr/bin:$PATH" - cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja + EXTRA_CXX_FLAGS="-stdlib=libc++ -std=c++23" + cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_CXX_FLAGS="${EXTRA_CXX_FLAGS}" - name: Build project run: | - cmake --build --preset ${{ matrix.config.build_type == 'Debug' && 'unix-deb-ninja' || 'unix-rel-ninja' }} + cmake --build --preset ${{ matrix.config.build_type == 'Debug' && 'unix-deb-ninja' || 'unix-rel-ninja' }} --config ${{ matrix.config.build_type }} - name: Run tests run: | From 7b755bb9aee88b835246582c3e308d791170b219 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 00:01:40 +0200 Subject: [PATCH 13/36] Format CI workflow YAML: standardize spacing and improve readability --- .github/workflows/build-test-check.yml | 126 ++++++++++++------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 92eb2f6..8302d9a 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -2,17 +2,17 @@ name: CI Build and Test on: pull_request: - branches: [ main, develop ] + branches: [main, develop] jobs: build-and-test: strategy: matrix: config: - - name: "Release Static" - build_type: "Release" - conan_profile: "Release" - cmake_preset: "unix-rel-ninja" + - name: 'Release Static' + build_type: 'Release' + conan_profile: 'Release' + cmake_preset: 'unix-rel-ninja' shared: false # - name: "Release Shared" # build_type: "Release" @@ -34,71 +34,71 @@ jobs: name: ${{ matrix.config.name }} steps: - - name: Checkout code - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.11' + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' - - name: Install system dependencies - run: | - sudo apt-get update - sudo apt-get install -y ninja-build clang-17 clang++-17 libc++-17-dev libc++abi-17-dev - # Verify ninja is installed and accessible - which ninja - ninja --version - clang++-17 --version - echo | clang++-17 -dM -E -std=c++23 - | grep __cplusplus + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y ninja-build clang-17 clang++-17 libc++-17-dev libc++abi-17-dev + # Verify ninja is installed and accessible + which ninja + ninja --version + # Check clang version and C++23 support + clang++-17 --version - - name: Install Conan - run: | - python -m pip install --upgrade pip - pip install conan + - name: Install Conan + run: | + python -m pip install --upgrade pip + pip install conan - - name: Configure Conan - run: | - conan profile detect --force + - name: Configure Conan + run: | + conan profile detect --force - - name: Install dependencies with Conan - run: | - conan install . -s build_type=${{ matrix.config.conan_profile }} -of=conan/${{ matrix.config.build_type == 'Debug' && 'debug' || 'release' }} --build=missing + - name: Install dependencies with Conan + run: | + conan install . -s build_type=${{ matrix.config.conan_profile }} -of=conan/${{ matrix.config.build_type == 'Debug' && 'debug' || 'release' }} --build=missing - - name: Set up CMake preset name - id: cmake_preset - run: | - if [ "${{ matrix.config.shared }}" = "true" ]; then - # For shared builds, we need to use the shared presets (though they don't exist in the current config) - # We'll use the regular presets and override BUILD_SHARED_LIBS - echo "preset=${{ matrix.config.cmake_preset }}" >> $GITHUB_OUTPUT - echo "shared_flag=-DBUILD_SHARED_LIBS=ON" >> $GITHUB_OUTPUT - else - echo "preset=${{ matrix.config.cmake_preset }}" >> $GITHUB_OUTPUT - echo "shared_flag=-DBUILD_SHARED_LIBS=OFF" >> $GITHUB_OUTPUT - fi + - name: Set up CMake preset name + id: cmake_preset + run: | + if [ "${{ matrix.config.shared }}" = "true" ]; then + # For shared builds, we need to use the shared presets (though they don't exist in the current config) + # We'll use the regular presets and override BUILD_SHARED_LIBS + echo "preset=${{ matrix.config.cmake_preset }}" >> $GITHUB_OUTPUT + echo "shared_flag=-DBUILD_SHARED_LIBS=ON" >> $GITHUB_OUTPUT + else + echo "preset=${{ matrix.config.cmake_preset }}" >> $GITHUB_OUTPUT + echo "shared_flag=-DBUILD_SHARED_LIBS=OFF" >> $GITHUB_OUTPUT + fi - - name: Configure CMake - run: | - export PATH="/usr/bin:$PATH" - EXTRA_CXX_FLAGS="-stdlib=libc++ -std=c++23" - cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_CXX_FLAGS="${EXTRA_CXX_FLAGS}" + - name: Configure CMake + run: | + export PATH="/usr/bin:$PATH" + EXTRA_CXX_FLAGS="-stdlib=libc++ -std=c++23" + cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_CXX_STANDARD=23 -DCMAKE_CXX_FLAGS="-stdlib=libc++" - - name: Build project - run: | - cmake --build --preset ${{ matrix.config.build_type == 'Debug' && 'unix-deb-ninja' || 'unix-rel-ninja' }} --config ${{ matrix.config.build_type }} + - name: Build project + run: | + cmake --build --preset ${{ matrix.config.build_type == 'Debug' && 'unix-deb-ninja' || 'unix-rel-ninja' }} --config ${{ matrix.config.build_type }} - - name: Run tests - run: | - cd build/${{ matrix.config.cmake_preset }} - ctest --output-on-failure --parallel $(nproc) + - name: Run tests + run: | + cd build/${{ matrix.config.cmake_preset }} + ctest --output-on-failure --parallel $(nproc) - - name: Upload build artifacts (on failure) - if: failure() - uses: actions/upload-artifact@v4 - with: - name: build-logs-${{ matrix.config.name }} - path: | - build/ - !build/**/CMakeFiles/ - retention-days: 7 \ No newline at end of file + - name: Upload build artifacts (on failure) + if: failure() + uses: actions/upload-artifact@v4 + with: + name: build-logs-${{ matrix.config.name }} + path: | + build/ + !build/**/CMakeFiles/ + retention-days: 7 From cd7e02381b999601607f7fea3b5b8cdf6550f241 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 00:05:45 +0200 Subject: [PATCH 14/36] Fix CMake command: remove redundant CXX flags in build step --- .github/workflows/build-test-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 8302d9a..ec8ba7b 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -82,7 +82,7 @@ jobs: run: | export PATH="/usr/bin:$PATH" EXTRA_CXX_FLAGS="-stdlib=libc++ -std=c++23" - cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_CXX_STANDARD=23 -DCMAKE_CXX_FLAGS="-stdlib=libc++" + cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja" - name: Build project run: | From 251d6c0a52207a6003f596054c4c1e53ca76697f Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 00:10:40 +0200 Subject: [PATCH 15/36] Refactor CI workflow: uncomment Debug Shared configuration and clean up Release Static settings --- .github/workflows/build-test-check.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index ec8ba7b..935d874 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -9,11 +9,11 @@ jobs: strategy: matrix: config: - - name: 'Release Static' - build_type: 'Release' - conan_profile: 'Release' - cmake_preset: 'unix-rel-ninja' - shared: false + # - name: 'Release Static' + # build_type: 'Release' + # conan_profile: 'Release' + # cmake_preset: 'unix-rel-ninja' + # shared: false # - name: "Release Shared" # build_type: "Release" # conan_profile: "Release" @@ -24,11 +24,11 @@ jobs: # conan_profile: "Debug" # cmake_preset: "unix-deb-ninja" # shared: false - # - name: "Debug Shared" - # build_type: "Debug" - # conan_profile: "Debug" - # cmake_preset: "unix-deb-ninja" # Will be modified for shared - # shared: true + - name: "Debug Shared" + build_type: "Debug" + conan_profile: "Debug" + cmake_preset: "unix-deb-ninja" # Will be modified for shared + shared: true runs-on: ubuntu-latest name: ${{ matrix.config.name }} @@ -82,7 +82,7 @@ jobs: run: | export PATH="/usr/bin:$PATH" EXTRA_CXX_FLAGS="-stdlib=libc++ -std=c++23" - cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja" + cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja - name: Build project run: | From ec713f9486860158c9e7762e1f5179240b8fa3bf Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 00:14:04 +0200 Subject: [PATCH 16/36] Enhance CMake configuration: set C++ standard to C++23 and specify libc++ in build step --- .github/workflows/build-test-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 935d874..9681a8d 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -82,7 +82,7 @@ jobs: run: | export PATH="/usr/bin:$PATH" EXTRA_CXX_FLAGS="-stdlib=libc++ -std=c++23" - cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja + cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_CXX_STANDARD=23 -DCMAKE_CXX_FLAGS="-stdlib=libc++" - name: Build project run: | From 94d9ec23dc24bf89057222796728a753824ac238 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 00:44:01 +0200 Subject: [PATCH 17/36] Refactor CI workflow: update CMake configuration and enhance test registration --- .github/workflows/build-test-check.yml | 7 ++++--- CMakeUserPresets.json | 9 --------- tests/CMakeLists.txt | 14 +++++++++----- tests/test_ssl.cpp | 12 ++++++------ 4 files changed, 19 insertions(+), 23 deletions(-) delete mode 100644 CMakeUserPresets.json diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 9681a8d..2c09fe1 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -87,11 +87,12 @@ jobs: - name: Build project run: | cmake --build --preset ${{ matrix.config.build_type == 'Debug' && 'unix-deb-ninja' || 'unix-rel-ninja' }} --config ${{ matrix.config.build_type }} - + - name: Run tests + if: ${{ matrix.config.build_type == 'Debug' }} run: | - cd build/${{ matrix.config.cmake_preset }} - ctest --output-on-failure --parallel $(nproc) + cd build/${{ matrix.config.cmake_preset }}/tests + ctest -C ${{ matrix.config.build_type }} --output-on-failure --parallel $(nproc) - name: Upload build artifacts (on failure) if: failure() diff --git a/CMakeUserPresets.json b/CMakeUserPresets.json deleted file mode 100644 index 173b4e8..0000000 --- a/CMakeUserPresets.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": 4, - "vendor": { - "conan": {} - }, - "include": [ - "conan/release/build/generators/CMakePresets.json" - ] -} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1b44379..2aa0a30 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -43,12 +43,7 @@ set_target_properties(bankid_tests PROPERTIES # Enable testing enable_testing() -# Add test discovery - temporarily disabled to avoid DLL issues -# include(GoogleTest) -# gtest_discover_tests(bankid_tests) - # Manual test registration as fallback -add_test(NAME AuthTests COMMAND bankid_tests --gtest_filter=AuthTest.*) # Add custom test target add_custom_target(run_tests @@ -99,3 +94,12 @@ add_custom_command(TARGET bankid_tests POST_BUILD COMMENT "Copying certificates folder to tests output directory" VERBATIM ) + +add_test(NAME SSLConfigTest COMMAND bankid_tests --gtest_filter=SSLConfigTest.*) +set_tests_properties(SSLConfigTest PROPERTIES WORKING_DIRECTORY $) + +add_test(NAME AuthTests COMMAND bankid_tests --gtest_filter=AuthTest.*) +set_tests_properties(AuthTests PROPERTIES WORKING_DIRECTORY $) + +add_test(NAME SignTests COMMAND bankid_tests --gtest_filter=SignTest.*) +set_tests_properties(SignTests PROPERTIES WORKING_DIRECTORY $) diff --git a/tests/test_ssl.cpp b/tests/test_ssl.cpp index 18787b0..1c23652 100644 --- a/tests/test_ssl.cpp +++ b/tests/test_ssl.cpp @@ -7,7 +7,7 @@ #include #include -class ConfigParamaters : public ::testing::Test +class SSLConfigTest : public ::testing::Test { protected: void SetUp() override @@ -19,7 +19,7 @@ class ConfigParamaters : public ::testing::Test } }; -TEST_F(ConfigParamaters, BasicDefaultValidConfig) +TEST_F(SSLConfigTest, BasicDefaultValidConfig) { BankID::SSLConfig sslConfig(BankID::Environment::TEST); @@ -27,7 +27,7 @@ TEST_F(ConfigParamaters, BasicDefaultValidConfig) EXPECT_TRUE(sslConfig.validate()); } -TEST_F(ConfigParamaters, BasicDefaultInvalidConfig) +TEST_F(SSLConfigTest, BasicDefaultInvalidConfig) { BankID::SSLConfig sslConfig(BankID::Environment::TEST, "certs/invalid.ca", "certs/bankid_cert.pem", "certs/bankid_key.pem"); @@ -36,7 +36,7 @@ TEST_F(ConfigParamaters, BasicDefaultInvalidConfig) EXPECT_FALSE(sslConfig.validate()); } -TEST_F(ConfigParamaters, CustomConfig) +TEST_F(SSLConfigTest, CustomConfig) { BankID::SSLConfig sslConfig(BankID::Environment::PRODUCTION, "certs/prod.ca", "certs/bankid_cert.pem", "certs/bankid_key.pem"); @@ -45,7 +45,7 @@ TEST_F(ConfigParamaters, CustomConfig) EXPECT_TRUE(sslConfig.validate()); } -TEST_F(ConfigParamaters, SendApiRequestWithValidConfig) +TEST_F(SSLConfigTest, SendApiRequestWithValidConfig) { BankID::SSLConfig sslConfig(BankID::Environment::TEST); @@ -71,7 +71,7 @@ TEST_F(ConfigParamaters, SendApiRequestWithValidConfig) EXPECT_EQ(cancelResponse.value().httpStatus, 200); } -TEST_F(ConfigParamaters, SendApiRequestWithInvalidConfig) +TEST_F(SSLConfigTest, SendApiRequestWithInvalidConfig) { BankID::SSLConfig sslConfig(BankID::Environment::TEST, "certs/prod.ca", "certs/bankid_cert.pem", "certs/bankid_key.pem"); From 3f558b6ff9d988b69fa0582578bbd26bd63924e1 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 00:54:41 +0200 Subject: [PATCH 18/36] Update CMake configuration: switch to GCC for compiler and enable testing in CMakeLists --- CMakePresets.json | 4 ++-- tests/CMakeLists.txt | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index dbe6e71..470e803 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -64,8 +64,8 @@ "hidden": true, "generator": "Ninja", "cacheVariables": { - "CMAKE_C_COMPILER": "clang-17", - "CMAKE_CXX_COMPILER": "clang++-17", + "CMAKE_C_COMPILER": "g++", + "CMAKE_CXX_COMPILER": "gcc", "CMAKE_CXX_FLAGS_INIT": "$env{CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -pedantic" } }, diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2aa0a30..14a66f2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.16) +# Enable testing +enable_testing() + # Find required packages find_package(GTest REQUIRED) find_package(nlohmann_json REQUIRED) @@ -40,8 +43,7 @@ set_target_properties(bankid_tests PROPERTIES CXX_EXTENSIONS OFF ) -# Enable testing -enable_testing() + # Manual test registration as fallback From a7929f105f07f87d81bf14f65fbae77f5d355ad6 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 01:02:57 +0200 Subject: [PATCH 19/36] Update CMake configuration: switch C++ compiler to Clang 17 --- CMakePresets.json | 85 ++--------------------------------------------- 1 file changed, 2 insertions(+), 83 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 470e803..12748ba 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -49,35 +49,16 @@ "CMAKE_EXPORT_COMPILE_COMMANDS": true } }, - { - "name": "unix-make", - "hidden": true, - "generator": "Unix Makefiles", - "cacheVariables": { - "CMAKE_CXX_COMPILER": "g++", - "CMAKE_C_COMPILER": "gcc", - "CMAKE_CXX_FLAGS_INIT": "$env{CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -pedantic" - } - }, { "name": "unix-ninja", "hidden": true, "generator": "Ninja", "cacheVariables": { - "CMAKE_C_COMPILER": "g++", - "CMAKE_CXX_COMPILER": "gcc", + "CMAKE_C_COMPILER": "clang-17", + "CMAKE_CXX_COMPILER": "clang++-17", "CMAKE_CXX_FLAGS_INIT": "$env{CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -pedantic" } }, - { - "name": "unix-shared", - "hidden": true, - "inherits": "unix-make", - "cacheVariables": { - "CMAKE_CXX_FLAGS_INIT": "$env{CMAKE_CXX_FLAGS_INIT} $env{CMAKE_CXX_FLAGS} -fPIC -Werror -Wall -Wextra -pedantic", - "BUILD_SHARED_LIBS": true - } - }, { "name": "vs2022", "hidden": true, @@ -95,16 +76,6 @@ "BUILD_SHARED_LIBS": true } }, - - { - "name": "unix-rel", - "displayName": "Unix Make Release", - "binaryDir": "${sourceDir}/build/unix-rel", - "inherits": ["unix-make", "rel", "conan-rel-unix"], - "cacheVariables": { - "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-rel/install" - } - }, { "name": "unix-rel-ninja", "displayName": "Unix Ninja Clang Release", @@ -114,25 +85,6 @@ "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-rel-ninja/install" } }, - { - "name": "unix-rel-shared", - "displayName": "Unix Make Release Shared", - "binaryDir": "${sourceDir}/build/unix-rel-shared", - "inherits": ["unix-shared", "unix-rel", "conan-rel-unix"], - "cacheVariables": { - "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-rel-shared/install" - } - }, - { - "name": "unix-deb", - "displayName": "Unix Make Debug", - "binaryDir": "${sourceDir}/build/unix-deb", - "inherits": ["unix-make", "deb", "conan-deb-unix"], - "cacheVariables": { - "CMAKE_CXX_FLAGS": "-O0 --coverage -g -fsanitize=address", - "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb/install" - } - }, { "name": "unix-deb-ninja", "displayName": "Unix Ninja Clang Debug", @@ -143,15 +95,6 @@ "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb-ninja/install" } }, - { - "name": "unix-deb-shared", - "displayName": "Unix Make Debug Shared", - "binaryDir": "${sourceDir}/build/unix-deb-shared", - "inherits": ["unix-shared", "unix-deb", "conan-deb-unix"], - "cacheVariables": { - "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb-shared/install" - } - }, { "name": "vs2022-rel", "displayName": "Visual Studio 2022 Release", @@ -214,41 +157,17 @@ "configurePreset": "vs2022-deb-shared", "configuration": "Debug" }, - { - "name": "unix-deb", - "displayName": "Unix Make Debug Build", - "configurePreset": "unix-deb", - "configuration": "Debug" - }, { "name": "unix-deb-ninja", "displayName": "Unix Ninja Debug Build", "configurePreset": "unix-deb-ninja", "configuration": "Debug" }, - { - "name": "unix-deb-shared", - "displayName": "Unix Make Debug Build", - "configurePreset": "unix-deb-shared", - "configuration": "Debug" - }, - { - "name": "unix-rel", - "displayName": "Unix Make Release Build", - "configurePreset": "unix-rel", - "configuration": "Release" - }, { "name": "unix-rel-ninja", "displayName": "Unix Ninja Release Build", "configurePreset": "unix-rel-ninja", "configuration": "Release" - }, - { - "name": "unix-rel-shared", - "displayName": "Unix Make Release Build", - "configurePreset": "unix-rel-shared", - "configuration": "Release" } ] } From c2d7152745e48fb258d4c9543c3c06d62809876e Mon Sep 17 00:00:00 2001 From: forsrobin Date: Sat, 26 Jul 2025 00:20:31 +0100 Subject: [PATCH 20/36] Update CMake configuration: switch C++ compiler to Clang 19 and format inheritance lists --- CMakePresets.json | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 12748ba..3ec9b69 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -54,8 +54,8 @@ "hidden": true, "generator": "Ninja", "cacheVariables": { - "CMAKE_C_COMPILER": "clang-17", - "CMAKE_CXX_COMPILER": "clang++-17", + "CMAKE_CXX_COMPILER": "clang++-19", + "CMAKE_C_COMPILER": "clang-19", "CMAKE_CXX_FLAGS_INIT": "$env{CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -pedantic" } }, @@ -80,7 +80,11 @@ "name": "unix-rel-ninja", "displayName": "Unix Ninja Clang Release", "binaryDir": "${sourceDir}/build/unix-rel-ninja", - "inherits": ["unix-ninja", "rel", "conan-rel-unix"], + "inherits": [ + "unix-ninja", + "rel", + "conan-rel-unix" + ], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-rel-ninja/install" } @@ -89,7 +93,11 @@ "name": "unix-deb-ninja", "displayName": "Unix Ninja Clang Debug", "binaryDir": "${sourceDir}/build/unix-deb-ninja", - "inherits": ["unix-ninja", "deb", "conan-deb-unix"], + "inherits": [ + "unix-ninja", + "deb", + "conan-deb-unix" + ], "cacheVariables": { "CMAKE_CXX_FLAGS": "-O0 --coverage -g -fsanitize=address", "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb-ninja/install" @@ -99,7 +107,11 @@ "name": "vs2022-rel", "displayName": "Visual Studio 2022 Release", "binaryDir": "${sourceDir}/build/vs2022-rel", - "inherits": ["vs2022", "rel", "conan-rel"], + "inherits": [ + "vs2022", + "rel", + "conan-rel" + ], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-rel/install" } @@ -108,7 +120,11 @@ "name": "vs2022-deb", "displayName": "Visual Studio 2022 Debug", "binaryDir": "${sourceDir}/build/vs2022-deb", - "inherits": ["vs2022", "deb", "conan-deb"], + "inherits": [ + "vs2022", + "deb", + "conan-deb" + ], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-deb/install" } @@ -117,7 +133,11 @@ "name": "vs2022-rel-shared", "displayName": "Visual Studio 2022 Release Shared", "binaryDir": "${sourceDir}/build/vs2022-rel-shared", - "inherits": ["vs2022-shared", "rel", "conan-rel"], + "inherits": [ + "vs2022-shared", + "rel", + "conan-rel" + ], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-rel/install" } @@ -126,7 +146,11 @@ "name": "vs2022-deb-shared", "displayName": "Visual Studio 2022 Debug Shared", "binaryDir": "${sourceDir}/build/vs2022-deb-shared", - "inherits": ["vs2022-shared", "deb", "conan-deb"], + "inherits": [ + "vs2022-shared", + "deb", + "conan-deb" + ], "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/vs2022-rel/install" } @@ -170,4 +194,4 @@ "configuration": "Release" } ] -} +} \ No newline at end of file From cd6c8f7cd37fae1020c985bc7e2570093226ee96 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 01:20:52 +0200 Subject: [PATCH 21/36] Refactor CMake presets: replace Unix Makefiles with Clang for Unix configurations and remove unused presets --- .github/workflows/build-test-check.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 2c09fe1..452c5ee 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -45,12 +45,7 @@ jobs: - name: Install system dependencies run: | sudo apt-get update - sudo apt-get install -y ninja-build clang-17 clang++-17 libc++-17-dev libc++abi-17-dev - # Verify ninja is installed and accessible - which ninja - ninja --version - # Check clang version and C++23 support - clang++-17 --version + sudo apt-get install -y ninja-build clang-17 - name: Install Conan run: | @@ -81,8 +76,7 @@ jobs: - name: Configure CMake run: | export PATH="/usr/bin:$PATH" - EXTRA_CXX_FLAGS="-stdlib=libc++ -std=c++23" - cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja -DCMAKE_CXX_STANDARD=23 -DCMAKE_CXX_FLAGS="-stdlib=libc++" + cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja - name: Build project run: | From a94f4a0319ea7633b3a3d2aaa5b6c42e55d47e8d Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 01:25:09 +0200 Subject: [PATCH 22/36] Update CI workflow: install additional Clang and LLVM packages for testing --- .github/workflows/build-test-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 452c5ee..0ac3f3c 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -45,7 +45,7 @@ jobs: - name: Install system dependencies run: | sudo apt-get update - sudo apt-get install -y ninja-build clang-17 + sudo apt-get install -y ninja-build clang-17 clang-19 lldb-19 lld-19 - name: Install Conan run: | From 95dc3a1bb865b61e30bd63d24243c435092f72da Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 01:25:15 +0200 Subject: [PATCH 23/36] Update CI workflow: remove unnecessary lldb and lld packages from system dependencies --- .github/workflows/build-test-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 0ac3f3c..c5bbfa7 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -45,7 +45,7 @@ jobs: - name: Install system dependencies run: | sudo apt-get update - sudo apt-get install -y ninja-build clang-17 clang-19 lldb-19 lld-19 + sudo apt-get install -y ninja-build clang-17 clang-19 - name: Install Conan run: | From 0f01051afa9da550d4fb5823dbf5af4e610268c8 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 01:44:54 +0200 Subject: [PATCH 24/36] Update CI workflow: remove clang-17 from system dependencies --- .github/workflows/build-test-check.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index c5bbfa7..53d8181 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -45,7 +45,8 @@ jobs: - name: Install system dependencies run: | sudo apt-get update - sudo apt-get install -y ninja-build clang-17 clang-19 + sudo apt-get install -y ninja-build clang-19 + clang --version - name: Install Conan run: | @@ -55,6 +56,7 @@ jobs: - name: Configure Conan run: | conan profile detect --force + conan prodile show - name: Install dependencies with Conan run: | From 6b21caa5d8bfc8bbbc60f1f9f9456b92fe2d24c0 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 01:46:06 +0200 Subject: [PATCH 25/36] Fix typo in Conan profile command in CI workflow --- .github/workflows/build-test-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 53d8181..2923262 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -56,7 +56,7 @@ jobs: - name: Configure Conan run: | conan profile detect --force - conan prodile show + conan profile show - name: Install dependencies with Conan run: | From 34be87db5b66a2699e48a2d4ec55f540d830dee2 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 02:00:25 +0200 Subject: [PATCH 26/36] Update CI workflow: install Clang 19 and configure build environment --- .github/workflows/build-test-check.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 2923262..c105174 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -42,11 +42,19 @@ jobs: with: python-version: '3.11' - - name: Install system dependencies + - name: Install Clang 19 run: | sudo apt-get update - sudo apt-get install -y ninja-build clang-19 - clang --version + sudo apt-get install -y wget gnupg lsb-release + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 19 + + - name: Configure with Clang 19 + run: | + export CC=clang-19 + export CXX=clang++-19 + cmake -B build -G Ninja . - name: Install Conan run: | From 5c24b81580a967fd91d72eb4f330b3e717d8534c Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 02:03:12 +0200 Subject: [PATCH 27/36] Remove unnecessary CMake configuration step in CI workflow --- .github/workflows/build-test-check.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index c105174..a6f9d68 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -54,7 +54,6 @@ jobs: run: | export CC=clang-19 export CXX=clang++-19 - cmake -B build -G Ninja . - name: Install Conan run: | From 02ac0e65acd1b2846806a20e528805f32e7ae0db Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 02:06:09 +0200 Subject: [PATCH 28/36] Update CI workflow: add ninja-build to Clang 19 installation step --- .github/workflows/build-test-check.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index a6f9d68..3be1ab4 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -45,7 +45,8 @@ jobs: - name: Install Clang 19 run: | sudo apt-get update - sudo apt-get install -y wget gnupg lsb-release + sudo apt-get install -y wget gnupg lsb-release ninja-build + which ninja wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh 19 From 81e8cc00377c297827a27d31a9a551f42f5b798d Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 02:14:52 +0200 Subject: [PATCH 29/36] Refactor CMake configuration: remove CMAKE_CXX_FLAGS from conan-deb-unix preset and adjust bankid_lib creation logic --- CMakePresets.json | 1 - bankid/CMakeLists.txt | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 3ec9b69..cc569fc 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -99,7 +99,6 @@ "conan-deb-unix" ], "cacheVariables": { - "CMAKE_CXX_FLAGS": "-O0 --coverage -g -fsanitize=address", "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb-ninja/install" } }, diff --git a/bankid/CMakeLists.txt b/bankid/CMakeLists.txt index e8732de..26d51a2 100644 --- a/bankid/CMakeLists.txt +++ b/bankid/CMakeLists.txt @@ -13,7 +13,11 @@ find_package(OpenSSL REQUIRED) find_package(nlohmann_json REQUIRED) # Create the BankID library (shared/static based on BUILD_SHARED_LIBS) -add_library(bankid_lib ${BANKID_LIB_SOURCES}) +if(BUILD_SHARED_LIBS) + add_library(bankid_lib SHARED ${BANKID_LIB_SOURCES}) +else() + add_library(bankid_lib STATIC ${BANKID_LIB_SOURCES}) +endif() # Set library properties set_target_properties(bankid_lib PROPERTIES From 56e303f62e667e5ede5b8703840552d10e2fe976 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 02:24:52 +0200 Subject: [PATCH 30/36] Update CMake configuration: add CMAKE_CXX_FLAGS for conan-deb-unix preset --- CMakePresets.json | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakePresets.json b/CMakePresets.json index cc569fc..3ec9b69 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -99,6 +99,7 @@ "conan-deb-unix" ], "cacheVariables": { + "CMAKE_CXX_FLAGS": "-O0 --coverage -g -fsanitize=address", "CMAKE_INSTALL_PREFIX": "${sourceDir}/build/unix-deb-ninja/install" } }, From b4a38692b4662dd44a9368c34adce166db43b416 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 02:35:09 +0200 Subject: [PATCH 31/36] Refactor Session initialization method and update BANKID_API definition for better visibility control --- bankid/bankid.cpp | 2 +- bankid/includes/bankid.h | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bankid/bankid.cpp b/bankid/bankid.cpp index 3d708a8..16e3f4d 100644 --- a/bankid/bankid.cpp +++ b/bankid/bankid.cpp @@ -23,7 +23,7 @@ namespace BankID } } - const bool Session::initialize() + bool Session::initialize() { if (!m_sslConfig.validate()) { diff --git a/bankid/includes/bankid.h b/bankid/includes/bankid.h index 01b4fe8..0e5f6e7 100644 --- a/bankid/includes/bankid.h +++ b/bankid/includes/bankid.h @@ -16,18 +16,22 @@ using json = nlohmann::json; #ifdef _WIN32 -#ifdef BANKID_STATIC -#define BANKID_API -#elif defined(BANKID_EXPORTS) -#define BANKID_API __declspec(dllexport) + #ifdef BANKID_STATIC + #define BANKID_API + #elif defined(BANKID_EXPORTS) + #define BANKID_API __declspec(dllexport) + #else + #define BANKID_API __declspec(dllimport) + #endif + // Suppress C4251 warnings for STL types in DLL interface + #pragma warning(push) + #pragma warning(disable : 4251) #else -#define BANKID_API __declspec(dllimport) -#endif -// Suppress C4251 warnings for STL types in DLL interface -#pragma warning(push) -#pragma warning(disable : 4251) -#else -#define BANKID_API + #ifdef BANKID_EXPORTS + #define BANKID_API __attribute__((visibility("default"))) + #else + #define BANKID_API + #endif #endif // Forward declaration - implementation in bankid.cpp @@ -258,7 +262,7 @@ namespace BankID // Get current token bool isInitialized() const { return m_initialized; } - const bool initialize(); + bool initialize(); const SSLConfig &getSSLConfig() const { return m_sslConfig; } private: From 06867467a1b88ec45407fedb36aa5a4eb3e15e7a Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 02:40:24 +0200 Subject: [PATCH 32/36] Enhance CMake configuration: set symbol visibility for shared libraries and improve RPATH handling for tests --- bankid/CMakeLists.txt | 25 +++++++++++++++++-------- tests/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/bankid/CMakeLists.txt b/bankid/CMakeLists.txt index 26d51a2..9d40e89 100644 --- a/bankid/CMakeLists.txt +++ b/bankid/CMakeLists.txt @@ -15,6 +15,11 @@ find_package(nlohmann_json REQUIRED) # Create the BankID library (shared/static based on BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS) add_library(bankid_lib SHARED ${BANKID_LIB_SOURCES}) + # Set symbol visibility for shared libraries + set_target_properties(bankid_lib PROPERTIES + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN YES + ) else() add_library(bankid_lib STATIC ${BANKID_LIB_SOURCES}) endif() @@ -26,22 +31,24 @@ set_target_properties(bankid_lib PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} ) -# Set compile definitions for Windows DLL export/import -if(WIN32) - if(BUILD_SHARED_LIBS) - target_compile_definitions(bankid_lib PRIVATE BANKID_EXPORTS) - else() - # For static libraries, we don't need the export/import macros - target_compile_definitions(bankid_lib PUBLIC BANKID_STATIC) - endif() +# Set compile definitions for symbol export/import +if(BUILD_SHARED_LIBS) + target_compile_definitions(bankid_lib PRIVATE BANKID_EXPORTS) + # For consumers of the shared library + target_compile_definitions(bankid_lib INTERFACE BANKID_SHARED) +else() + # For static libraries, we don't need the export/import macros + target_compile_definitions(bankid_lib PUBLIC BANKID_STATIC) endif() + # Include directories for the library target_include_directories(bankid_lib PUBLIC $ $ ) +target_compile_features(bankid_lib PUBLIC cxx_std_23) target_link_libraries(bankid_lib PUBLIC OpenSSL::SSL OpenSSL::Crypto nlohmann_json::nlohmann_json) # Installation rules @@ -55,6 +62,8 @@ install(TARGETS bankid_lib RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + + # Install headers install(DIRECTORY ${BANKID_INCLUDE_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 14a66f2..8450fd3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -43,18 +43,25 @@ set_target_properties(bankid_tests PROPERTIES CXX_EXTENSIONS OFF ) - +# Handle shared library runtime path (RPATH) on Unix systems +if(BUILD_SHARED_LIBS AND UNIX) + # Set RPATH so the executable can find the shared library + set_target_properties(bankid_tests PROPERTIES + BUILD_RPATH "${CMAKE_BINARY_DIR}/bankid" + INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" + BUILD_WITH_INSTALL_RPATH FALSE + SKIP_BUILD_RPATH FALSE + ) +endif() # Manual test registration as fallback - -# Add custom test target add_custom_target(run_tests COMMAND bankid_tests DEPENDS bankid_tests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) -# If using shared libraries on Windows, copy the DLL and dependencies +# Handle DLL copying for Windows shared builds if(WIN32 AND BUILD_SHARED_LIBS) # Create a script to handle DLL copying set(COPY_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/copy_dlls.cmake") @@ -88,6 +95,18 @@ if(WIN32 AND BUILD_SHARED_LIBS) ) endif() +# For Unix shared builds, ensure the library is available at test runtime +if(BUILD_SHARED_LIBS AND UNIX) + # Add a custom command to create a symlink or copy the shared library + add_custom_command(TARGET bankid_tests POST_BUILD + COMMAND ${CMAKE_COMMAND} -E create_symlink + $ + $/lib$ + COMMENT "Creating symlink to shared library in test directory" + VERBATIM + ) +endif() + # Copy certificates folder to output directory for tests add_custom_command(TARGET bankid_tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory @@ -105,3 +124,10 @@ set_tests_properties(AuthTests PROPERTIES WORKING_DIRECTORY $) + +# Set environment variables for tests to find shared libraries +if(BUILD_SHARED_LIBS AND UNIX) + set_tests_properties(SSLConfigTest AuthTests SignTests PROPERTIES + ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/bankid:$ENV{LD_LIBRARY_PATH}" + ) +endif() \ No newline at end of file From 2c9bdd93e94c407adeabbf487c16d4ddf7365170 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 02:52:28 +0200 Subject: [PATCH 33/36] Update CI workflow: streamline Clang 19 installation and remove unused file_exists function --- .github/workflows/build-test-check.yml | 6 +--- bankid/bankid.cpp | 5 ---- bankid/includes/bankid.h | 41 +++++++++++++------------- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 3be1ab4..17fec91 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -45,11 +45,7 @@ jobs: - name: Install Clang 19 run: | sudo apt-get update - sudo apt-get install -y wget gnupg lsb-release ninja-build - which ninja - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 19 + sudo apt-get install -y clang-19 ninja-build - name: Configure with Clang 19 run: | diff --git a/bankid/bankid.cpp b/bankid/bankid.cpp index 16e3f4d..789a8b3 100644 --- a/bankid/bankid.cpp +++ b/bankid/bankid.cpp @@ -1,10 +1,5 @@ #include "bankid.h" -// Implementation of file_exists function -bool file_exists(const std::string &path) -{ - return std::filesystem::exists(path); -} namespace BankID { diff --git a/bankid/includes/bankid.h b/bankid/includes/bankid.h index 0e5f6e7..941a68b 100644 --- a/bankid/includes/bankid.h +++ b/bankid/includes/bankid.h @@ -16,29 +16,27 @@ using json = nlohmann::json; #ifdef _WIN32 - #ifdef BANKID_STATIC - #define BANKID_API - #elif defined(BANKID_EXPORTS) - #define BANKID_API __declspec(dllexport) - #else - #define BANKID_API __declspec(dllimport) - #endif - // Suppress C4251 warnings for STL types in DLL interface - #pragma warning(push) - #pragma warning(disable : 4251) +#ifdef BANKID_STATIC +#define BANKID_API +#elif defined(BANKID_EXPORTS) +#define BANKID_API __declspec(dllexport) #else - #ifdef BANKID_EXPORTS - #define BANKID_API __attribute__((visibility("default"))) - #else - #define BANKID_API - #endif +#define BANKID_API __declspec(dllimport) +#endif +// Suppress C4251 warnings for STL types in DLL interface +#pragma warning(push) +#pragma warning(disable : 4251) +#else +#ifdef BANKID_EXPORTS +#define BANKID_API __attribute__((visibility("default"))) +#else +#define BANKID_API +#endif #endif - -// Forward declaration - implementation in bankid.cpp -bool file_exists(const std::string &path); namespace BankID { + struct BANKID_API AppConfig { std::string appIdentifier; @@ -92,6 +90,7 @@ namespace BankID } }; + /** SSL configuration structure * This structure contains the SSL configuration for the BankID API. * It includes the environment, CA file path, PEM certificate path, and PEM key path. @@ -151,16 +150,16 @@ namespace BankID std::expected validate() const { // Verify certificate files exist - if (!file_exists(this->pemCertPath)) + if (!std::filesystem::exists(this->pemCertPath)) { return std::unexpected("Certificate file does not exist: " + this->pemCertPath); } - if (!file_exists(this->pemKeyPath)) + if (!std::filesystem::exists(this->pemKeyPath)) { return std::unexpected("Key file does not exist: " + this->pemKeyPath); } - if (!file_exists(this->caFilePath)) + if (!std::filesystem::exists(this->caFilePath)) { return std::unexpected("CA file does not exist: " + this->caFilePath); } From 91e49deb01254917ab94577eb537dbe858bf66b4 Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 02:56:43 +0200 Subject: [PATCH 34/36] Refactor CI workflow: remove unnecessary CMake preset setup and simplify CMake configuration step --- .github/workflows/build-test-check.yml | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 17fec91..68f84e7 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -66,23 +66,10 @@ jobs: run: | conan install . -s build_type=${{ matrix.config.conan_profile }} -of=conan/${{ matrix.config.build_type == 'Debug' && 'debug' || 'release' }} --build=missing - - name: Set up CMake preset name - id: cmake_preset - run: | - if [ "${{ matrix.config.shared }}" = "true" ]; then - # For shared builds, we need to use the shared presets (though they don't exist in the current config) - # We'll use the regular presets and override BUILD_SHARED_LIBS - echo "preset=${{ matrix.config.cmake_preset }}" >> $GITHUB_OUTPUT - echo "shared_flag=-DBUILD_SHARED_LIBS=ON" >> $GITHUB_OUTPUT - else - echo "preset=${{ matrix.config.cmake_preset }}" >> $GITHUB_OUTPUT - echo "shared_flag=-DBUILD_SHARED_LIBS=OFF" >> $GITHUB_OUTPUT - fi - - name: Configure CMake run: | export PATH="/usr/bin:$PATH" - cmake --preset ${{ steps.cmake_preset.outputs.preset }} ${{ steps.cmake_preset.outputs.shared_flag }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja + cmake --preset ${{ matrix.config.cmake_preset }} -DCMAKE_MAKE_PROGRAM=/usr/bin/ninja - name: Build project run: | @@ -92,7 +79,7 @@ jobs: if: ${{ matrix.config.build_type == 'Debug' }} run: | cd build/${{ matrix.config.cmake_preset }}/tests - ctest -C ${{ matrix.config.build_type }} --output-on-failure --parallel $(nproc) + ctest -C ${{ matrix.config.build_type }} --output-on-failure - name: Upload build artifacts (on failure) if: failure() From 29f14a834d7ee9c497bba2910052b7f929db421c Mon Sep 17 00:00:00 2001 From: Forsrobin Date: Sat, 26 Jul 2025 03:01:59 +0200 Subject: [PATCH 35/36] Update CI workflow: reintroduce Release configuration and remove commented static build options --- .github/workflows/build-test-check.yml | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-test-check.yml b/.github/workflows/build-test-check.yml index 68f84e7..ac4d667 100644 --- a/.github/workflows/build-test-check.yml +++ b/.github/workflows/build-test-check.yml @@ -9,26 +9,14 @@ jobs: strategy: matrix: config: - # - name: 'Release Static' - # build_type: 'Release' - # conan_profile: 'Release' - # cmake_preset: 'unix-rel-ninja' - # shared: false - # - name: "Release Shared" - # build_type: "Release" - # conan_profile: "Release" - # cmake_preset: "unix-rel-ninja" # Will be modified for shared - # shared: true - # - name: "Debug Static" - # build_type: "Debug" - # conan_profile: "Debug" - # cmake_preset: "unix-deb-ninja" - # shared: false - - name: "Debug Shared" + - name: "Release" + build_type: "Release" + conan_profile: "Release" + cmake_preset: "unix-rel-ninja" # Will be modified for shared + - name: "Debug" build_type: "Debug" conan_profile: "Debug" cmake_preset: "unix-deb-ninja" # Will be modified for shared - shared: true runs-on: ubuntu-latest name: ${{ matrix.config.name }} From 2d1344d83743d17f57d554de16dcc5f4c6eba4c0 Mon Sep 17 00:00:00 2001 From: forsrobin Date: Sat, 26 Jul 2025 11:25:47 +0100 Subject: [PATCH 36/36] Refactor error handling: wrap status codes in a struct for improved clarity and consistency --- bankid/bankid.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bankid/bankid.cpp b/bankid/bankid.cpp index 789a8b3..304abe5 100644 --- a/bankid/bankid.cpp +++ b/bankid/bankid.cpp @@ -5,7 +5,7 @@ namespace BankID { // New Session implementation using SSLConfig only Session::Session(const SSLConfig &sslConfig, const bool showDebugLog) - : m_sslConfig(sslConfig), m_initialized(false), m_cli(nullptr), m_showDebugLog(showDebugLog) + : m_sslConfig(sslConfig), m_cli(nullptr), m_initialized(false), m_showDebugLog(showDebugLog) { m_initialized = initialize(); } @@ -110,7 +110,7 @@ namespace BankID } return std::unexpected(BankID::AuthError{ - 500, + {500}, BankID::BankIdErrorCode::NOT_INITIALIZED, "Session not initialized"}); } @@ -144,7 +144,7 @@ namespace BankID } return std::unexpected(AuthError{ - 403, + {403}, BankIdErrorCode::INTERNAL_ERROR, "SSL server verification failed"}); } @@ -166,7 +166,7 @@ namespace BankID catch (const std::exception &e) { return std::unexpected(AuthError{ - res->status, + {res->status}, BankIdErrorCode::INVALID_PARAMETERS, std::string("Failed to parse response: ") + e.what()}); } @@ -177,7 +177,7 @@ namespace BankID if (it != customErrors.end()) { return std::unexpected(AuthError{ - res->status, + {res->status}, BankIdErrorCode::INVALID_PARAMETERS, // Or let caller map their own code it->second}); } @@ -242,7 +242,7 @@ namespace BankID } return std::unexpected(AuthError{ - res->status, + {res->status}, errorCode, res->body}); } @@ -282,7 +282,7 @@ namespace BankID } return std::unexpected(AuthError{ - res->status, + {res->status}, errorCode, std::string("Non-JSON error response: ") + e.what() + " - " + res->body}); } @@ -304,14 +304,14 @@ namespace BankID if (defIt != defaultErrors.end()) { return std::unexpected(AuthError{ - res->status, + {res->status}, defIt->second.first, defIt->second.second}); } // Fallback for unknown codes return std::unexpected(AuthError{ - res->status, + {res->status}, BankIdErrorCode::INTERNAL_ERROR, "Unhandled HTTP error"}); } @@ -369,7 +369,7 @@ namespace BankID { int seconds = getElapsedSeconds(); if (isExpired()) - return std::unexpected(BankID::API::ErrorResponse{404, "QR code expired", "The QR code has expired after 30 seconds."}); + return std::unexpected(BankID::API::ErrorResponse{{404}, "QR code expired", "The QR code has expired after 30 seconds."}); std::string authCode = computeAuthCode(seconds); return "bankid." + m_qr_start_token + "." + std::to_string(seconds) + "." + authCode;