Skip to content

Commit

Permalink
Update cmake-multi-platform.yml to try to cross compile
Browse files Browse the repository at this point in the history
  • Loading branch information
YSaxon authored Mar 8, 2024
1 parent 476d7e8 commit 0d9cd43
Showing 1 changed file with 62 additions and 13 deletions.
75 changes: 62 additions & 13 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,27 @@ jobs:
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest, windows-latest, macos-latest]
arch: [x86, x64, arm, arm64, riscv64]
exclude:
- os: macos-latest
arch: arm
- os: macos-latest
arch: arm64
- os: macos-latest
arch: riscv64
- os: windows-latest
arch: arm
- os: windows-latest
arch: arm64
- os: windows-latest
arch: riscv64
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
Expand All @@ -36,13 +56,7 @@ jobs:
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl


steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -81,13 +95,48 @@ jobs:
choco install -y libffi
echo "C:\Program Files\libffi\lib" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Set up Cross-Compilation Toolchains (Ubuntu)
if: runner.os == 'Linux'
run: |
if [ "${{ matrix.arch }}" == "arm" ]; then
echo "CC=arm-linux-gnueabi-gcc" >> $GITHUB_ENV
elif [ "${{ matrix.arch }}" == "arm64" ]; then
echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
elif [ "${{ matrix.arch }}" == "riscv64" ]; then
echo "CC=riscv64-linux-gnu-gcc" >> $GITHUB_ENV
fi
- name: Configure CMake (Ubuntu)
if: runner.os == 'Linux'
run: |
if [ "${{ matrix.arch }}" == "x86" ]; then
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-m32"
elif [ "${{ matrix.arch }}" == "x64" ]; then
cmake -B build -DCMAKE_BUILD_TYPE=Release
elif [ "${{ matrix.arch }}" == "arm" ]; then
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm.cmake
elif [ "${{ matrix.arch }}" == "arm64" ]; then
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-arm64.cmake
elif [ "${{ matrix.arch }}" == "riscv64" ]; then
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-riscv64.cmake
fi
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}

- name: Run Tests (Ubuntu)
if: runner.os == 'Linux'
run: |
if [ "${{ matrix.arch }}" == "x86" ] || [ "${{ matrix.arch }}" == "x64" ]; then
cd build && ctest -C Release
else
cd build && qemu-${{ matrix.arch }} -L /usr/${{ matrix.arch }}-linux-gnu ctest -C Release
fi
- name: Run Tests (macOS or Windows)
if: runner.os != 'Linux'
run: |
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}

0 comments on commit 0d9cd43

Please sign in to comment.