Skip to content

Commit

Permalink
Fix issue with installation of gfortran 11
Browse files Browse the repository at this point in the history
On my own repo I had issues running programs compiled with gfortran 11 in CI.
It turned out they were being compiled with gfortran 11, but were picking up
libgfortran-5.dll from /c/mingw64/bin, which is from gcc 12, at runtime, and would
crash.

I've modified hw.90 to reproduce the problem as minimally as I can, although perhaps
someone else can make it more minimal.

I've temporarily added an intentionally failing action to demonstrate the issue,
obviously we would remove that ahead of merging.

I also added gcc 12 to the test matrix. It claims to be supported so it seems only
logical to test it in addition to 11 and 13.
  • Loading branch information
nbelakovski committed Dec 20, 2023
1 parent 05091bb commit bdff5be
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .github/actions/test-fc/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,23 @@ runs:
args="-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
fi
fi
${{ env.FC }} $args -o hw hw.f90
output=$(./hw '2>&1')
[[ "$output" == *"hello world"* ]] && echo "$output" || (echo "Unexpected Fortran program output: $output"; exit 1)
rm hw
- name: Test compile (bash) (intentionally failing)
if: ${{ runner.os == 'Windows' && inputs.compiler == 'gcc' && inputs.version == '11' }}
shell: bash
run: |
set -x
# Move the old libgfortran-5.dll back to its original place.
mv "$RUNNER_TEMP/mingw64/libgfortran-5.dll" /c/mingw64/bin/libgfortran-5.dll
# Confirm that we find the gcc12 one ahead of the gcc11 one.
which -a libgfortran-5.dll
${{ env.FC }} $args -o hw hw.f90
output=$(./hw '2>&1')
[[ "$output" == *"hello world"* ]] && echo "$output" || (echo "Unexpected Fortran program output: $output"; exit 1)
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
- windows-2022
- windows-2019
toolchain:
- {compiler: gcc, version: 11}
- {compiler: gcc, version: 12}
- {compiler: gcc, version: 13}
- {compiler: intel, version: '2023.2'}
- {compiler: intel-classic, version: '2021.10'}
Expand Down
25 changes: 22 additions & 3 deletions hw.f90
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
program hello
print *, "hello world"
end program hello
program bobyqa_exmp
implicit none

logical :: parent_logical_array(20)
integer(4), allocatable :: locations(:)

locations = true_locations(parent_logical_array)
print *, "hello world"

contains

function true_locations(logical_array) result(location_array)
implicit none
logical, intent(in) :: logical_array(:)
integer(4), allocatable :: location_array(:)
integer(4) :: n, monotone_array(size(logical_array))
n = count(logical_array)
allocate(location_array(1:n))
location_array = pack(monotone_array, mask=logical_array)

end function true_locations
end program bobyqa_exmp
1 change: 1 addition & 0 deletions setup-fortran.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ install_gcc_choco()
# otherwise hide preinstalled mingw compilers
mkdir "$RUNNER_TEMP/mingw64"
mv /c/mingw64/bin/gfortran "$RUNNER_TEMP/mingw64/gfortran"
mv /c/mingw64/bin/libgfortran-5.dll "$RUNNER_TEMP/mingw64/libgfortran-5.dll"
mv /c/mingw64/bin/gcc "$RUNNER_TEMP/mingw64/gcc"
mv /c/mingw64/bin/g++ "$RUNNER_TEMP/mingw64/g++"
# ...and install selected version
Expand Down

0 comments on commit bdff5be

Please sign in to comment.