GitHub Actions per-job compiler
GitHub Actions workflows can use different compilers per job. This is useful for programs and libraries that need distinct compiler versions. An example of this is Matlab, where each Matlab release has a range of compatible compilers.
Implement in GitHub Actions:
jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
release: [R2021b, R2024a, latest-including-prerelease]
steps:
- name: GCC-8 (Matlab < R2022a)
if: ${{ matrix.release < 'R2022a' && matrix.release != 'latest-including-prerelease' }}
run: |
echo "CC=gcc-8" >> $GITHUB_ENV
echo "CXX=g++-8" >> $GITHUB_ENV
echo "FC=gfortran-8" >> $GITHUB_ENV
- name: GCC-10 (Matlab >= R2022a)
if: ${{ matrix.release >= 'R2022a' || matrix.release == 'latest-including-prerelease' }}
run: |
echo "CC=gcc-10" >> $GITHUB_ENV
echo "CXX=g++-10" >> $GITHUB_ENV
echo "FC=gfortran-10" >> $GITHUB_ENV
- name: Install MATLAB
uses: matlab-actions/setup-matlab
with:
release: ${{ matrix.release }}