@@ -208,7 +208,8 @@ jobs:
208208 # Only install gcc if not already available
209209 which gfortran-${{ env.GCC_V }} || brew install gcc@${{ env.GCC_V }}
210210 which gfortran-${{ env.GCC_V }}
211- which gfortran || ln -s /usr/local/bin/gfortran-${{ env.GCC_V }} /usr/local/bin/gfortran
211+ BREW_PREFIX=$(brew --prefix)
212+ which gfortran || ln -s ${BREW_PREFIX}/bin/gfortran-${{ env.GCC_V }} ${BREW_PREFIX}/bin/gfortran
212213
213214 - name : (macOS) Install homebrew MPICH
214215 if : contains(matrix.mpi,'mpich') && contains(matrix.os,'macos')
@@ -231,26 +232,91 @@ jobs:
231232 brew install netcdf
232233 brew install netcdf-fortran
233234
234- - name : (macOS) Patch gfortran paths
235- if : contains(matrix.os,'macos')
236- run : |
237- # Backport gfortran shared libraries to version 10 folder. This is necessary because all macOS releases of fpm
238- # have these paths hardcoded in the executable (no PIC?). Current bootstrap version 0.8.0 has gcc-10
239- mkdir /usr/local/opt/gcc@10
240- mkdir /usr/local/opt/gcc@10/lib
241- mkdir /usr/local/opt/gcc@10/lib/gcc
242- mkdir /usr/local/opt/gcc@10/lib/gcc/10
243- mkdir /usr/local/lib/gcc/10
244- ln -fs /usr/local/opt/gcc@${{ env.GCC_V }}/lib/gcc/${{ env.GCC_V }}/libquadmath.0.dylib /usr/local/opt/gcc@10/lib/gcc/10/libquadmath.0.dylib
245- ln -fs /usr/local/opt/gcc@${{ env.GCC_V }}/lib/gcc/${{ env.GCC_V }}/libgfortran.5.dylib /usr/local/opt/gcc@10/lib/gcc/10/libgfortran.5.dylib
246- # Newer gcc versions use libgcc_s.1.1.dylib
247- ln -fs /usr/local/lib/gcc/${{ env.GCC_V }}/libgcc_s.1.dylib /usr/local/lib/gcc/10/libgcc_s.1.dylib || ln -fs /usr/local/lib/gcc/${{ env.GCC_V }}/libgcc_s.1.1.dylib /usr/local/lib/gcc/10/libgcc_s.1.dylib
248-
249235 # Phase 1: Bootstrap fpm with existing version
250236 - name : Install fpm
251- uses : fortran-lang/setup-fpm@v7
237+ uses : fortran-lang/setup-fpm@v8
252238 with :
253- fpm-version : ' v0.8.0'
239+ fpm-version : ' v0.12.0'
240+
241+ # Backport gfortran shared libraries to the paths expected by the bootstrap fpm binary.
242+ # The macOS x86_64 release used for bootstrapping has hardcoded library paths from the gcc version
243+ # it was built with. If the versions match, skip this step. Otherwise, create symlinks.
244+ # On ARM64 it runs under Rosetta 2 and needs /usr/local paths.
245+ - name : MacOS patch libgfortran
246+ if : contains(matrix.os, 'macos')
247+ run : |
248+ which gfortran-${{ env.GCC_V }}
249+ which gfortran || true
250+ BREW_PREFIX=$(brew --prefix)
251+
252+ # Query the actual library paths that fpm expects
253+ echo "Checking library dependencies of fpm bootstrap binary..."
254+ otool -L $(which fpm)
255+
256+ # Extract the gcc version from the bootstrap binary's library paths
257+ BOOTSTRAP_GCC_VERSION=$(otool -L $(which fpm) | grep -o 'gcc@[0-9]\+' | head -n 1 | cut -d@ -f2)
258+ if [ -z "$BOOTSTRAP_GCC_VERSION" ]; then
259+ # Try alternative pattern: /lib/gcc/13/ -> extract 13
260+ BOOTSTRAP_GCC_VERSION=$(otool -L $(which fpm) | grep libgfortran | grep -o '/lib/gcc/[0-9]\+/' | grep -o '[0-9]\+' | head -n 1)
261+ fi
262+
263+ echo "Bootstrap fpm built with gcc@$BOOTSTRAP_GCC_VERSION"
264+ echo "Current toolchain: gcc@${{ env.GCC_V }}"
265+
266+ if [ "$BOOTSTRAP_GCC_VERSION" == "${{ env.GCC_V }}" ]; then
267+ echo "✓ Bootstrap gcc version matches current toolchain - no patching needed"
268+ exit 0
269+ fi
270+
271+ echo "⚠ Version mismatch detected - creating compatibility symlinks..."
272+
273+ # Find the actual Cellar path by following the symlink
274+ if [ -L "${BREW_PREFIX}/opt/gcc@${{ env.GCC_V }}" ]; then
275+ GCC_CELLAR_PATH=$(cd -P "${BREW_PREFIX}/opt/gcc@${{ env.GCC_V }}" && pwd)
276+ else
277+ GCC_CELLAR_PATH="${BREW_PREFIX}/Cellar/gcc@${{ env.GCC_V }}"/*
278+ fi
279+ echo "GCC Cellar path: $GCC_CELLAR_PATH"
280+
281+ # Find the actual library files
282+ CURRENT_GFORTRAN=$(find "$GCC_CELLAR_PATH"/lib/gcc/${{ env.GCC_V }} -name "libgfortran.*.dylib" 2>/dev/null | head -n 1)
283+ CURRENT_QUADMATH=$(find "$GCC_CELLAR_PATH"/lib/gcc/${{ env.GCC_V }} -name "libquadmath.*.dylib" 2>/dev/null | head -n 1)
284+ CURRENT_GCC_S=$(find "$GCC_CELLAR_PATH"/lib/gcc/${{ env.GCC_V }} -name "libgcc_s.*.dylib" 2>/dev/null | head -n 1)
285+
286+ echo "Current gcc@${{ env.GCC_V }} libraries:"
287+ echo " libgfortran: $CURRENT_GFORTRAN"
288+ echo " libquadmath: $CURRENT_QUADMATH"
289+ echo " libgcc_s: $CURRENT_GCC_S"
290+
291+ # Extract the expected libgfortran path and create symlink
292+ LIBGFORTRAN_PATH=$(otool -L $(which fpm) | grep libgfortran | awk '{print $1}' | head -n 1)
293+ if [ -n "$LIBGFORTRAN_PATH" ] && [ -n "$CURRENT_GFORTRAN" ]; then
294+ TARGET_DIR=$(dirname "$LIBGFORTRAN_PATH")
295+ echo "Creating directory: $TARGET_DIR"
296+ sudo mkdir -p "$TARGET_DIR"
297+ echo "Linking $CURRENT_GFORTRAN to $LIBGFORTRAN_PATH"
298+ sudo ln -fs "$CURRENT_GFORTRAN" "$LIBGFORTRAN_PATH"
299+ fi
300+
301+ # Extract the expected libquadmath path and create symlink
302+ LIBQUADMATH_PATH=$(otool -L $(which fpm) | grep libquadmath | awk '{print $1}' | head -n 1)
303+ if [ -n "$LIBQUADMATH_PATH" ] && [ -n "$CURRENT_QUADMATH" ]; then
304+ TARGET_DIR=$(dirname "$LIBQUADMATH_PATH")
305+ echo "Creating directory: $TARGET_DIR"
306+ sudo mkdir -p "$TARGET_DIR"
307+ echo "Linking $CURRENT_QUADMATH to $LIBQUADMATH_PATH"
308+ sudo ln -fs "$CURRENT_QUADMATH" "$LIBQUADMATH_PATH"
309+ fi
310+
311+ # Extract the expected libgcc_s path and create symlink
312+ LIBGCC_PATH=$(otool -L $(which fpm) | grep libgcc_s | awk '{print $1}' | head -n 1)
313+ if [ -n "$LIBGCC_PATH" ] && [ -n "$CURRENT_GCC_S" ]; then
314+ TARGET_DIR=$(dirname "$LIBGCC_PATH")
315+ echo "Creating directory: $TARGET_DIR"
316+ sudo mkdir -p "$TARGET_DIR"
317+ echo "Linking $CURRENT_GCC_S to $LIBGCC_PATH"
318+ sudo ln -fs "$CURRENT_GCC_S" "$LIBGCC_PATH"
319+ fi
254320
255321 - name : Remove fpm from path
256322 shell : bash
0 commit comments