Skip to content

Commit 82ccb70

Browse files
authored
feat: set FPM environment variables (#63)
* set FPM_FC/FPM_CC/FPM_CXX matching FC/CC/CXX * consolidate env var assignment in setup script
1 parent e9da799 commit 82ccb70

File tree

6 files changed

+64
-65
lines changed

6 files changed

+64
-65
lines changed

.github/actions/test-cc/action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ runs:
1414
- name: Check compiler version
1515
shell: bash
1616
run: |
17+
# check $CC == $FPM_CC
18+
[[ "${{ 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)
19+
20+
# check compiler version
1721
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]] && [[ "${{ inputs.compiler }}" != "nvidia-hpc" ]]); then
1822
# only last line of output captured by command substitution, write to temp file instead
1923
${{ env.CC }} //QV > "$RUNNER_TEMP/${{ env.CC }}.ver" 2>&1

.github/actions/test-cxx/action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ runs:
1414
- name: Check compiler version
1515
shell: bash
1616
run: |
17+
# check $CXX == $FPM_CXX
18+
[[ "${{ 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)
19+
20+
# check compiler version
1721
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ matrix.toolchain.compiler }}" =~ "intel" ]] && [[ "${{ matrix.toolchain.compiler }}" != "nvidia-hpc" ]]); then
1822
# only last line of output captured by command substitution, write to temp file instead
1923
${{ env.CXX }} //QV > "$RUNNER_TEMP/${{ env.CXX }}.ver" 2>&1

.github/actions/test-fc/action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ runs:
1414
- name: Check compiler version
1515
shell: bash
1616
run: |
17+
# check $FC == $FPM_FC
18+
[[ "${{ 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)
19+
20+
# check compiler version
1721
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]] && [[ "${{ inputs.compiler }}" != "nvidia-hpc" ]]); then
1822
# only last line of output captured by command substitution, write to temp file instead
1923
${{ env.FC }} //QV > "$RUNNER_TEMP/${{ env.FC }}.ver" 2>&1

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ The same values are also set as environment variables:
8989
- `CC`
9090
- `CXX`
9191

92+
Corresponding FPM environment variables are also set:
93+
94+
- `FPM_FC`
95+
- `FPM_CC`
96+
- `FPM_CXX`
97+
9298
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).
9399

94100

action.yml

+28-32
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,9 @@ runs:
7979
;;
8080
esac
8181
82-
if ! ([[ "$RUNNER_OS" == "Windows" ]] && [[ "${{ inputs.compiler }}" =~ "intel" ]]); then
83-
# save environment variables
84-
echo "FC=${FC}" >> $GITHUB_ENV
85-
echo "CC=${CC}" >> $GITHUB_ENV
86-
echo "CXX=${CXX}" >> $GITHUB_ENV
87-
fi
82+
echo "FC=${FC}" >> $GITHUB_ENV
83+
echo "CC=${CC}" >> $GITHUB_ENV
84+
echo "CXX=${CXX}" >> $GITHUB_ENV
8885
8986
# save oneAPI cache and activate environment
9087
- name: Save cache
@@ -103,42 +100,41 @@ runs:
103100
:: this script fails when install location is not the default
104101
call "%ONEAPI_ROOT%\compiler\%LATEST%\env\vars.bat"
105102
set | findstr /c:"oneAPI" >> "%GITHUB_ENV%"
106-
# Intel compilers may have restored from cache so env vars may not be set,
107-
# set them then set outputs for all compilers/toolchains
103+
108104
- name: Set outputs and env vars
109105
shell: bash
110106
id: outputs
111107
run: |
108+
# Intel compilers may have restored from cache so env vars may not be set
112109
if [[ "$RUNNER_OS" == "Windows" ]]; then
113110
if [[ "${{ inputs.compiler }}" == "intel" ]]; then
114-
echo fc=ifx>>$GITHUB_OUTPUT
115-
echo cc=icx>>$GITHUB_OUTPUT
116-
echo cxx=icx>>$GITHUB_OUTPUT
117-
echo FC=ifx>>$GITHUB_ENV
118-
echo CC=icx>>$GITHUB_ENV
119-
echo CXX=icx>>$GITHUB_ENV
111+
FC=ifx
112+
CC=icx
113+
CXX=icx
114+
echo SETVARS_COMPLETED=1>>$GITHUB_ENV
120115
elif [[ "${{ inputs.compiler }}" == "intel-classic" ]]; then
121-
echo fc=ifort>>$GITHUB_OUTPUT
122-
echo cc=icl>>$GITHUB_OUTPUT
123-
echo cxx=icl>>$GITHUB_OUTPUT
124-
echo FC=ifort>>$GITHUB_ENV
125-
echo CC=icl>>$GITHUB_ENV
126-
echo CXX=icl>>$GITHUB_ENV
127-
else
128-
echo fc=$FC>>$GITHUB_OUTPUT
129-
echo cc=$CC>>$GITHUB_OUTPUT
130-
echo cxx=$CXX>>$GITHUB_OUTPUT
116+
FC=ifort
117+
CC=icl
118+
CXX=icl
119+
echo SETVARS_COMPLETED=1>>$GITHUB_ENV
131120
fi
132-
else
133-
echo fc=$FC>>$GITHUB_OUTPUT
134-
echo cc=$CC>>$GITHUB_OUTPUT
135-
echo cxx=$CXX>>$GITHUB_OUTPUT
136121
fi
137122
138-
# intel oneapi flag to indicate env has been activated
139-
if [[ "${{ inputs.compiler }}" =~ "intel" ]]; then
140-
echo SETVARS_COMPLETED=1>>$GITHUB_ENV
141-
fi
123+
# set env vars
124+
echo FC=$FC>>$GITHUB_ENV
125+
echo CC=$CC>>$GITHUB_ENV
126+
echo CXX=$CXX>>$GITHUB_ENV
127+
128+
# set fpm env vars
129+
echo FPM_FC=$FC>>$GITHUB_ENV
130+
echo FPM_CC=$CC>>$GITHUB_ENV
131+
echo FPM_CXX=$CXX>>$GITHUB_ENV
132+
133+
# set action outputs
134+
echo fc=$FC>>$GITHUB_OUTPUT
135+
echo cc=$CC>>$GITHUB_OUTPUT
136+
echo cxx=$CXX>>$GITHUB_OUTPUT
137+
142138
# GitHub Actions prepends GNU linker to the PATH before all bash steps, hide it so MSVC linker is found
143139
- name: Hide GNU linker (Windows)
144140
if: runner.os == 'Windows' && contains(inputs.compiler, 'intel')

setup-fortran.sh

+18-33
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ install_gcc_brew()
5959
ln -fs /usr/local/bin/g++-${version} /usr/local/bin/g++
6060
fi
6161
fi
62-
63-
export FC="gfortran"
64-
export CC="gcc"
65-
export CXX="g++"
6662
}
6763

6864
install_gcc_apt()
@@ -83,10 +79,6 @@ install_gcc_apt()
8379
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${version} \
8480
--slave /usr/bin/gcov gcov /usr/bin/gcov-${version} \
8581
--slave /usr/bin/g++ g++ /usr/bin/g++-${version}
86-
87-
export FC="gfortran"
88-
export CC="gcc"
89-
export CXX="g++"
9082
}
9183

9284
install_gcc_choco()
@@ -143,10 +135,6 @@ install_gcc_choco()
143135
if [ -d "$FCDIR" ] && [ -f "$LNDIR/libgfortran-5.dll" ] && [ ! -f "$FCDIR/libgfortran-5.dll" ]; then
144136
ln -s "$LNDIR/libgfortran-5.dll" "$FCDIR/libgfortran-5.dll"
145137
fi
146-
147-
export FC="gfortran"
148-
export CC="gcc"
149-
export CXX="g++"
150138
}
151139

152140
install_gcc()
@@ -173,6 +161,10 @@ install_gcc()
173161
exit 1
174162
;;
175163
esac
164+
165+
export FC="gfortran"
166+
export CC="gcc"
167+
export CXX="g++"
176168
}
177169

178170
export_intel_vars()
@@ -348,16 +340,6 @@ install_intel_apt()
348340

349341
source /opt/intel/oneapi/setvars.sh
350342
export_intel_vars
351-
352-
if $classic; then
353-
export FC="ifort"
354-
export CC="icc"
355-
export CXX="icpc"
356-
else
357-
export FC="ifx"
358-
export CC="icx"
359-
export CXX="icpx"
360-
fi
361343
}
362344

363345
install_intel_dmg()
@@ -428,10 +410,6 @@ install_intel_dmg()
428410

429411
source /opt/intel/oneapi/setvars.sh
430412
export_intel_vars
431-
432-
export FC="ifort"
433-
export CC="icc"
434-
export CXX="icpc"
435413
}
436414

437415
install_intel_win()
@@ -515,6 +493,16 @@ install_intel()
515493
exit 1
516494
;;
517495
esac
496+
497+
if $classic; then
498+
export FC="ifort"
499+
export CC="icc"
500+
export CXX="icpc"
501+
else
502+
export FC="ifx"
503+
export CC="icx"
504+
export CXX="icpx"
505+
fi
518506
}
519507

520508
export_nvidiahpc_vars()
@@ -563,14 +551,7 @@ install_nvidiahpc_apt()
563551
echo "NVIDIA HPC SDK $version module loaded."
564552

565553
# set environment variables
566-
echo "Setting environment variables..."
567554
export_nvidiahpc_vars $version
568-
569-
# set environment variables
570-
export FC="nvfortran"
571-
export CC="nvc"
572-
export CXX="nvc++"
573-
echo "Environment variables set."
574555
}
575556

576557
install_nvidiahpc()
@@ -601,4 +582,8 @@ install_nvidiahpc()
601582
exit 1
602583
;;
603584
esac
585+
586+
export FC="nvfortran"
587+
export CC="nvc"
588+
export CXX="nvc++"
604589
}

0 commit comments

Comments
 (0)