Skip to content

Commit 3c97a99

Browse files
Merge pull request #402 from VincentMarnier/master
fix: windows crosscompilation and added a workflow to test it by crosscompiling on ubuntu and running tests on windows
2 parents d7aa51c + 24c8ecc commit 3c97a99

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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

common/time_util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ either expressed or implied, of the Regents of The University of Michigan.
3232
#include <time.h>
3333

3434
#ifdef _WIN32
35+
#if defined __has_include && __has_include ("winsock2.h")
36+
#include <winsock2.h>
37+
#else
3538
#include <Winsock2.h>
39+
#endif
3640
typedef long long suseconds_t;
3741
#endif
3842

0 commit comments

Comments
 (0)