Skip to content

Commit 911b7c6

Browse files
authored
implement version: latest for gcc, intel and lfortran, fixes #136 and #33 (#137)
Implementation of version: latest parsing, fixes #136 and #33 version: latest is now default for gcc and lfortran installations (since they use package managers) while also defaults to the latest "known" version for intel if explicitly specified in the workflow, e.g. - uses: fortran-lang/setup-fortran@v1 with: compiler: intel version: latest If the version option is not explicitly specified, the updated defaults are now: gcc: latest lfortran: latest intel-classic: 2023.2.0 (pinned) intel: 2025.0 (pinned) nvidia-hpc: 25.1 (pinned) The main changes to the logic are: install_gcc_brew: Uses brew install gcc without version pinning for version: latest install_gcc_apt: Installs gcc gfortran g++ without version pinning for version: latest install_gcc_choco: Install unpinned gcc via choco install for version: latest install_intel_apt: Installs last known version of Intel packages when version: latest, but only if version: latest explicitly specified install_lfortran_*: All platforms install unpinned lfortran when latest Note that the Cache key in action.yml uses ${{ inputs.version || 'latest' }} instead of just ${{ inputs.version }}. This ensures that when no version is specified, it defaults to 'latest' in the cache key. This should prevent cache conflicts between different "latest" installs.
1 parent e584d68 commit 911b7c6

File tree

3 files changed

+87
-51
lines changed

3 files changed

+87
-51
lines changed

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ runs:
4444
uses: actions/cache/restore@v3
4545
with:
4646
path: ${{ env.ONEAPI_ROOT }}
47-
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.version }}-${{ steps.get-date.outputs.date }}
47+
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.version || 'latest' }}-${{ steps.get-date.outputs.date }}
4848

4949
# Use micromamba for lfortran install on mac. Check if micromamba already
5050
# exists, only install it if needed. If we install it, clean it up after.
@@ -88,7 +88,7 @@ runs:
8888
uses: actions/cache/save@v3
8989
with:
9090
path: ${{ env.ONEAPI_ROOT }}
91-
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.version }}-${{ steps.get-date.outputs.date }}
91+
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.version || 'latest' }}-${{ steps.get-date.outputs.date }}
9292
- name: Activate oneAPI
9393
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
9494
shell: cmd

main.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ source ./setup-fortran.sh
1313

1414
case $compiler in
1515
gcc)
16-
version=${VERSION:-13}
16+
version=${VERSION:-latest}
1717
install_gcc $platform
1818
;;
1919
intel-classic)
@@ -29,7 +29,7 @@ case $compiler in
2929
install_nvidiahpc $platform
3030
;;
3131
lfortran)
32-
version=${VERSION:-0.45.0}
32+
version=${VERSION:-latest}
3333
install_lfortran $platform
3434
;;
3535
*)

setup-fortran.sh

Lines changed: 83 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,61 @@ install_environment_modules_apt() {
2727

2828
install_gcc_brew()
2929
{
30-
brew install --force gcc@${version}
30+
if [[ "$version" == "latest" ]]; then
31+
brew install --force gcc
32+
# detect installed version using homebrew
33+
gcc_version=$(brew list --versions gcc | grep -o '[0-9]\+' | head -1)
34+
else
35+
brew install --force gcc@${version}
36+
gcc_version=$version
37+
fi
3138

3239
# make an unversioned symlink
3340
os_ver=$(sw_vers -productVersion | cut -d'.' -f1)
3441
if (( "$os_ver" > 13 )); then
3542
# default homebrew bin dir changed with macos 14
36-
ln -fs /opt/homebrew/bin/gfortran-${version} /usr/local/bin/gfortran
37-
ln -fs /opt/homebrew/bin/gcc-${version} /usr/local/bin/gcc
38-
ln -fs /opt/homebrew/bin/g++-${version} /usr/local/bin/g++
43+
bindir=/opt/homebrew/bin
3944
else
40-
ln -fs /usr/local/bin/gfortran-${version} /usr/local/bin/gfortran
41-
ln -fs /usr/local/bin/gcc-${version} /usr/local/bin/gcc
42-
ln -fs /usr/local/bin/g++-${version} /usr/local/bin/g++
45+
bindir=/usr/local/bin
4346
fi
47+
48+
ln -fs ${bindir}/gfortran-${gcc_version} /usr/local/bin/gfortran
49+
ln -fs ${bindir}/gcc-${gcc_version} /usr/local/bin/gcc
50+
ln -fs ${bindir}/g++-${gcc_version} /usr/local/bin/g++
4451
}
4552

4653
install_gcc_apt()
4754
{
48-
# Check whether the system gcc version is the version we are after.
49-
cur=$(apt show gcc | grep "Version" | cut -d':' -f3 | cut -d'-' -f1)
50-
maj=$(echo $cur | cut -d'.' -f1)
51-
needs_install=1
52-
if [ "$maj" == "$version" ]; then
53-
# Check whether that version is installed.
54-
if apt list --installed gcc-${version} | grep -q "gcc-${version}/"; then
55-
echo "GCC $version already installed"
56-
needs_install=0
57-
fi
58-
else
59-
# Install the PPA for installing other versions of gcc.
60-
sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
55+
if [ "$version" == "latest" ]; then
6156
sudo apt-get update
62-
fi
57+
sudo apt-get install -y gcc gfortran g++
58+
else
59+
# Check whether the system gcc version is the version we are after.
60+
cur=$(apt show gcc | grep "Version" | cut -d':' -f3 | cut -d'-' -f1)
61+
maj=$(echo $cur | cut -d'.' -f1)
62+
needs_install=1
63+
if [ "$maj" == "$version" ]; then
64+
# Check whether that version is installed.
65+
if apt list --installed gcc-${version} | grep -q "gcc-${version}/"; then
66+
echo "GCC $version already installed"
67+
needs_install=0
68+
fi
69+
else
70+
# Install the PPA for installing other versions of gcc.
71+
sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
72+
sudo apt-get update
73+
fi
6374

64-
if [ "${needs_install}" == "1" ]; then
65-
sudo apt-get install -y gcc-${version} gfortran-${version} g++-${version}
66-
fi
75+
if [ "${needs_install}" == "1" ]; then
76+
sudo apt-get install -y gcc-${version} gfortran-${version} g++-${version}
77+
fi
6778

68-
sudo update-alternatives \
69-
--install /usr/bin/gcc gcc /usr/bin/gcc-${version} 100 \
70-
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${version} \
71-
--slave /usr/bin/gcov gcov /usr/bin/gcov-${version} \
72-
--slave /usr/bin/g++ g++ /usr/bin/g++-${version}
79+
sudo update-alternatives \
80+
--install /usr/bin/gcc gcc /usr/bin/gcc-${version} 100 \
81+
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${version} \
82+
--slave /usr/bin/gcov gcov /usr/bin/gcov-${version} \
83+
--slave /usr/bin/g++ g++ /usr/bin/g++-${version}
84+
fi
7385
}
7486

7587
install_gcc_choco()
@@ -88,8 +100,12 @@ install_gcc_choco()
88100
mv /c/mingw64 "$RUNNER_TEMP/"
89101
# ...and install selected version
90102
case $version in
91-
13)
92-
choco install mingw --version 13.2.0 --force
103+
latest|13)
104+
if [ "$version" == "latest" ]; then
105+
choco install mingw --force
106+
else
107+
choco install mingw --version 13.2.0 --force
108+
fi
93109
# mingw 13 on Windows doesn't create shims (http://disq.us/p/2w5c5tj)
94110
# so hide Strawberry compilers and manually add mingw bin dir to PATH
95111
mkdir "$RUNNER_TEMP/strawberry"
@@ -114,7 +130,7 @@ install_gcc_choco()
114130
choco install mingw --version 8.5.0 --force
115131
;;
116132
*)
117-
echo "Unsupported version: $version (choose 8-13)"
133+
echo "Unsupported version: $version (choose 8-13 or latest)"
118134
exit 1
119135
;;
120136
esac
@@ -345,7 +361,9 @@ install_intel_apt()
345361
{
346362
local version=$1
347363
local classic=$2
348-
intel_version_map_l $version $classic
364+
if [ "$version" != "latest" ]; then
365+
intel_version_map_l $version $classic
366+
fi
349367

350368
require_fetch
351369
local _KEY="GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB"
@@ -356,17 +374,23 @@ install_intel_apt()
356374
| sudo tee /etc/apt/sources.list.d/oneAPI.list
357375
sudo apt-get update
358376

359-
# c/cpp compiler package names changed with 2024+
360-
case $version in
361-
2024* | 2025*)
362-
sudo apt-get install -y \
363-
intel-oneapi-compiler-{fortran,dpcpp-cpp}-$version
364-
;;
365-
*)
366-
sudo apt-get install -y \
367-
intel-oneapi-compiler-{fortran,dpcpp-cpp-and-cpp-classic}-$version
368-
;;
369-
esac
377+
if [ "$version" == "latest" ]; then
378+
sudo apt-get install -y \
379+
intel-oneapi-compiler-fortran \
380+
intel-oneapi-compiler-dpcpp-cpp
381+
else
382+
# c/cpp compiler package names changed with 2024+
383+
case $version in
384+
2024* | 2025*)
385+
sudo apt-get install -y \
386+
intel-oneapi-compiler-{fortran,dpcpp-cpp}-$version
387+
;;
388+
*)
389+
sudo apt-get install -y \
390+
intel-oneapi-compiler-{fortran,dpcpp-cpp-and-cpp-classic}-$version
391+
;;
392+
esac
393+
fi
370394

371395
source /opt/intel/oneapi/setvars.sh
372396
export_intel_vars
@@ -623,7 +647,11 @@ install_lfortran_l()
623647
export CC="gcc"
624648
export CXX="g++"
625649
export CONDA=conda
626-
$CONDA install -c conda-forge -n base -y lfortran=$version
650+
if [ "$version" == "latest" ]; then
651+
$CONDA install -c conda-forge -n base -y lfortran
652+
else
653+
$CONDA install -c conda-forge -n base -y lfortran=$version
654+
fi
627655
}
628656

629657
install_lfortran_w()
@@ -632,7 +660,11 @@ install_lfortran_w()
632660
export CC="cl"
633661
export CXX="cl"
634662
export CONDA=$CONDA\\Scripts\\conda # https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md#environment-variables
635-
$CONDA install -c conda-forge -n base -y lfortran=$version
663+
if [ "$version" == "latest" ]; then
664+
$CONDA install -c conda-forge -n base -y lfortran
665+
else
666+
$CONDA install -c conda-forge -n base -y lfortran=$version
667+
fi
636668
}
637669

638670
install_lfortran_m()
@@ -642,7 +674,11 @@ install_lfortran_m()
642674
export CXX="g++"
643675
export CONDA_ROOT_PREFIX=$MAMBA_ROOT_PREFIX
644676
export CONDA=micromamba
645-
$CONDA install -c conda-forge -n base -y lfortran=$version
677+
if [ "$version" == "latest" ]; then
678+
$CONDA install -c conda-forge -n base -y lfortran
679+
else
680+
$CONDA install -c conda-forge -n base -y lfortran=$version
681+
fi
646682
}
647683

648684
install_lfortran()

0 commit comments

Comments
 (0)