|
| 1 | +name: Cross compilation |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "master" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "master" ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + # Use mingw to cross compile apriltag and its tests on linux |
| 12 | + build: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + shared_libs: ['ON','OFF'] |
| 18 | + |
| 19 | + steps: |
| 20 | + # Install required packages to build for windows |
| 21 | + - name: install dependencies |
| 22 | + run: | |
| 23 | + sudo apt update |
| 24 | + sudo apt install -y --no-install-recommends cmake ninja-build gcc-mingw-w64-x86-64 |
| 25 | +
|
| 26 | + # Get the sources |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + |
| 29 | + # Save the "build/" folder path |
| 30 | + - name: Set reusable strings |
| 31 | + id: strings |
| 32 | + shell: bash |
| 33 | + run: | |
| 34 | + echo "build-output-dir=$GITHUB_WORKSPACE/build" >> "$GITHUB_OUTPUT" |
| 35 | +
|
| 36 | + # Configure cmake |
| 37 | + # CMAKE_SYSTEM_NAME=Windows is needed else it will produce libapriltag.so instead of .dll |
| 38 | + - name: Configure CMake |
| 39 | + run: > |
| 40 | + cmake -B ${{ steps.strings.outputs.build-output-dir }} |
| 41 | + -G Ninja |
| 42 | + -D CMAKE_SYSTEM_NAME=Windows |
| 43 | + -D CMAKE_C_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc |
| 44 | + -D CMAKE_BUILD_TYPE=Release |
| 45 | + -D BUILD_SHARED_LIBS=${{ matrix.shared_libs }} |
| 46 | + -D BUILD_TESTING=ON |
| 47 | + -S $GITHUB_WORKSPACE |
| 48 | +
|
| 49 | + # Build apriltag |
| 50 | + - name: Build |
| 51 | + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} |
| 52 | + |
| 53 | + # In case of shared lib, copy the .dll file in the test directory |
| 54 | + - name: add DLL to test folder |
| 55 | + if: matrix.shared_libs == 'ON' |
| 56 | + working-directory: ${{ steps.strings.outputs.build-output-dir }} |
| 57 | + run: | |
| 58 | + cp *apriltag.dll test/ |
| 59 | +
|
| 60 | + # Upload the "build/" directory as artifact |
| 61 | + - name: Upload build artifact |
| 62 | + uses: actions/upload-artifact@v4 |
| 63 | + with: |
| 64 | + name: cross-compilation-build-sharedlib-${{ matrix.shared_libs }} |
| 65 | + path: ${{ steps.strings.outputs.build-output-dir }} |
| 66 | + |
| 67 | + # On windows, retrieve the cross compiled build and run the tests |
| 68 | + test: |
| 69 | + needs: build |
| 70 | + runs-on: windows-latest |
| 71 | + |
| 72 | + strategy: |
| 73 | + matrix: |
| 74 | + shared_libs: ['ON','OFF'] |
| 75 | + |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v4 |
| 78 | + |
| 79 | + # Save the "build/" folder path |
| 80 | + - name: Set reusable strings |
| 81 | + id: strings |
| 82 | + shell: bash |
| 83 | + run: | |
| 84 | + echo "build-output-dir=$GITHUB_WORKSPACE/build" >> "$GITHUB_OUTPUT" |
| 85 | +
|
| 86 | + # Download the "build/" directory |
| 87 | + - name: Download build artifact |
| 88 | + uses: actions/download-artifact@v4 |
| 89 | + with: |
| 90 | + name: cross-compilation-build-sharedlib-${{ matrix.shared_libs }} |
| 91 | + path: ${{ steps.strings.outputs.build-output-dir }} |
| 92 | + |
| 93 | + # Change the tests pathes so they match the windows ones instead of the linux ones |
| 94 | + - name: Change test pathes |
| 95 | + run: | |
| 96 | + (Get-Content ${{ steps.strings.outputs.build-output-dir }}/test/CTestTestfile.cmake) -replace '/home/runner/work/apriltag/apriltag', $PWD.Path.Replace('\', '/') | Set-Content ${{ steps.strings.outputs.build-output-dir }}/test/CTestTestfile.cmake |
| 97 | +
|
| 98 | + # Run the tests |
| 99 | + - name: Test |
| 100 | + working-directory: ${{ steps.strings.outputs.build-output-dir }} |
| 101 | + run: | |
| 102 | + ctest --no-tests=error --output-on-failure --verbose |
0 commit comments