Build MATLAB MEX #441
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | name: Build MATLAB MEX | |
| on: | |
| # Weekly schedule (Sunday 00:00 UTC) | |
| schedule: | |
| - cron: "0 0 * * 0" | |
| # On tag push | |
| push: | |
| tags: | |
| - 'v*' | |
| # Manual trigger (with an optional deploy toggle) | |
| workflow_dispatch: | |
| inputs: | |
| deploy: | |
| description: "Deploy after build?" | |
| type: boolean | |
| required: false | |
| default: false | |
| jobs: | |
| mex: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-22.04 | |
| - os: windows-2022 | |
| # - os: macos-13 this requires matlab openmp to work. | |
| - os: macos-14 | |
| - os: macos-15 | |
| name: ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup C++ toolchain | |
| uses: aminya/[email protected] | |
| with: | |
| cmake: true | |
| ninja: true | |
| vcvarsall: true | |
| - name: Select Xcode 16.0 (macOS 15 only) | |
| if: ${{ runner.os == 'macOS' && matrix.os == 'macos-15' }} | |
| uses: maxim-lobanov/setup-xcode@v1 | |
| with: | |
| xcode-version: '16.0' | |
| - name: Set macOS deployment target | |
| if: runner.os == 'macOS' | |
| shell: bash | |
| run: | | |
| xcodebuild -version | |
| brew install fftw libomp | |
| echo "LDFLAGS=-L$(brew --prefix libomp)/lib" >> $GITHUB_ENV | |
| echo "CPPFLAGS=-I$(brew --prefix libomp)/include" >> $GITHUB_ENV | |
| echo "LIBRARY_PATH=$(brew --prefix libomp)/lib" >> $GITHUB_ENV | |
| echo "DYLD_LIBRARY_PATH=$(brew --prefix libomp)/lib" >> $GITHUB_ENV | |
| echo "CMAKE_PREFIX_PATH=$(brew --prefix):$(brew --prefix libomp)" >> $GITHUB_ENV | |
| ver="${{ matrix.os }}"; ver="${ver#macos-}" | |
| echo "MACOSX_DEPLOYMENT_TARGET=${ver}.0" >> "$GITHUB_ENV" | |
| # Install CUDA on non-macOS runners | |
| - name: Install CUDA Toolkit (non-macOS) | |
| if: runner.os != 'macOS' | |
| uses: Jimver/[email protected] | |
| with: | |
| cuda: '12.4.0' | |
| method: 'network' | |
| linux-local-args: '["--toolkit"]' | |
| log-file-suffix: '${{matrix.os}}-cuda-install.txt' | |
| sub-packages: ${{runner.os == 'Linux' && '["nvcc", "cudart"]' || '["nvcc", "cudart", "cufft", "cufft_dev"]'}} | |
| non-cuda-sub-packages: ${{runner.os == 'Linux' && '["libcufft","libcufft-dev"]' || '[]'}} | |
| use-local-cache: 'false' | |
| use-github-cache: 'false' #it is not working at the moment https://github.com/Jimver/cuda-toolkit/issues/390 | |
| - name: Set up MATLAB | |
| uses: matlab-actions/setup-matlab@v2 | |
| with: | |
| release: R2023b | |
| products: Parallel_Computing_Toolbox | |
| cache: false | |
| - name: Detect mexext via MATLAB | |
| uses: matlab-actions/run-command@v2 | |
| with: | |
| command: | | |
| me = mexext; % e.g., mexa64|mexw64|mexmaci64|mexmaca64 | |
| fprintf('Detected mexext: %s\n', me); | |
| f = fopen(getenv('GITHUB_ENV'), 'a'); | |
| fprintf(f, 'MEXEXT=%s\n', me); | |
| fclose(f); | |
| - name: Configure & Build | |
| shell: bash | |
| run: | | |
| # Ensure MATLAB is on PATH if provided by setup-matlab | |
| if [ -n "${MATLAB_ROOT:-}" ]; then export PATH="${MATLAB_ROOT}/bin:${PATH}"; fi | |
| # Enable CUDA if not macOS | |
| CUDA_FLAG="" | |
| if [ "${RUNNER_OS}" != "macOS" ]; then | |
| CUDA_FLAG="-DFINUFFT_USE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=50;60;70;80;89" | |
| fi | |
| # Map MEXEXT to arch dir for any path logic you might need | |
| case "$MEXEXT" in | |
| mexa64) MATLAB_ARCH_DIR=glnxa64 ;; | |
| mexw64) MATLAB_ARCH_DIR=win64 ;; | |
| mexmaci64) MATLAB_ARCH_DIR=maci64 ;; | |
| mexmaca64) MATLAB_ARCH_DIR=maca64 ;; | |
| *) echo "Unknown MEXEXT=$MEXEXT"; exit 1;; | |
| esac | |
| echo "MEXEXT=$MEXEXT, MATLAB_ARCH_DIR=$MATLAB_ARCH_DIR" | |
| # On macOS, force Apple Silicon build so we don't accidentally target x86_64 | |
| EXTRA_MACOS_FLAGS="" | |
| if [ "${RUNNER_OS}" = "macOS" ]; then | |
| EXTRA_MACOS_FLAGS="-DCMAKE_OSX_ARCHITECTURES=arm64" | |
| fi | |
| cmake -S . -B build -G Ninja \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DFINUFFT_USE_DUCC0=ON \ | |
| -DFINUFFT_USE_OPENMP=ON \ | |
| -DFINUFFT_MATLAB_INSTALL=ON \ | |
| -DMatlab_MEX_EXTENSION="${MEXEXT}" \ | |
| -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded$<$<CONFIG:Debug>:Debug>" \ | |
| ${CUDA_FLAG} | |
| cmake --build build --verbose --target finufft_mex --parallel | |
| if [ "${RUNNER_OS}" != "macOS" ]; then | |
| cmake --build build --verbose --target cufinufft_mex --parallel | |
| fi | |
| - name: Run fullmathtest.m | |
| uses: matlab-actions/run-command@v2 | |
| with: | |
| command: | | |
| addpath(genpath('matlab')); | |
| addpath(genpath('build')); | |
| fullmathtest | |
| - name: Package with CPack | |
| shell: bash | |
| run: cmake --build build --target package | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: finufft-matlab-mex-${{ matrix.os }} | |
| path: | | |
| build/*.zip | |
| build/*.tar.gz | |
| if-no-files-found: error |