Skip to content

Commit

Permalink
feat: set FPM environment variables (#63)
Browse files Browse the repository at this point in the history
* set FPM_FC/FPM_CC/FPM_CXX matching FC/CC/CXX
* consolidate env var assignment in setup script
  • Loading branch information
wpbonelli authored Mar 7, 2024
1 parent e9da799 commit 82ccb70
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 65 deletions.
4 changes: 4 additions & 0 deletions .github/actions/test-cc/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ runs:
- name: Check compiler version
shell: bash
run: |
# check $CC == $FPM_CC
[[ "${{ env.CC }}" == "${{ env.FPM_CC }}" ]] && (echo "CC and FPM_CC match") || (echo "CC and FPM_CC don't match: ${{ env.CC }} != ${{ env.FPM_CC}}"; exit 1)
# check compiler version
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]] && [[ "${{ inputs.compiler }}" != "nvidia-hpc" ]]); then
# only last line of output captured by command substitution, write to temp file instead
${{ env.CC }} //QV > "$RUNNER_TEMP/${{ env.CC }}.ver" 2>&1
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/test-cxx/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ runs:
- name: Check compiler version
shell: bash
run: |
# check $CXX == $FPM_CXX
[[ "${{ env.CXX }}" == "${{ env.FPM_CXX }}" ]] && (echo "CXX and FPM_CXX match") || (echo "CXX and FPM_CXX don't match: ${{ env.CXX }} != ${{ env.FPM_CXX}}"; exit 1)
# check compiler version
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ matrix.toolchain.compiler }}" =~ "intel" ]] && [[ "${{ matrix.toolchain.compiler }}" != "nvidia-hpc" ]]); then
# only last line of output captured by command substitution, write to temp file instead
${{ env.CXX }} //QV > "$RUNNER_TEMP/${{ env.CXX }}.ver" 2>&1
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/test-fc/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ runs:
- name: Check compiler version
shell: bash
run: |
# check $FC == $FPM_FC
[[ "${{ env.FC }}" == "${{ env.FPM_FC }}" ]] && (echo "FC and FPM_FC match") || (echo "FC and FPM_FC don't match: ${{ env.FC }} != ${{ env.FPM_FC}}"; exit 1)
# check compiler version
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]] && [[ "${{ inputs.compiler }}" != "nvidia-hpc" ]]); then
# only last line of output captured by command substitution, write to temp file instead
${{ env.FC }} //QV > "$RUNNER_TEMP/${{ env.FC }}.ver" 2>&1
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ The same values are also set as environment variables:
- `CC`
- `CXX`

Corresponding FPM environment variables are also set:

- `FPM_FC`
- `FPM_CC`
- `FPM_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).


Expand Down
60 changes: 28 additions & 32 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,9 @@ runs:
;;
esac
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
echo "FC=${FC}" >> $GITHUB_ENV
echo "CC=${CC}" >> $GITHUB_ENV
echo "CXX=${CXX}" >> $GITHUB_ENV
# save oneAPI cache and activate environment
- name: Save cache
Expand All @@ -103,42 +100,41 @@ runs:
:: 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: |
# Intel compilers may have restored from cache so env vars may not be set
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
FC=ifx
CC=icx
CXX=icx
echo SETVARS_COMPLETED=1>>$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
FC=ifort
CC=icl
CXX=icl
echo SETVARS_COMPLETED=1>>$GITHUB_ENV
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
# set env vars
echo FC=$FC>>$GITHUB_ENV
echo CC=$CC>>$GITHUB_ENV
echo CXX=$CXX>>$GITHUB_ENV
# set fpm env vars
echo FPM_FC=$FC>>$GITHUB_ENV
echo FPM_CC=$CC>>$GITHUB_ENV
echo FPM_CXX=$CXX>>$GITHUB_ENV
# set action outputs
echo fc=$FC>>$GITHUB_OUTPUT
echo cc=$CC>>$GITHUB_OUTPUT
echo cxx=$CXX>>$GITHUB_OUTPUT
# 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
51 changes: 18 additions & 33 deletions setup-fortran.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ install_gcc_brew()
ln -fs /usr/local/bin/g++-${version} /usr/local/bin/g++
fi
fi

export FC="gfortran"
export CC="gcc"
export CXX="g++"
}

install_gcc_apt()
Expand All @@ -83,10 +79,6 @@ install_gcc_apt()
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${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"
export CXX="g++"
}

install_gcc_choco()
Expand Down Expand Up @@ -143,10 +135,6 @@ install_gcc_choco()
if [ -d "$FCDIR" ] && [ -f "$LNDIR/libgfortran-5.dll" ] && [ ! -f "$FCDIR/libgfortran-5.dll" ]; then
ln -s "$LNDIR/libgfortran-5.dll" "$FCDIR/libgfortran-5.dll"
fi

export FC="gfortran"
export CC="gcc"
export CXX="g++"
}

install_gcc()
Expand All @@ -173,6 +161,10 @@ install_gcc()
exit 1
;;
esac

export FC="gfortran"
export CC="gcc"
export CXX="g++"
}

export_intel_vars()
Expand Down Expand Up @@ -348,16 +340,6 @@ install_intel_apt()

source /opt/intel/oneapi/setvars.sh
export_intel_vars

if $classic; then
export FC="ifort"
export CC="icc"
export CXX="icpc"
else
export FC="ifx"
export CC="icx"
export CXX="icpx"
fi
}

install_intel_dmg()
Expand Down Expand Up @@ -428,10 +410,6 @@ install_intel_dmg()

source /opt/intel/oneapi/setvars.sh
export_intel_vars

export FC="ifort"
export CC="icc"
export CXX="icpc"
}

install_intel_win()
Expand Down Expand Up @@ -515,6 +493,16 @@ install_intel()
exit 1
;;
esac

if $classic; then
export FC="ifort"
export CC="icc"
export CXX="icpc"
else
export FC="ifx"
export CC="icx"
export CXX="icpx"
fi
}

export_nvidiahpc_vars()
Expand Down Expand Up @@ -563,14 +551,7 @@ install_nvidiahpc_apt()
echo "NVIDIA HPC SDK $version module loaded."

# set environment variables
echo "Setting environment variables..."
export_nvidiahpc_vars $version

# set environment variables
export FC="nvfortran"
export CC="nvc"
export CXX="nvc++"
echo "Environment variables set."
}

install_nvidiahpc()
Expand Down Expand Up @@ -601,4 +582,8 @@ install_nvidiahpc()
exit 1
;;
esac

export FC="nvfortran"
export CC="nvc"
export CXX="nvc++"
}

0 comments on commit 82ccb70

Please sign in to comment.