From f6049f0df6b8e8993e031657501338f885d22fd5 Mon Sep 17 00:00:00 2001 From: muk2 Date: Sun, 16 Aug 2026 13:13:38 -0400 Subject: [PATCH] Add LLVM Flang CI Add a Linux CI job that builds libamrex and its Fortran interfaces with LLVM Flang (and matching Clang). This catches LLVM-Flang-specific Fortran compile errors such as the duplicate `public` attribute fixed in #5604, which gfortran-based CI does not flag. Closes #5605. Co-Authored-By: Claude Opus 4.8 --- .../dependencies/dependencies_flang.sh | 32 ++++++++++++ .github/workflows/flang.yml | 49 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100755 .github/workflows/dependencies/dependencies_flang.sh create mode 100644 .github/workflows/flang.yml diff --git a/.github/workflows/dependencies/dependencies_flang.sh b/.github/workflows/dependencies/dependencies_flang.sh new file mode 100755 index 00000000000..07aa25049d2 --- /dev/null +++ b/.github/workflows/dependencies/dependencies_flang.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# +# Copyright 2020-2026 The AMReX Community +# +# License: BSD-3-Clause-LBNL + +set -eu -o pipefail + +# `man apt.conf`: +# Number of retries to perform. If this is non-zero APT will retry +# failed files the given number of times. +echo 'Acquire::Retries "3";' | sudo tee /etc/apt/apt.conf.d/80-retries + +# Install a recent LLVM Flang (and the matching Clang) from apt.llvm.org. +# The desired LLVM major version is passed as the first argument. +if [[ ! -f /etc/apt/trusted.gpg.d/apt.llvm.org.asc ]]; then + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc +fi + +source /etc/os-release # set UBUNTU_CODENAME + +sudo add-apt-repository "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME} main" +sudo add-apt-repository "deb http://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-$1 main" + +sudo apt-get update + +sudo apt-get install -y --no-install-recommends \ + build-essential \ + libfftw3-dev \ + clang-$1 \ + flang-$1 \ + libomp-$1-dev diff --git a/.github/workflows/flang.yml b/.github/workflows/flang.yml new file mode 100644 index 00000000000..0efe0de56d9 --- /dev/null +++ b/.github/workflows/flang.yml @@ -0,0 +1,49 @@ +name: LinuxFlang + +on: + push: + branches-ignore: + - 'dependabot/**' + pull_request: + +concurrency: + group: ${{ github.ref }}-${{ github.head_ref }}-linux-flang + cancel-in-progress: true + +jobs: + check_changes: + uses: ./.github/workflows/check_changes.yml + + # Build libamrex and its Fortran interfaces with LLVM Flang. + # This guards against LLVM-Flang-specific Fortran errors such as #5603. + library_flang: + name: Flang@20 DP NOMPI Fortran Interfaces [lib] + runs-on: ubuntu-24.04 + needs: check_changes + if: needs.check_changes.outputs.has_non_docs_changes == 'true' + steps: + - uses: actions/checkout@v7 + - name: Dependencies + run: .github/workflows/dependencies/dependencies_flang.sh 20 + - name: Build & Install + run: | + # The apt.llvm.org packages ship the driver as either flang- + # or flang-new- depending on the LLVM release. + FLANG=$(which flang-20 || which flang-new-20) + + mkdir build + cd build + cmake .. \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DCMAKE_INSTALL_PREFIX=/tmp/my-amrex \ + -DAMReX_EB=ON \ + -DAMReX_FORTRAN=ON \ + -DAMReX_FORTRAN_INTERFACES=ON \ + -DAMReX_MPI=OFF \ + -DCMAKE_C_COMPILER=$(which clang-20) \ + -DCMAKE_CXX_COMPILER=$(which clang++-20) \ + -DCMAKE_Fortran_COMPILER=${FLANG} + make -j 4 + make install + make test_install