GitHub Action: Setup Fortran with Conda

Yes, this issue affects the Flang compiler on Windows specifically. It seems the -fPIC flag isn’t supported on Windows, so it might be worth removing it from the default flags for flang-new in fpm.

With the v0.2.0 release, I added a GitHub Actions job summary table that shows the OS, compiler version, and fpm version. For example: Update Fortran setup action to version v0 and remove redundant Ubuntu… · gha3mi/M_time@5495bf2 · GitHub

Additionally, the CI workflow now generates a STATUS.md file and deploys it to a dedicated branch. See:M_time/STATUS.md at gh-pages-status · gha3mi/M_time · GitHub

Alternatively, this file can also be committed directly to the main branch using a GitHub Actions bot if preferred.

This step from here is now included by default in the updated setup, so it can be removed from CI configuration.

  - name: Set environment for ubuntu
    if: matrix.os == 'ubuntu-latest'
    run: |
      ulimit -c unlimited -d unlimited -f unlimited -m unlimited -s unlimited -t unlimited -v unlimited -x unlimited

An above and beyond effort. Any fpm project with test programs can add testing on multiple platforms with multiple compilers just by adding .github/workflows/*.yml files to their project.

2 Likes

How annoying would it be to somehow include MPI?

btw, thanks so much for this; this is fantastic I am working to include this in my current CI

2 Likes

The latest version v0.6.0 now includes:

  • Support for the nvfortran compiler
  • Versioned compiler installation by specifying: compiler-version
  • Added support for cmake
  • Fortitude linter integration via the new linter_fortitude job
  • Simplified CI/CD workflow configuration (include only the jobs you need)
  • Automatic status table generation with pull requests
    Example: https://github.com/gha3mi/forimage#status
  • latest tag added for stable reference: gha3mi/setup-fortran-conda@latest
  • Integrated Doxygen and FORD documentation support
  • Updated README with usage instructions
  • Various fixes and improvements
  • MIT License added

I’ve also tested the action on some of my repos using fpm, cmake and ford: ForImage, ForCAD, ForTime

I’m also thinking about adding Visualizing Fortran Projects with fpm: Create Stunning Module Dependency Charts as a new job, which could be a great addition to the README.

Contributions are always welcome!

3 Likes

I’m not sure about MPI, as I don’t have much experience with it and don’t currently have any repositories using MPI to test with. It would be great if you could provide a very simple example program to try it out.

MPI in a pain because of the MPI module needs to be compiled with the same compiler…in theory we could use vapaa, bind to that and that binds to C? I’ll look into that and maybe try to open a PR

2 Likes

on other news, I don’t know how often people look but the fpm has been downloaded 80,295 times.

1 Like

absolutely, not even mentioning that not depending on the non-universal Fortran module format would enable users to freely use MPI from Fortran regardless of the implementation that best suits their machine.

You can also use GitHub - lfortran/fortran_mpi, it works with GFortran and LFortran, we used it to compile the POT3D code. But it might not be as complete as Vapaa yet.

1 Like

As an update, the supported compilers are listed below.

Ubuntu

Fortran Compiler C Compiler C++ Compiler
gfortran gcc g++
ifx icx icx
lfortran gcc clang g++ clang++
flang, flang-new clang clang++
nvfortran nvc nvc++

macOS

Fortran Compiler C Compiler C++ Compiler
gfortran gcc g++
lfortran clang clang++

Windows

Fortran Compiler C Compiler C++ Compiler
gfortran gcc g++
ifx icx icx
lfortran clang-cl clang-cl
flang, flang-new clang-cl clang-cl

The following environment variables are set automatically:

  • FC, CC, CXX
  • FPM_FC, FPM_CC, FPM_CXX
  • CMAKE_Fortran_COMPILER, CMAKE_C_COMPILER, CMAKE_CXX_COMPILER

Below are the results of a simple “Hello World” test. The required build tools (fpm, cmake, ninja and meson) are preinstalled, so no additional setup is needed.

Compiler macos ubuntu windows
flang-new - fpm✔ cmake✔ meson✔ fpm✖ cmake✔ meson✖
gfortran fpm✔ cmake✔ meson✔ fpm✔ cmake✔ meson✔ fpm✔ cmake✔ meson✔
ifx - fpm✔ cmake✔ meson✔ fpm✔ cmake✔ meson✔
lfortran fpm✔ cmake✔ meson✖ fpm✔ cmake✔ meson✖ fpm✔ cmake✖ meson✖
mpifort mpi_fpm✔ mpi_fpm✔ -
nvfortran - fpm✔ cmake✔ meson✔ -

Here is a minimal usage example:

name: Setup Fortran Conda CI/CD

on: [push]
permissions:
  contents: write
jobs:
  test_fpm:
    name: ${{ matrix.os }}_${{ matrix.compiler }}_fpm
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        compiler: [gfortran, ifx, lfortran, flang-new, nvfortran]
        exclude:
          - os: macos-latest
            compiler: flang-new
          - os: macos-latest
            compiler: ifx
          - os: macos-latest
            compiler: nvfortran
          - os: windows-latest
            compiler: nvfortran
    steps:
      - name: Setup Fortran
        uses: gha3mi/setup-fortran-conda@latest
        with:
          compiler: ${{ matrix.compiler }}
          platform: ${{ matrix.os }}

      - name: fpm test (debug)
        run: fpm test --compiler ${{ matrix.compiler }} --profile debug

      - name: fpm test (release)
        run: fpm test --compiler ${{ matrix.compiler }} --profile release
4 Likes

@Ali thank you so much for maintaining the compilers’ setup, this is the way to go.

1 Like

Thanks a lot for implementing this GitHub Action! I am already using it.

Just a question: Why is lfortran paired with gcc in Ubuntu, but with clang in MacOS and Windows? Would it not be preferable to have the same pairing across OSs?

1 Like

@HugoMVale thank you for using the action, happy to see it is working for you.

My priority was to get the basic hello world test with fpm working correctly, then run tests on some of my own repositories with both fpm and CMake. Later I added the C/C++ compiler without considering making the pairing consistent across OSs (my mistake :wink:). To be honest, I was not sure what would be the best pairing for lfortran. Any suggestion? I can improve this in the next version.

(I am also thinking about introducing two new variables like c-compiler and cpp-compiler so the user can choose them, but that would also require adding c-version and cpp-version and modifying the logic of the implementation. I would like to avoid that for now as it needs more time.)

LFortran works with either one. Usually clang is available by default on macOS and gcc on Linux, so that seems to make the most sense?

On Windows typically clang is easier to install via conda.

1 Like

For a default settings, as an user testing different compilers, I would find it reasonable to pair Lfortran with clang systematically. For the simple reason that both are from the LLVM family. And for a CI/CD script I would find it nice that it helps verify cross-platform stability, meaning that if Lfortran is paired with clang on one platform, I would find it easier-to-follow-mentally to have the same pairing for the other platforms as to minimize the number of things to check if something goes wrong or results are too different.

2 Likes

That is exactly what I was thinking when I raised the question in my previous post.

1 Like

Since LFortran works with all cases, I would follow @hkvzjal’s and @HugoMVale’s suggestion to use Clang with LFortran on all platforms as the default case. Thanks!

1 Like

With the latest release (v0.10.0), clang/clang++ is now paired with LFortran on Ubuntu.

1 Like

Good idea. We should update LFortran upstream to by default expect clang on both Linux and macOS, and only use gcc if the user selects (either compiler option or environment variables). Since we use LLVM as our default backend, I agree that it makes sense to just depend on Clang.

1 Like