Skip to content

Commit c651d51

Browse files
committed
query libgfortran/libquadmath from fpm directly
1 parent d6ba8aa commit c651d51

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

.github/workflows/CI.yml

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,54 @@ jobs:
6969

7070
# Phase 1: Bootstrap fpm with existing version
7171
- name: Install fpm
72-
uses: fortran-lang/setup-fpm@v7
72+
uses: fortran-lang/setup-fpm@v8
7373
with:
7474
fpm-version: 'v0.12.0'
7575

76-
# Backport gfortran shared libraries to gcc@12 folder. This is necessary because the macOS x86_64 release
77-
# of fpm v0.12.0 used for bootstrapping was built with gcc@12 and has these paths hardcoded in the executable.
76+
# Backport gfortran shared libraries to the paths expected by the bootstrap fpm binary.
77+
# The macOS x86_64 release used for bootstrapping has hardcoded library paths from the gcc version
78+
# it was built with. Query those paths using otool and create symlinks to the current gcc version.
7879
# On ARM64 it runs under Rosetta 2 and needs /usr/local paths.
7980
- name: MacOS patch libgfortran
8081
if: contains(matrix.os, 'macos')
8182
run: |
8283
which gfortran-${{ matrix.toolchain.version }}
8384
which gfortran
8485
BREW_PREFIX=$(brew --prefix)
85-
# x86_64 bootstrap binary expects gcc@12 libraries at /usr/local (runs natively on x86_64, under Rosetta 2 on ARM64)
86-
sudo mkdir -p /usr/local/opt/gcc@12/lib/gcc/12
87-
sudo mkdir -p /usr/local/lib/gcc/12
88-
sudo ln -fs ${BREW_PREFIX}/opt/gcc@${{ matrix.toolchain.version }}/lib/gcc/${{ matrix.toolchain.version }}/libquadmath.0.dylib /usr/local/opt/gcc@12/lib/gcc/12/libquadmath.0.dylib
89-
sudo ln -fs ${BREW_PREFIX}/opt/gcc@${{ matrix.toolchain.version }}/lib/gcc/${{ matrix.toolchain.version }}/libgfortran.5.dylib /usr/local/opt/gcc@12/lib/gcc/12/libgfortran.5.dylib
90-
sudo ln -fs ${BREW_PREFIX}/lib/gcc/${{ matrix.toolchain.version }}/libgcc_s.1.dylib /usr/local/lib/gcc/12/libgcc_s.1.dylib
86+
87+
# Query the actual library paths that fpm expects
88+
echo "Checking library dependencies of fpm bootstrap binary..."
89+
otool -L $(which fpm)
90+
91+
# Extract the expected libgfortran path and create the target directory
92+
LIBGFORTRAN_PATH=$(otool -L $(which fpm) | grep libgfortran | awk '{print $1}' | head -n 1)
93+
if [ -n "$LIBGFORTRAN_PATH" ]; then
94+
TARGET_DIR=$(dirname "$LIBGFORTRAN_PATH")
95+
echo "Creating directory: $TARGET_DIR"
96+
sudo mkdir -p "$TARGET_DIR"
97+
echo "Linking libgfortran from ${BREW_PREFIX}/opt/gcc@${{ matrix.toolchain.version }}/lib/gcc/${{ matrix.toolchain.version }}/libgfortran.5.dylib to $LIBGFORTRAN_PATH"
98+
sudo ln -fs ${BREW_PREFIX}/opt/gcc@${{ matrix.toolchain.version }}/lib/gcc/${{ matrix.toolchain.version }}/libgfortran.5.dylib "$LIBGFORTRAN_PATH"
99+
fi
100+
101+
# Extract the expected libquadmath path and create the target directory
102+
LIBQUADMATH_PATH=$(otool -L $(which fpm) | grep libquadmath | awk '{print $1}' | head -n 1)
103+
if [ -n "$LIBQUADMATH_PATH" ]; then
104+
TARGET_DIR=$(dirname "$LIBQUADMATH_PATH")
105+
echo "Creating directory: $TARGET_DIR"
106+
sudo mkdir -p "$TARGET_DIR"
107+
echo "Linking libquadmath from ${BREW_PREFIX}/opt/gcc@${{ matrix.toolchain.version }}/lib/gcc/${{ matrix.toolchain.version }}/libquadmath.0.dylib to $LIBQUADMATH_PATH"
108+
sudo ln -fs ${BREW_PREFIX}/opt/gcc@${{ matrix.toolchain.version }}/lib/gcc/${{ matrix.toolchain.version }}/libquadmath.0.dylib "$LIBQUADMATH_PATH"
109+
fi
110+
111+
# Extract the expected libgcc_s path and create the target directory
112+
LIBGCC_PATH=$(otool -L $(which fpm) | grep libgcc_s | awk '{print $1}' | head -n 1)
113+
if [ -n "$LIBGCC_PATH" ]; then
114+
TARGET_DIR=$(dirname "$LIBGCC_PATH")
115+
echo "Creating directory: $TARGET_DIR"
116+
sudo mkdir -p "$TARGET_DIR"
117+
echo "Linking libgcc_s from ${BREW_PREFIX}/lib/gcc/${{ matrix.toolchain.version }}/libgcc_s.1.dylib to $LIBGCC_PATH"
118+
sudo ln -fs ${BREW_PREFIX}/lib/gcc/${{ matrix.toolchain.version }}/libgcc_s.1.dylib "$LIBGCC_PATH"
119+
fi
91120
92121
# gcc and g++ will point to clang/clang++: use versioned alias for fpm
93122
- name: MacOS patch C and C++ compilers

0 commit comments

Comments
 (0)