Skip to content

revise setup_mex_mingw #29

revise setup_mex_mingw

revise setup_mex_mingw #29

name: Test MEX with MinGW
on:
# Trigger the workflow on push or pull request
push:
# Trigger the workflow by cron. The default time zone of GitHub Actions is UTC.
schedule:
- cron: '0 20 * * 6'
# Trigger the workflow when it is manually triggered
workflow_dispatch:
jobs:
test:
name: Test MEX
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
matlab: [R2024a, R2024b, R2025a, R2025b, R2026a, latest]
mingw: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, latest]
lang: [Fortran, C]
steps:
- name: Check out repository
uses: actions/checkout@v6.0.2
# - name: Remove Visual Studio completely
# shell: cmd
# if: startsWith(matrix.os, 'windows')
# run: |
# "C:\Program Files (x86)\Microsoft Visual Studio\Installer\InstallCleanup.exe"
- name: Remove existing gcc and gfortran installation
shell: cmd
if: startsWith(matrix.os, 'windows')
run: |
rmdir "C:\mingw64" /s /q
rmdir "C:\Strawberry" /s /q
- name: Install MinGW
# Here, we install mingw using Chocolatey. It can also be installed as a MATLAB Add-on.
# See https://www.mathworks.com/matlabcentral/fileexchange/52848-matlab-support-for-mingw-w64-c-c-fortran-compiler
shell: bash
if: startsWith(matrix.os, 'windows')
run: |
VERSION="${{ matrix.mingw }}"
if [ "$VERSION" = "latest" ]; then
choco install mingw -y --no-progress
choco upgrade mingw -y --no-progress
else
if [ "$VERSION" -eq 6 ]; then
VERSION=6.4.0
elif [ "$VERSION" -eq 7 ]; then
VERSION=7.5.0
elif [ "$VERSION" -eq 8 ]; then
VERSION=8.5.0
elif [ "$VERSION" -eq 9 ]; then
VERSION=9.4.0
elif [ "$VERSION" -eq 10 ]; then
VERSION=10.3.0
else
VERSION="${VERSION}".2.0
fi
choco install mingw --version=$VERSION -y --no-progress
fi
echo "C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin" >> $GITHUB_PATH # mingw 12 and earlier
echo "C:\ProgramData\mingw64\mingw64\bin" >> $GITHUB_PATH # mingw 13 and later
- name: Check gcc and gfortran version
if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'windows')
run: which gcc && gcc --version && which gfortran && gfortran --version
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v3.0.0
with:
release: ${{ matrix.matlab }}
cache: true
- name: Run the test
uses: matlab-actions/run-command@v3.1.0
with:
command: |
% 'MW_MINGW64_LOC' should be set to the directory containing bin\gcc.exe and bin\gfortran.exe
% See https://www.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab
if strcmpi('${{ matrix.mingw }}', 'latest') || ${{ matrix.mingw }} > 12
setenv('MW_MINGW64_LOC', 'C:\ProgramData\mingw64\mingw64')
else
setenv('MW_MINGW64_LOC', 'C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64')
end
lang = '${{ matrix.lang }}';
fprintf("\n\nTry setting mex up:\n\n");
mex -v -setup ${{ matrix.lang }}
fprintf("\n\nTry compiling the official example from MathWorks:\n\n");
mex('-v', official_mex_example(lang));
timestwo(1)