diff --git a/.github/actions/test-cc/action.yml b/.github/actions/test-cc/action.yml index bb930ed0..b6dceb77 100644 --- a/.github/actions/test-cc/action.yml +++ b/.github/actions/test-cc/action.yml @@ -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 diff --git a/.github/actions/test-cxx/action.yml b/.github/actions/test-cxx/action.yml index f7b3ae71..7e6c8262 100644 --- a/.github/actions/test-cxx/action.yml +++ b/.github/actions/test-cxx/action.yml @@ -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 diff --git a/.github/actions/test-fc/action.yml b/.github/actions/test-fc/action.yml index 477bbc11..bca4e9ea 100644 --- a/.github/actions/test-fc/action.yml +++ b/.github/actions/test-fc/action.yml @@ -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 diff --git a/README.md b/README.md index d95fc881..ed60893c 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/action.yml b/action.yml index d3f88755..af0ba68d 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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') diff --git a/setup-fortran.sh b/setup-fortran.sh index 7dbde6c1..ec436dbd 100755 --- a/setup-fortran.sh +++ b/setup-fortran.sh @@ -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() @@ -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() @@ -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() @@ -173,6 +161,10 @@ install_gcc() exit 1 ;; esac + + export FC="gfortran" + export CC="gcc" + export CXX="g++" } export_intel_vars() @@ -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() @@ -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() @@ -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() @@ -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() @@ -601,4 +582,8 @@ install_nvidiahpc() exit 1 ;; esac + + export FC="nvfortran" + export CC="nvc" + export CXX="nvc++" } \ No newline at end of file