From 4d80d415bb19d5f09e72644828100cf2ae65d9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Fri, 7 Aug 2026 20:13:45 +0200 Subject: [PATCH] FIX: Add Windows export handling and downstream consumer CI Add a Windows-specific `CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS` setting in the top-level CMake configuration so shared-library builds on Windows export symbols explicitly. Extend CI with a downstream consumer job that installs `trx-cpp`, runs a minimal `find_package(trx-cpp CONFIG REQUIRED)` build, and verifies the package can be consumed after the main build succeeds. This helps catch Windows packaging/export regressions that a self-build does not surface, while keeping the existing build and test workflow intact. --- .github/workflows/ci.yml | 91 ++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 3 ++ 2 files changed, 94 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef2468b..da058ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -227,3 +227,94 @@ jobs: - name: Test run: ctest --test-dir build-zlib-only --output-on-failure -C Release + + consumer: + name: consumer ${{ matrix.os }} + needs: build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, windows-latest] + + steps: + - uses: actions/checkout@v4 + + - name: Cache vcpkg (Windows) + if: runner.os == 'Windows' + uses: actions/cache@v4 + with: + path: ${{ github.workspace }}\vcpkg_cache + key: consumer-vcpkg-${{ runner.os }}-${{ hashFiles('.github/workflows/ci.yml') }} + + - name: Install dependencies (macOS) + if: runner.os == 'macOS' + run: | + brew update + brew install libzip eigen googletest ninja zlib + + - name: Install dependencies (Windows) + if: runner.os == 'Windows' + shell: pwsh + run: | + choco install ninja -y + New-Item -ItemType Directory -Force "$env:GITHUB_WORKSPACE\vcpkg_cache" | Out-Null + git clone https://github.com/microsoft/vcpkg "$env:GITHUB_WORKSPACE\vcpkg" + & "$env:GITHUB_WORKSPACE\vcpkg\bootstrap-vcpkg.bat" + $env:VCPKG_BINARY_SOURCES="clear;files,$env:GITHUB_WORKSPACE\vcpkg_cache,readwrite" + & "$env:GITHUB_WORKSPACE\vcpkg\vcpkg.exe" install ` + libzip ` + eigen3 ` + gtest ` + zlib ` + --triplet x64-windows + + - name: Setup MSVC environment (Windows) + if: runner.os == 'Windows' + uses: ilammy/msvc-dev-cmd@v1 + + - name: Configure trx-cpp + run: | + cmake -S . -B build \ + -G Ninja \ + -DTRX_USE_CONAN=OFF \ + -DTRX_BUILD_TESTS=ON \ + -DTRX_BUILD_EXAMPLES=ON \ + -DTRX_ENABLE_NIFTI=ON \ + -DCMAKE_BUILD_TYPE=Release \ + ${{ runner.os == 'Windows' && format('-DCMAKE_TOOLCHAIN_FILE={0}/vcpkg/scripts/buildsystems/vcpkg.cmake', github.workspace) || '' }} + + - name: Build and install trx-cpp + run: cmake --build build --config Release --target install + + - name: Configure downstream consumer + shell: bash + run: | + consumer="${GITHUB_WORKSPACE}/ci-consumer" + mkdir -p "$consumer" + + cat > "$consumer/CMakeLists.txt" <<'EOF' + cmake_minimum_required(VERSION 3.16) + project(trx_consumer LANGUAGES CXX) + + find_package(trx-cpp CONFIG REQUIRED) + + add_executable(trx_consumer main.cpp) + target_link_libraries(trx_consumer PRIVATE trx-cpp::trx) + target_compile_features(trx_consumer PRIVATE cxx_std_17) + EOF + + cat > "$consumer/main.cpp" <<'EOF' + #include + int main() { + return 0; + } + EOF + + cmake -S "$consumer" -B "$consumer/build" \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_PREFIX_PATH="${GITHUB_WORKSPACE}/build" + + - name: Build downstream consumer + run: cmake --build ci-consumer/build --config Release \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 123ee78..9b3a96f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,9 @@ endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +if(WIN32) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +endif() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE Debug) endif()