# Fortran compiler setup for GitHub actions

**URL:** <https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671>\
**Category:** Announcements\
**Created:** [April 26, 2023, 5:50pm UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671 "2023-04-26T17:50:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [April 26, 2023, 5:50pm UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671/1 "2023-04-26T17:50:26Z")

</div>

Some while ago I created a _setup-fortran_ action for usage in CI with GitHub actions, which apparently is [already in use around the Fortran ecosystem](https://github.com/awvwgk/setup-fortran/network/dependents). Turns out I never properly announced it in our discourse, so here we go:

> **[Setup Fortran - GitHub Marketplace](https://github.com/marketplace/actions/setup-fortran)**
>
> Setup Fortran compiler and toolchain

* * *

Currently the action allows to setup `gfortran` (_gcc_), `ifort` (_intel-classic_) and `ifx` (_intel_):

```auto
jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        toolchain: [{compiler: gcc, version: 11}]
        include:
          - os: ubuntu-latest
            toolchain: {compiler: intel, version: '2023.1'}
          - os: ubuntu-latest
            toolchain: {compiler: intel-classic, version: '2021.9'}
          - os: macos-latest
            toolchain: {compiler: intel-classic, version: '2021.9'}

    steps:
      - uses: awvwgk/setup-fortran@v1
        with:
          compiler: ${{ matrix.toolchain.compiler }}
          version: ${{ matrix.toolchain.version }}

      - run: ${{ env.FC }} --version

```

Support for the GCC toolchains:

| runner | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| macos-11 | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| macos-12 | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| ubuntu-20.04 | | | ✓ | ✓ | ✓ | ✓ | ✓ | |
| ubuntu-22.04 | | | | | ✓ | ✓ | ✓ | ✓ |
| windows-2019 | | | | ✓ | ✓ | ✓ | ✓ | ✓ |
| windows-2022 | | | | ✓ | ✓ | ✓ | ✓ | ✓ |

Supported Intel toolchains (the version refers to the compiler version in the output not the version of the oneapi release, read more about this [here](https://community.intel.com/t5/Blogs/Tech-Innovation/Tools/Intel-oneAPI-Compilers-Packaging-and-Versioning-2021-2022/post/1425602)):

| runner | compiler | version |
| --- | --- | --- |
| ubuntu-\* | intel | 2023.1, 2023.0,   
 2022.2.1, 2022.2, 2022.1, 2022.0,   
 2021.4, 2021.3, 2021.2, 2021.1.2, 2021.1 |
| ubuntu-\* | intel-classic | 2021.9, 2021.8,   
 2021.7.1, 2021.7, 2021.6, 2021.5,   
 2021.4, 2021.3, 2021.2, 2021.1.2, 2021.1 |
| macos-\* | intel-classic | 2021.9, 2021.8,   
 2021.7.1, 2021.7, 2021.6, 2021.5,   
 2021.4, 2021.3, 2021.2, 2021.1 |

Looking for help with other toolchains, like

- Intel-cl: [Support setting up Intel toolchain · Issue #1 · awvwgk/setup-fortran · GitHub](https://github.com/awvwgk/setup-fortran/issues/1)
- LFortran: [Support setting up LFortran toolchain · Issue #11 · awvwgk/setup-fortran · GitHub](https://github.com/awvwgk/setup-fortran/issues/11)
- LLVM flang: [Support setting up LLVM flang toolchain · Issue #12 · awvwgk/setup-fortran · GitHub](https://github.com/awvwgk/setup-fortran/issues/12)

---

<div class="post-metadata">

**Author:** ![FedericoPerini](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/federicoperini/32/1750_2.png) [@FedericoPerini](https://fortran-lang.discourse.group/u/FedericoPerini)\
**Post date:** [April 27, 2023, 6:53am UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671/2 "2023-04-27T06:53:23Z")

</div>

This is awesome - exactly what we need to stress test the fpm system libraries implementation!

---

<div class="post-metadata">

**Author:** ![alirezagh76](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@alirezagh76](https://fortran-lang.discourse.group/u/alirezagh76)\
**Post date:** [April 27, 2023, 8:39am UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671/3 "2023-04-27T08:39:11Z")

</div>

Thanks, it is great. It would be nice to have something similar on gitlab too.

---

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [April 27, 2023, 8:43am UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671/4 "2023-04-27T08:43:41Z")

</div>

I’m not much of a GitLab user, but the setup steps are mainly collected in one big script at [setup-fortran/setup-fortran.sh at main · awvwgk/setup-fortran · GitHub](https://github.com/awvwgk/setup-fortran/blob/main/setup-fortran.sh) and should be reusable. There are some GitHub actions specific steps like making the Intel setup persistent between workflow steps, which could be guarded by checking for GHA specific env vars. Is there an equivalent to custom GHA for providing steps in a GitLab pipeline?

---

<div class="post-metadata">

**Author:** ![ludnic](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@ludnic](https://fortran-lang.discourse.group/u/ludnic)\
**Post date:** [October 13, 2023, 8:15am UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671/5 "2023-10-13T08:15:05Z")

</div>

Hello. Thanks @awvwgk for sharing the setup-fortran action. I’m using in my workflows and it has worked great.

Since this morning I am seeing worfkflows failing with erorr: `Error: Unable to resolve action. Repository not found: awvwgk/setup-fortran`. Posting here to check fi this is a general problem. Has the action been migrated? The usage [instructions](https://github.com/marketplace/actions/setup-fortran#usage) on github marketplace have not changed for what I can tell.

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [October 13, 2023, 1:10pm UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671/6 "2023-10-13T13:10:30Z")

</div>

The repo moved yesterday to [GitHub - fortran-lang/setup-fortran: GitHub action to setup Fortran compiler and toolchain](https://github.com/fortran-lang/setup-fortran), and it seems like the GH Action doesn’t automatically redirect. Does it work if you change the “awvwgk” part with “fortran-lang”?

---

<div class="post-metadata">

**Author:** ![hkvzjal](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/hkvzjal/32/3055_2.png) [@hkvzjal](https://fortran-lang.discourse.group/u/hkvzjal)\
**Post date:** [October 13, 2023, 1:27pm UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671/7 "2023-10-13T13:27:34Z")

</div>

@milancurcic I saw in the repo this comment:

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

Does it use the mingw 64 tool chain? if so, version 13.2 is already available  
[https://packages.msys2.org/package/mingw-w64-x86\_64-gcc-fortran](https://packages.msys2.org/package/mingw-w64-x86_64-gcc-fortran)

And I guess the readme should be updated as it still points to “awvwgk/setup-fortran@v1” in the “Usage” section

---

<div class="post-metadata">

**Author:** ![ludnic](https://avatars.discourse-cdn.com/v4/letter/l/958977/32.png) [@ludnic](https://fortran-lang.discourse.group/u/ludnic)\
**Post date:** [October 13, 2023, 1:27pm UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671/8 "2023-10-13T13:27:56Z")

</div>

Thanks for confirming @milancurcic . Indeed I had tried replacing with fortran-lang/ and it works. Does it help if I send a PR to update the usage note?

---

<div class="post-metadata">

**Author:** ![RobertPincus](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@RobertPincus](https://fortran-lang.discourse.group/u/RobertPincus)\
**Post date:** [October 14, 2023, 3:05am UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671/9 "2023-10-14T03:05:18Z")

</div>

Hi -

Thanks, this looks neat. I’m curious about the use with `gfortran`? For Github runners based on Ubuntu 22.04, gfortran-10, -11, and -12 are available default (see [this example](https://github.com/earth-system-radiation/rte-rrtmgp/blob/main/.github/workflows/continuous-integration.yml)).

Another possible compiler for which support would be useful is the [Nvidia HPC toolkit](https://developer.nvidia.com/hpc-sdk) (i.e. `nvfortran`). I’m using my own [home-built containers](https://github.com/earth-system-radiation/rte-rrtmgp/blob/main/.github/workflows/containerized-ci.yml) for this and the Intel compilers. A Github action that let me skip the containers is/would be the bomb.

---

<div class="post-metadata">

**Author:** ![zaikunzhang](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/zaikunzhang/32/785_2.png) [@zaikunzhang](https://fortran-lang.discourse.group/u/zaikunzhang)\
**Post date:** [October 14, 2023, 6:46am UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671/10 "2023-10-14T06:46:04Z")

</div>

In addition to [fortran-lang/setup-fortran](https://github.com/marketplace/actions/setup-fortran) (thank @awvwgk and contributors), I use the following scripts for the GitHub Actions of [PRIMA](http://www.libprima.net) to install Fortran compilers on **GitHub-hosted** runners.

- Intel oneAPI (alternative to fortran-lang/setup-fortran)

- NVIDIA nvfortran  
[https://github.com/equipez/github\_actions\_scripts/blob/main/install\_nvfortran](https://github.com/equipez/github_actions_scripts/blob/main/install_nvfortran)

- AMD AOCC flang  
[https://github.com/equipez/github\_actions\_scripts/blob/main/install\_aocc](https://github.com/equipez/github_actions_scripts/blob/main/install_aocc)

- Classic flang  
[https://github.com/equipez/github\_actions\_scripts/blob/main/install\_flang](https://github.com/equipez/github_actions_scripts/blob/main/install_flang)

I also have scripts to install [sunf95](https://github.com/equipez/github_actions_scripts/blob/main/install_sunf95) and [g95](https://github.com/equipez/github_actions_scripts/blob/main/install_g95) on GitHub-hosted runners even though these compilers are discontinued.

The scripts are naive (e.g., call `apt install` to install `oneapi`), and they may take a few minutes to run, which is tolerable in my case.

Here is a concrete workflow that applies them:

[https://github.com/s-prima/prima/blob/main/.github/workflows/lint\_hosted.yml#L87-L117](https://github.com/s-prima/prima/blob/main/.github/workflows/lint_hosted.yml#L87-L117),

where the Fortran source code of [PRIMA](https://github.com/libprima/prima) is compiled using **eight** compilers (`gfortran`, `ifort`, `ifx`, `nvfortran`, AOCC `flang`, Classic `flang`, `sunf95`, and `g95`) with strict debug options to make sure that no error (of course) or warning is raised (PRIMA does not tolerate any warning).

**N.B.** : Do not use the scripts on your own computers before examining them. They may make unwanted changes to your system.

---

<div class="post-metadata">

**Author:** ![Andrii](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Andrii](https://fortran-lang.discourse.group/u/Andrii)\
**Post date:** [January 24, 2024, 7:48pm UTC](https://fortran-lang.discourse.group/t/fortran-compiler-setup-for-github-actions/5671/11 "2024-01-24T19:48:08Z")

</div>

Just would like to add that with multiarch images one can run in github Actions also ARM Fortran@aarch64 and the free version of IBM XL@ppc64le.
