Skip to content

Commit a0955bb

Browse files
authored
Various enhancements (#44)
* expand/automate compatibility testing in weekly workflow * consolidate gcc and intel compatibility tables in README.md * only test latest toolchain versions on each platform on push/pr * update README wording to reflect support for standalone compilers * install g++ separately on ubuntu (not included with gcc-13 via APT) * support gcc 13 via chocolatey mingw on windows * bump default gcc from 11 to 13 (supported on all 3 platforms) * set cxx output and env var consistently * test compiling C/C++ programs
1 parent 85d479e commit a0955bb

File tree

9 files changed

+390
-158
lines changed

9 files changed

+390
-158
lines changed

.github/workflows/test.yml

+249-102
Large diffs are not rendered by default.

README.md

+18-27
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Action to setup a Fortran compiler.
2525

2626
This action sets up a Fortran compiler on Ubuntu, MacOS and Windows runners.
2727

28+
C/C++ compilers of the same toolchain/version are provided where possible, otherwise (if a standalone Fortran compiler is selected) defaulting to the preinstalled GCC.
29+
2830
```yaml
2931
jobs:
3032
test:
@@ -65,56 +67,45 @@ jobs:
6567
- *version*: Version of the compiler toolchain. See [runner compatibility](#runner-compatibility) charts below.
6668

6769

68-
6970
## Outputs
7071

7172
The action sets the following outputs:
7273

73-
- `cc`: C compiler executable, e.g. `gcc`
7474
- `fc`: Fortran compiler executable, e.g. `gfortran`
75+
- `cc`: C compiler executable, e.g. `gcc`
76+
- `cxx`: C++ compiler executable, e.g. `g++`
7577

7678

7779
## Environment variables
7880

7981
The same values are also set as environment variables:
8082

81-
- `CC`
8283
- `FC`
84+
- `CC`
85+
- `CXX`
8386

8487
These are made available to subsequent workflow steps via the [`GITHUB_ENV` environment file mechanism](https://docs.github.com/en/actions/learn-github-actions/environment-variables#passing-values-between-steps-and-jobs-in-a-workflow).
8588

8689

8790
## Runner compatibility
8891

89-
Support for the GCC toolchain varies across GitHub-hosted runner images.
92+
Toolchain support varies across GitHub-hosted runner images.
9093

9194
<!-- compat starts -->
92-
| runner | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
93-
|:-------------|:--------|:--------|:--------|:--------|:--------|:--------|:--------|:--------|
94-
| macos-11 | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
95-
| macos-12 | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
96-
| macos-13 | | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
97-
| ubuntu-20.04 | | &check; | &check; | &check; | &check; | &check; | | &check; |
98-
| ubuntu-22.04 | | | | &check; | &check; | &check; | &check; | &check; |
99-
| windows-2019 | | | &check; | &check; | &check; | &check; | &check; | |
100-
| windows-2022 | | | &check; | &check; | &check; | &check; | &check; | |
95+
| runner | gcc 10 | gcc 11 | gcc 12 | gcc 13 | gcc 6 | gcc 7 | gcc 8 | gcc 9 | intel-classic 2021.1.2 | intel-classic 2021.1 | intel-classic 2021.10 | intel-classic 2021.2 | intel-classic 2021.3 | intel-classic 2021.4 | intel-classic 2021.5 | intel-classic 2021.6 | intel-classic 2021.7.1 | intel-classic 2021.7 | intel-classic 2021.8 | intel-classic 2021.9 | intel 2021.1.2 | intel 2021.1 | intel 2021.2 | intel 2021.4 | intel 2022.0 | intel 2022.1 | intel 2022.2.1 | intel 2022.2 | intel 2023.0 | intel 2023.1 | intel 2023.2 |
96+
|:-------------|:----------------|:----------------|:----------------|:----------------|:---------------|:---------------|:---------------|:---------------|:--------------------------------|:------------------------------|:-------------------------------|:------------------------------|:------------------------------|:------------------------------|:------------------------------|:------------------------------|:--------------------------------|:------------------------------|:------------------------------|:------------------------------|:------------------------|:----------------------|:----------------------|:----------------------|:----------------------|:----------------------|:------------------------|:----------------------|:----------------------|:----------------------|:----------------------|
97+
| macos-11 | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | | | | | | | | | | | |
98+
| macos-12 | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | | | | | | | | | | | |
99+
| macos-13 | &check; | &check; | &check; | &check; | | &check; | &check; | &check; | | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | | | | | | | | | | | |
100+
| ubuntu-20.04 | &check; | &check; | | &check; | | &check; | &check; | &check; | &check; | &check; | &check; | &check; | | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
101+
| ubuntu-22.04 | &check; | &check; | &check; | &check; | | | | &check; | &check; | &check; | &check; | &check; | | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
102+
| windows-2019 | &check; | &check; | &check; | &check; | | | &check; | &check; | | | &check; | | | | | &check; | | &check; | &check; | &check; | | | | | | &check; | | &check; | &check; | &check; | &check; |
103+
| windows-2022 | &check; | &check; | &check; | &check; | | | &check; | &check; | | | &check; | | | | | &check; | | &check; | &check; | &check; | | | | | | &check; | | &check; | &check; | &check; | &check; |
101104
<!-- compat ends -->
102105

103-
**Note:** version 13 of the GNU toolchain is not yet available on Windows.
104-
105-
**Note:** on `macos-13`, gcc 7-9 require flag `-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib`.
106-
107-
Supported Intel toolchains:
108-
109-
| runner | compiler | version |
110-
| :-------- | :------------- | :------ |
111-
| ubuntu-\* | intel | 2023.2, 2023.1, 2023.0, <br/> 2022.2.1, 2022.2, 2022.1, 2022.0, <br/> 2021.4, 2021.2, 2021.1.2, 2021.1 |
112-
| ubuntu-\* | intel-classic | 2021.10, 2021.9, 2021.8, <br/> 2021.7.1, 2021.7, 2021.6, 2021.5, <br/> 2021.4, 2021.3, 2021.2, 2021.1.2, 2021.1 |
113-
| macos-\* | intel-classic | 2021.10, 2021.9, 2021.8, <br/> 2021.7.1, 2021.7, 2021.6, 2021.5, <br/> 2021.4, 2021.3, 2021.2, 2021.1 |
114-
| windows-\* | intel | 2023.2, 2023.1, 2023.0, 2022.2.0, 2022.1.0 |
115-
| windows-\* | intel-classic | 2021.10.0, 2021.9.0, 2021.8.0, 2021.7.0, 2021.6.0 |
106+
**Note:** on `macos-13`, `gfortran` 7-9 require flag `-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib`.
116107

117-
**Note:** on macOS `ifx` is not supported, so the `intel` option redirects to `intel-classic` (`ifort`).
108+
**Note:** Intel's `ifx` compiler is not supported on macOS, so the `intel` option redirects to `intel-classic` (`ifort`).
118109

119110
## License
120111

action.yml

+24-18
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: "Setup Fortran"
22
description: "Setup Fortran compiler and toolchain"
33
inputs:
44
compiler:
5-
description: "Compiler toolchain"
5+
description: "Toolchain or compiler to install"
66
required: true
77
default: "gcc"
88
version:
9-
description: "Version of compiler toolchain"
9+
description: "Version of toolchain or compiler"
1010
required: false
1111
outputs:
1212
fc:
@@ -15,41 +15,43 @@ outputs:
1515
cc:
1616
description: "Path to C compiler"
1717
value: ${{ steps.outputs.outputs.cc }}
18+
cxx:
19+
description: "Path to C++ compiler"
20+
value: ${{ steps.outputs.outputs.cxx }}
1821
runs:
1922
using: "composite"
2023
steps:
21-
24+
# On Windows runners the Intel toolchain is very slow to install,
25+
# setup caching with daily key rotation. Steps are also needed to
26+
# activate the oneAPI environment.
2227
- name: Set oneAPI install dir
2328
id: oneapi-root
2429
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
2530
shell: bash
2631
run: echo "ONEAPI_ROOT=C:\Program Files (x86)\Intel\oneAPI" >> "$GITHUB_ENV"
27-
2832
# GNU tar can't handle symlinks on Windows, hide it so default Windows tar is used to restore cache
2933
- name: Hide GNU tar
3034
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
3135
shell: bash
3236
run: mv "C:\Program Files\Git\usr\bin\tar.exe" "$RUNNER_TEMP\tar.exe"
33-
34-
- name: Get Date
37+
- name: Get date
3538
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
3639
id: get-date
3740
shell: bash
3841
run: echo "date=$(/bin/date -u "+%Y%m%d")" >> "$GITHUB_OUTPUT"
39-
4042
- name: Restore cache
4143
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
4244
id: cache
4345
uses: actions/cache/restore@v3
4446
with:
4547
path: ${{ env.ONEAPI_ROOT }}
4648
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.version }}-${{ steps.get-date.outputs.date }}
47-
4849
- name: Restore GNU tar
4950
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
5051
shell: bash
5152
run: mv "$RUNNER_TEMP\tar.exe" 'C:\Program Files\Git\usr\bin\tar.exe'
5253

54+
# Set up the selected toolchain or compiler
5355
- name: Setup toolchain
5456
id: setup
5557
if: steps.cache.outputs.cache-hit != 'true'
@@ -66,7 +68,7 @@ runs:
6668
6769
case $compiler in
6870
gcc)
69-
version=${VERSION:-11}
71+
version=${VERSION:-13}
7072
install_gcc $platform
7173
;;
7274
intel-classic)
@@ -82,62 +84,66 @@ runs:
8284
;;
8385
esac
8486
85-
if ! ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]]); then
86-
which "${FC}"
87-
which "${CC}"
88-
89-
# persist environment variables
87+
if ! ([[ "$RUNNER_OS" == "Windows" ]] && [[ "${{ inputs.compiler }}" =~ "intel" ]]); then
88+
# save environment variables
9089
echo "FC=${FC}" >> $GITHUB_ENV
9190
echo "CC=${CC}" >> $GITHUB_ENV
91+
echo "CXX=${CXX}" >> $GITHUB_ENV
9292
fi
9393
94+
# save oneAPI cache and activate environment
9495
- name: Save cache
9596
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel') && steps.cache.outputs.cache-hit != 'true'
9697
uses: actions/cache/save@v3
9798
with:
9899
path: ${{ env.ONEAPI_ROOT }}
99100
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.version }}-${{ steps.get-date.outputs.date }}
100-
101101
- name: Activate oneAPI
102102
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
103103
shell: cmd
104104
run: |
105+
ver | findstr /i "10\.0\.17" && set VS2019INSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise
106+
ver | findstr /i "10\.0\.20" && set VS2022INSTALLDIR=C:\Program Files\Microsoft Visual Studio\2022\Enterprise
105107
for /f "tokens=* usebackq" %%f in (`dir /b "%ONEAPI_ROOT%\compiler\" ^| findstr /V latest ^| sort`) do @set "LATEST=%%f"
106108
:: this script fails when install location is not the default
107109
call "%ONEAPI_ROOT%\compiler\%LATEST%\env\vars.bat"
108110
set | findstr /c:"oneAPI" >> "%GITHUB_ENV%"
109-
111+
# Intel compilers may have restored from cache so env vars may not be set,
112+
# set them then set outputs for all compilers/toolchains
110113
- name: Set outputs and env vars
111114
shell: bash
112115
id: outputs
113116
run: |
114-
if [ "$RUNNER_OS" == "Windows" ]; then
117+
if [[ "$RUNNER_OS" == "Windows" ]]; then
115118
if [[ "${{ inputs.compiler }}" == "intel" ]]; then
116119
echo fc=ifx>>$GITHUB_OUTPUT
117120
echo cc=icx>>$GITHUB_OUTPUT
121+
echo cxx=icx>>$GITHUB_OUTPUT
118122
echo FC=ifx>>$GITHUB_ENV
119123
echo CC=icx>>$GITHUB_ENV
120124
echo CXX=icx>>$GITHUB_ENV
121125
elif [[ "${{ inputs.compiler }}" == "intel-classic" ]]; then
122126
echo fc=ifort>>$GITHUB_OUTPUT
123127
echo cc=icl>>$GITHUB_OUTPUT
128+
echo cxx=icl>>$GITHUB_OUTPUT
124129
echo FC=ifort>>$GITHUB_ENV
125130
echo CC=icl>>$GITHUB_ENV
126131
echo CXX=icl>>$GITHUB_ENV
127132
else
128133
echo fc=$FC>>$GITHUB_OUTPUT
129134
echo cc=$CC>>$GITHUB_OUTPUT
135+
echo cxx=$CXX>>$GITHUB_OUTPUT
130136
fi
131137
else
132138
echo fc=$FC>>$GITHUB_OUTPUT
133139
echo cc=$CC>>$GITHUB_OUTPUT
140+
echo cxx=$CXX>>$GITHUB_OUTPUT
134141
fi
135142
136143
# intel oneapi flag to indicate env has been activated
137144
if [[ "${{ inputs.compiler }}" =~ "intel" ]]; then
138145
echo SETVARS_COMPLETED=1>>$GITHUB_ENV
139146
fi
140-
141147
# GitHub Actions prepends GNU linker to the PATH before all bash steps, hide it so MSVC linker is found
142148
- name: Hide GNU linker (Windows)
143149
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')

compat.csv

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
runner,6,7,8,9,10,11,12,13
2-
macos-11,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;
3-
macos-12,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;
4-
macos-13,,&check;,&check;,&check;,&check;,&check;,&check;,&check;
5-
ubuntu-20.04,,&check;,&check;,&check;,&check;,&check;,,&check;
6-
ubuntu-22.04,,,,&check;,&check;,&check;,&check;,&check;
7-
windows-2019,,,&check;,&check;,&check;,&check;,&check;,
8-
windows-2022,,,&check;,&check;,&check;,&check;,&check;,
1+
compiler,gcc,gcc,gcc,gcc,gcc,gcc,gcc,gcc,intel-classic,intel-classic,intel-classic,intel-classic,intel-classic,intel-classic,intel-classic,intel-classic,intel-classic,intel-classic,intel-classic,intel-classic,intel,intel,intel,intel,intel,intel,intel,intel,intel,intel,intel
2+
version,10,11,12,13,6,7,8,9,2021.1.2,2021.1,2021.10,2021.2,2021.3,2021.4,2021.5,2021.6,2021.7.1,2021.7,2021.8,2021.9,2021.1.2,2021.1,2021.2,2021.4,2022.0,2022.1,2022.2.1,2022.2,2023.0,2023.1,2023.2
3+
runner,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
4+
macos-11,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,,,,,,,,,,,
5+
macos-12,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,,,,,,,,,,,
6+
macos-13,&check;,&check;,&check;,&check;,,&check;,&check;,&check;,,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,,,,,,,,,,,
7+
ubuntu-20.04,&check;,&check;,,&check;,,&check;,&check;,&check;,&check;,&check;,&check;,&check;,,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;
8+
ubuntu-22.04,&check;,&check;,&check;,&check;,,,,&check;,&check;,&check;,&check;,&check;,,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;
9+
windows-2019,&check;,&check;,&check;,&check;,,,&check;,&check;,,,&check;,,,,,&check;,,&check;,&check;,&check;,,,,,,&check;,,&check;,&check;,&check;,&check;
10+
windows-2022,&check;,&check;,&check;,&check;,,,&check;,&check;,,,&check;,,,,,&check;,,&check;,&check;,&check;,,,,,,&check;,,&check;,&check;,&check;,&check;

hw.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
printf("hello world\n");
5+
return 0;
6+
}

hw.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <iostream>
2+
3+
int main() {
4+
std::cout << "hello world\n";
5+
return 0;
6+
}

setup-fortran.sh

+13-3
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ install_gcc_apt()
4545
{
4646
sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
4747
sudo apt-get update
48-
sudo apt-get install -y gcc-${version} gfortran-${version}
48+
sudo apt-get install -y gcc-${version} gfortran-${version} g++-${version}
4949
sudo update-alternatives \
5050
--install /usr/bin/gcc gcc /usr/bin/gcc-${version} 100 \
5151
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${version} \
52-
--slave /usr/bin/gcov gcov /usr/bin/gcov-${version}
52+
--slave /usr/bin/gcov gcov /usr/bin/gcov-${version} \
53+
--slave /usr/bin/g++ g++ /usr/bin/g++-${version}
5354

5455
export FC="gfortran"
5556
export CC="gcc"
@@ -59,6 +60,15 @@ install_gcc_apt()
5960
install_gcc_choco()
6061
{
6162
case $version in
63+
13)
64+
choco install mingw --version 13.2.0 --force
65+
# mingw 13 on Windows doesn't create shims (http://disq.us/p/2w5c5tj)
66+
# so hide Strawberry compilers and manually add mingw bin dir to PATH
67+
mv /c/Strawberry/c/bin/gfortran "$RUNNER_TEMP/gfortran"
68+
mv /c/Strawberry/c/bin/gcc "$RUNNER_TEMP/gcc"
69+
mv /c/Strawberry/c/bin/g++ "$RUNNER_TEMP/g++"
70+
echo "C:\ProgramData\mingw64\mingw64\bin" >> $GITHUB_PATH
71+
;;
6272
12)
6373
choco install mingw --version 12.2.0 --force
6474
;;
@@ -75,7 +85,7 @@ install_gcc_choco()
7585
choco install mingw --version 8.5.0 --force
7686
;;
7787
*)
78-
echo "Unsupported version: $version (choose 8-12)"
88+
echo "Unsupported version: $version (choose 8-13)"
7989
exit 1
8090
;;
8191
esac

0 commit comments

Comments
 (0)