Skip to content

Commit

Permalink
Various enhancements (#44)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wpbonelli authored Oct 18, 2023
1 parent 85d479e commit a0955bb
Show file tree
Hide file tree
Showing 9 changed files with 390 additions and 158 deletions.
351 changes: 249 additions & 102 deletions .github/workflows/test.yml

Large diffs are not rendered by default.

45 changes: 18 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Action to setup a Fortran compiler.

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

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.

```yaml
jobs:
test:
Expand Down Expand Up @@ -65,56 +67,45 @@ jobs:
- *version*: Version of the compiler toolchain. See [runner compatibility](#runner-compatibility) charts below.



## Outputs

The action sets the following outputs:

- `cc`: C compiler executable, e.g. `gcc`
- `fc`: Fortran compiler executable, e.g. `gfortran`
- `cc`: C compiler executable, e.g. `gcc`
- `cxx`: C++ compiler executable, e.g. `g++`


## Environment variables

The same values are also set as environment variables:

- `CC`
- `FC`
- `CC`
- `CXX`

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).


## Runner compatibility

Support for the GCC toolchain varies across GitHub-hosted runner images.
Toolchain support varies across GitHub-hosted runner images.

<!-- compat starts -->
| runner | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
|:-------------|:--------|:--------|:--------|:--------|:--------|:--------|:--------|:--------|
| macos-11 | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
| macos-12 | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
| macos-13 | | &check; | &check; | &check; | &check; | &check; | &check; | &check; |
| ubuntu-20.04 | | &check; | &check; | &check; | &check; | &check; | | &check; |
| ubuntu-22.04 | | | | &check; | &check; | &check; | &check; | &check; |
| windows-2019 | | | &check; | &check; | &check; | &check; | &check; | |
| windows-2022 | | | &check; | &check; | &check; | &check; | &check; | |
| 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 |
|:-------------|:----------------|:----------------|:----------------|:----------------|:---------------|:---------------|:---------------|:---------------|:--------------------------------|:------------------------------|:-------------------------------|:------------------------------|:------------------------------|:------------------------------|:------------------------------|:------------------------------|:--------------------------------|:------------------------------|:------------------------------|:------------------------------|:------------------------|:----------------------|:----------------------|:----------------------|:----------------------|:----------------------|:------------------------|:----------------------|:----------------------|:----------------------|:----------------------|
| macos-11 | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | | | | | | | | | | | |
| macos-12 | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | | | | | | | | | | | |
| macos-13 | &check; | &check; | &check; | &check; | | &check; | &check; | &check; | | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | &check; | | | | | | | | | | | |
| 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; |
| 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; |
| windows-2019 | &check; | &check; | &check; | &check; | | | &check; | &check; | | | &check; | | | | | &check; | | &check; | &check; | &check; | | | | | | &check; | | &check; | &check; | &check; | &check; |
| windows-2022 | &check; | &check; | &check; | &check; | | | &check; | &check; | | | &check; | | | | | &check; | | &check; | &check; | &check; | | | | | | &check; | | &check; | &check; | &check; | &check; |
<!-- compat ends -->

**Note:** version 13 of the GNU toolchain is not yet available on Windows.

**Note:** on `macos-13`, gcc 7-9 require flag `-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib`.

Supported Intel toolchains:

| runner | compiler | version |
| :-------- | :------------- | :------ |
| 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 |
| 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 |
| 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 |
| windows-\* | intel | 2023.2, 2023.1, 2023.0, 2022.2.0, 2022.1.0 |
| windows-\* | intel-classic | 2021.10.0, 2021.9.0, 2021.8.0, 2021.7.0, 2021.6.0 |
**Note:** on `macos-13`, `gfortran` 7-9 require flag `-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib`.

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

## License

Expand Down
42 changes: 24 additions & 18 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: "Setup Fortran"
description: "Setup Fortran compiler and toolchain"
inputs:
compiler:
description: "Compiler toolchain"
description: "Toolchain or compiler to install"
required: true
default: "gcc"
version:
description: "Version of compiler toolchain"
description: "Version of toolchain or compiler"
required: false
outputs:
fc:
Expand All @@ -15,41 +15,43 @@ outputs:
cc:
description: "Path to C compiler"
value: ${{ steps.outputs.outputs.cc }}
cxx:
description: "Path to C++ compiler"
value: ${{ steps.outputs.outputs.cxx }}
runs:
using: "composite"
steps:

# On Windows runners the Intel toolchain is very slow to install,
# setup caching with daily key rotation. Steps are also needed to
# activate the oneAPI environment.
- name: Set oneAPI install dir
id: oneapi-root
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
shell: bash
run: echo "ONEAPI_ROOT=C:\Program Files (x86)\Intel\oneAPI" >> "$GITHUB_ENV"

# GNU tar can't handle symlinks on Windows, hide it so default Windows tar is used to restore cache
- name: Hide GNU tar
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
shell: bash
run: mv "C:\Program Files\Git\usr\bin\tar.exe" "$RUNNER_TEMP\tar.exe"

- name: Get Date
- name: Get date
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
id: get-date
shell: bash
run: echo "date=$(/bin/date -u "+%Y%m%d")" >> "$GITHUB_OUTPUT"

- name: Restore cache
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
id: cache
uses: actions/cache/restore@v3
with:
path: ${{ env.ONEAPI_ROOT }}
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.version }}-${{ steps.get-date.outputs.date }}

- name: Restore GNU tar
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
shell: bash
run: mv "$RUNNER_TEMP\tar.exe" 'C:\Program Files\Git\usr\bin\tar.exe'

# Set up the selected toolchain or compiler
- name: Setup toolchain
id: setup
if: steps.cache.outputs.cache-hit != 'true'
Expand All @@ -66,7 +68,7 @@ runs:
case $compiler in
gcc)
version=${VERSION:-11}
version=${VERSION:-13}
install_gcc $platform
;;
intel-classic)
Expand All @@ -82,62 +84,66 @@ runs:
;;
esac
if ! ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]]); then
which "${FC}"
which "${CC}"
# persist environment variables
if ! ([[ "$RUNNER_OS" == "Windows" ]] && [[ "${{ inputs.compiler }}" =~ "intel" ]]); then
# save environment variables
echo "FC=${FC}" >> $GITHUB_ENV
echo "CC=${CC}" >> $GITHUB_ENV
echo "CXX=${CXX}" >> $GITHUB_ENV
fi
# save oneAPI cache and activate environment
- name: Save cache
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel') && steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v3
with:
path: ${{ env.ONEAPI_ROOT }}
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.version }}-${{ steps.get-date.outputs.date }}

- name: Activate oneAPI
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
shell: cmd
run: |
ver | findstr /i "10\.0\.17" && set VS2019INSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise
ver | findstr /i "10\.0\.20" && set VS2022INSTALLDIR=C:\Program Files\Microsoft Visual Studio\2022\Enterprise
for /f "tokens=* usebackq" %%f in (`dir /b "%ONEAPI_ROOT%\compiler\" ^| findstr /V latest ^| sort`) do @set "LATEST=%%f"
:: this script fails when install location is not the default
call "%ONEAPI_ROOT%\compiler\%LATEST%\env\vars.bat"
set | findstr /c:"oneAPI" >> "%GITHUB_ENV%"
# Intel compilers may have restored from cache so env vars may not be set,
# set them then set outputs for all compilers/toolchains
- name: Set outputs and env vars
shell: bash
id: outputs
run: |
if [ "$RUNNER_OS" == "Windows" ]; then
if [[ "$RUNNER_OS" == "Windows" ]]; then
if [[ "${{ inputs.compiler }}" == "intel" ]]; then
echo fc=ifx>>$GITHUB_OUTPUT
echo cc=icx>>$GITHUB_OUTPUT
echo cxx=icx>>$GITHUB_OUTPUT
echo FC=ifx>>$GITHUB_ENV
echo CC=icx>>$GITHUB_ENV
echo CXX=icx>>$GITHUB_ENV
elif [[ "${{ inputs.compiler }}" == "intel-classic" ]]; then
echo fc=ifort>>$GITHUB_OUTPUT
echo cc=icl>>$GITHUB_OUTPUT
echo cxx=icl>>$GITHUB_OUTPUT
echo FC=ifort>>$GITHUB_ENV
echo CC=icl>>$GITHUB_ENV
echo CXX=icl>>$GITHUB_ENV
else
echo fc=$FC>>$GITHUB_OUTPUT
echo cc=$CC>>$GITHUB_OUTPUT
echo cxx=$CXX>>$GITHUB_OUTPUT
fi
else
echo fc=$FC>>$GITHUB_OUTPUT
echo cc=$CC>>$GITHUB_OUTPUT
echo cxx=$CXX>>$GITHUB_OUTPUT
fi
# intel oneapi flag to indicate env has been activated
if [[ "${{ inputs.compiler }}" =~ "intel" ]]; then
echo SETVARS_COMPLETED=1>>$GITHUB_ENV
fi
# GitHub Actions prepends GNU linker to the PATH before all bash steps, hide it so MSVC linker is found
- name: Hide GNU linker (Windows)
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')
Expand Down
18 changes: 10 additions & 8 deletions compat.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
runner,6,7,8,9,10,11,12,13
macos-11,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;
macos-12,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;
macos-13,,&check;,&check;,&check;,&check;,&check;,&check;,&check;
ubuntu-20.04,,&check;,&check;,&check;,&check;,&check;,,&check;
ubuntu-22.04,,,,&check;,&check;,&check;,&check;,&check;
windows-2019,,,&check;,&check;,&check;,&check;,&check;,
windows-2022,,,&check;,&check;,&check;,&check;,&check;,
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
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
runner,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
macos-11,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,,,,,,,,,,,
macos-12,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,,,,,,,,,,,
macos-13,&check;,&check;,&check;,&check;,,&check;,&check;,&check;,,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,&check;,,,,,,,,,,,
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;
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;
windows-2019,&check;,&check;,&check;,&check;,,,&check;,&check;,,,&check;,,,,,&check;,,&check;,&check;,&check;,,,,,,&check;,,&check;,&check;,&check;,&check;
windows-2022,&check;,&check;,&check;,&check;,,,&check;,&check;,,,&check;,,,,,&check;,,&check;,&check;,&check;,,,,,,&check;,,&check;,&check;,&check;,&check;
6 changes: 6 additions & 0 deletions hw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

int main() {
printf("hello world\n");
return 0;
}
6 changes: 6 additions & 0 deletions hw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

int main() {
std::cout << "hello world\n";
return 0;
}
16 changes: 13 additions & 3 deletions setup-fortran.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ install_gcc_apt()
{
sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -y gcc-${version} gfortran-${version}
sudo apt-get install -y gcc-${version} gfortran-${version} g++-${version}
sudo update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-${version} 100 \
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${version} \
--slave /usr/bin/gcov gcov /usr/bin/gcov-${version}
--slave /usr/bin/gcov gcov /usr/bin/gcov-${version} \
--slave /usr/bin/g++ g++ /usr/bin/g++-${version}

export FC="gfortran"
export CC="gcc"
Expand All @@ -59,6 +60,15 @@ install_gcc_apt()
install_gcc_choco()
{
case $version in
13)
choco install mingw --version 13.2.0 --force
# mingw 13 on Windows doesn't create shims (http://disq.us/p/2w5c5tj)
# so hide Strawberry compilers and manually add mingw bin dir to PATH
mv /c/Strawberry/c/bin/gfortran "$RUNNER_TEMP/gfortran"
mv /c/Strawberry/c/bin/gcc "$RUNNER_TEMP/gcc"
mv /c/Strawberry/c/bin/g++ "$RUNNER_TEMP/g++"
echo "C:\ProgramData\mingw64\mingw64\bin" >> $GITHUB_PATH
;;
12)
choco install mingw --version 12.2.0 --force
;;
Expand All @@ -75,7 +85,7 @@ install_gcc_choco()
choco install mingw --version 8.5.0 --force
;;
*)
echo "Unsupported version: $version (choose 8-12)"
echo "Unsupported version: $version (choose 8-13)"
exit 1
;;
esac
Expand Down
Loading

0 comments on commit a0955bb

Please sign in to comment.