fortran-lang / setup-fortran

GitHub action to setup Fortran compiler and toolchain
https://github.com/marketplace/actions/setup-fortran
Apache License 2.0
74 stars 24 forks source link

`intel` compiler not found in Windows `cmake` project build #45

Open praynaud opened 10 months ago

praynaud commented 10 months ago

Summary

This is for a Windows fortran project that uses cmake to build and test and uses Visual Studio 17 2022 as the generator. I need to install the intel-classic compiler, preferably the latest version, which is 2021.10. The compiler seemingly installs, but then cmake does not know the Fortran compiler identification and the build fails.

Details

My CI script (relevant parts):

jobs:
  CI_Windows:
    runs-on: [windows-latest]
    strategy:
      fail-fast: true

    - name: Setup Fortran
      uses: fortran-lang/setup-fortran@v1
      with:
        compiler: intel-classic
        version: '2021.10'

    - name: Check Compilers and Versions
      run: |
        echo $env:FC
        cmake --version
        python --version

    - name: Build and Test
      run: |
        .\build_and_test.bat

My build_and_test.bat script is as follows:

cmake -S . -B build
cmake --build build --config Debug -j %NUMBER_OF_PROCESSORS%

The output/error in the GitHub CI is:

-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 6.2.9200.
-- The Fortran compiler identification is unknown
-- The C compiler identification is MSVC 19.35.32217.1
-- The CXX compiler identification is MSVC 19.35.32217.1
CMake Error at CMakeLists.txt:96 (project):
  No CMAKE_Fortran_COMPILER could be found.

I tried other GitHub Actions and the modflowpy/install-intelfortran-action@v1 action works for my project by takes a very long time. It appears this action is an ancestor of the current fortran-lang/setup-fortran action, so I'm hoping there is something in that older action that could be added to the current action to properly set environment variables such that cmake can correctly detect the Fortran compiler.

For information, here is the output of my successful CI when using the older Action:

-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 6.2.9200.
-- The Fortran compiler identification is Intel 2021.7.0.20220726
-- The C compiler identification is MSVC 19.35.32217.1
-- The CXX compiler identification is MSVC 19.35.32217.1

Thanks for helping and for creating these great tools!

wpbonelli commented 10 months ago

Thanks for raising, ideally this could be tested (planned in #31).

Does anything here help? https://github.com/modflowpy/install-intelfortran-action/issues/10 issues with cmake discovery have been reported before. See also https://github.com/fortran-lang/setup-fortran/issues/6

praynaud commented 10 months ago

@wpbonelli Thank you for the links. It does seem like some people have found workarounds by using a different generator. I will investigate and report back if I find a solution.

In the meantime, I fully support the work planned in #31 !

wpbonelli commented 9 months ago

@praynaud does your issue occur consistently, or only on cache restore? If the latter, perhaps #48 may resolve it

praynaud commented 9 months ago

@wpbonelli It's been a minute since I looked into this. Let me give it a try with this new version. I will report back ASAP.

praynaud commented 9 months ago

@wpbonelli Unfortunately, the cache restore still does not work. I used the action with @main instead of @v1 (see below). I will let you know tomorrow if a fresh install works, because unfortunately something downstream was wrong with my script upon the first run, so the cache was created but the script failed because of something unrelated. The cache should be 'gone' by tomorrow...

jobs:
  CI_Windows:
    runs-on: [windows-latest]
    strategy:
      fail-fast: false

    - name: Setup Fortran
      uses: fortran-lang/setup-fortran@main
      id: setup-fortran
      with:
        compiler: intel-classic
        version: '2021.10'
praynaud commented 9 months ago

@wpbonelli The fresh install also fails, but I'm now looking into other generators. As mentioned above, the modflowpy/install-intelfortran-action@v1 action worked on fresh install (not cache restore), so there must be a difference between the two actions that causes the failure for fresh installations using the new action.

praynaud commented 8 months ago

@zbeekman I am tagging because you might be able to help...

rma-rripken commented 8 months ago

I'm on Windows and using fortran-lang/setup-fortran@main and have a similar problem. When there isn't a cache the build will work but once the cache is hit cmake fails to find the fortran compiler. I briefly tried '-G Ninja' in my local environment and that caused my local build to fail in ways I didn't know how to solve. I was hopeful that #48 was going to fix my build issue but something in my setup still isn't quite right. I'd appreciate any suggestions or next steps I could try to improve the build configuration.
https://github.com/rma-rripken/AnnLineGen_RMA