From aa481dc6d50265975bcca1f42ff814e19711a8be Mon Sep 17 00:00:00 2001 From: Martynas Gurskas Date: Fri, 22 Mar 2024 11:17:39 +0200 Subject: [PATCH] Turn test job into matrix for Linux and Windows Signed-off-by: Martynas Gurskas --- .github/workflows/cpp.yml | 73 ++++++++++++++----- build_bindgen.sh | 4 - ...scaffolding.sh => build_scaffolding_lib.sh | 2 + fixtures/Cargo.toml | 2 +- 4 files changed, 57 insertions(+), 24 deletions(-) delete mode 100755 build_bindgen.sh rename build_scaffolding.sh => build_scaffolding_lib.sh (71%) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index c63be02..7b12564 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -10,13 +10,64 @@ env: CARGO_TERM_COLOR: always jobs: - build-scaffolding: + run-tests: + runs-on: ${{ matrix.os }} + strategy: + # TODO: remove this when the workflow is stable + fail-fast: false + + matrix: + # Ubuntu-20.04 is being used here on purpose instead of ubuntu-latest due to a bug with clang and libstdc++ + # https://github.com/actions/runner-images/issues/8659 + os: [ubuntu-20.04, windows-latest] + build_type: [Release] + cpp_compiler: [g++, clang++, cl] + exclude: + - os: windows-latest + cpp_compiler: g++ + - os: windows-latest + cpp_compiler: clang++ + - os: ubuntu-20.04 + cpp_compiler: cl + + steps: + - uses: actions/checkout@v3 + + - name: Set reusable strings + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/cpp-tests/build" >> "$GITHUB_OUTPUT" + echo "build-source-dir=${{ github.workspace }}/cpp-tests" >> "$GITHUB_OUTPUT" + + - name: Install additional dependencies + shell: bash + run: | + if [ "$RUNNER_OS" == "Linux" ]; then + sudo apt update && sudo apt install -y valgrind + fi + + - name: Configure CMake + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ steps.strings.outputs.build-source-dir }} + - name: Build + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Run tests + working-directory: ${{ steps.strings.outputs.build-output-dir }} + run: ctest --build-config ${{ matrix.build_type }} + + build-scaffolding-lib: runs-on: ubuntu-latest container: image: ghcr.io/nordsecurity/uniffi-bindgen-cpp-test-runner:v0.3.0 steps: - uses: actions/checkout@v3 - - name: Build scaffolding + + - name: Build scaffolding library shell: bash env: # Github sets HOME to /github/home and breaks dependencies in Docker image.. @@ -24,28 +75,12 @@ jobs: HOME: /root run: | source ~/.bashrc - ./build_bindgen.sh - ./build_scaffolding.sh + ./build_scaffolding_lib.sh - uses: actions/upload-artifact@v3 with: name: scaffolding_lib path: cpp-tests/build/libuniffi_fixtures.so - run-tests: - runs-on: ubuntu-latest - container: - image: ghcr.io/nordsecurity/uniffi-bindgen-cpp-test-runner:v0.3.0 - steps: - - uses: actions/checkout@v3 - - name: Run tests - shell: bash - env: - HOME: /root - run: | - source ~/.bashrc - ./build_bindgen.sh - ./test_bindings.sh - test-scaffolding-go: runs-on: ubuntu-latest container: diff --git a/build_bindgen.sh b/build_bindgen.sh deleted file mode 100755 index 1fa5027..0000000 --- a/build_bindgen.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -euxo pipefail - -cargo build --release --package uniffi-bindgen-cpp diff --git a/build_scaffolding.sh b/build_scaffolding_lib.sh similarity index 71% rename from build_scaffolding.sh rename to build_scaffolding_lib.sh index c58f93d..68f010a 100755 --- a/build_scaffolding.sh +++ b/build_scaffolding_lib.sh @@ -1,6 +1,8 @@ #!/bin/bash set -euxo pipefail +cargo build --release --package uniffi-bindgen-cpp + mkdir -p cpp-tests/build cd cpp-tests/build cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/fixtures/Cargo.toml b/fixtures/Cargo.toml index 097ed1d..958d813 100644 --- a/fixtures/Cargo.toml +++ b/fixtures/Cargo.toml @@ -4,7 +4,7 @@ version = "1.0.0" edition = "2021" [lib] -crate-type = ["cdylib", "lib"] +crate-type = ["cdylib", "lib", "staticlib"] [dependencies] uniffi-example-arithmetic = { git = "https://github.com/NordSecurity/uniffi-rs.git", tag = "v0.3.1+v0.25.0" }