lukka / run-cmake

GitHub Action to build C++ applications with CMake (CMakePresets.json), Ninja and vcpkg on GitHub.
MIT License
171 stars 19 forks source link

run-cmake doesn't set `toolset environment variables` when removing `configurePreset` #115

Closed bwrsandman closed 1 year ago

bwrsandman commented 1 year ago

Following discussion in #113. I am attempting this configuration where I remove configurePreset on the 2nd and 3rd use of lukka/run-cmake

      - uses: lukka/get-cmake@latest

      - name: Restore from cache and setup vcpkg executable and data files.
        uses: lukka/run-vcpkg@v11
        with:
          vcpkgJsonGlob: 'vcpkg.json'

      - name: Configure CMake+vcpkg+Ninja to generate.
        uses: lukka/run-cmake@v10
        with:
          configurePreset: 'ninja-multi-vcpkg'
          configurePresetCmdString: "[`--preset`, `$[env.CONFIGURE_PRESET_NAME]`, `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`, `-DOPENBLACK_WARNINGS_AS_ERRORS=ON`]"

      - name: Run CMake+vcpkg+Ninja+CTest to build/test (Debug).
        uses: lukka/run-cmake@v10
        with:
          # configurePreset: 'ninja-multi-vcpkg'
          # configurePresetCmdString: "[`--preset`, `$[env.CONFIGURE_PRESET_NAME]`, `-DOPENBLACK_WARNINGS_AS_ERRORS=ON`]"
          buildPreset: 'ninja-multi-vcpkg-debug'
          testPreset: 'ninja-multi-vcpkg-debug'

      - name: Run CMake+vcpkg+Ninja+CTest to build/test (Release).
        uses: lukka/run-cmake@v10
        with:
          # configurePreset: 'ninja-multi-vcpkg'
          # configurePresetCmdString: "[`--preset`, `$[env.CONFIGURE_PRESET_NAME]`, `-DOPENBLACK_WARNINGS_AS_ERRORS=ON`]"
          buildPreset: 'ninja-multi-vcpkg-release'
          testPreset: 'ninja-multi-vcpkg-release'

The reason why I do two runs after configuration is to reduce the size of my run matrix. This makes it so half the runners are spawned and the time spent in setup and cmake configure is saved (especially during cache misses). When I used lukka/run-vcpkg@v10 it also reduced the size of my caches. It may well be a lot less now with v11.

In the first run-cmake you need to define the variable definition (as you are already doing), then that is going to be cached and it is not needed anymore in subsequent steps (this is CMake doing it). On the 2nd and 3rd run-cmake you could drop the configurePreset (and configurePresetAdditionalArgs) and just keep the build preset, it will just run the build (and skip the configuration that already happened). Let me know if it is working as I think it does :)

Removing configurePreset on subsequent runs causes a strange error about being unable to find float.h

Running command '"D:\a\_temp\2061842909\cmake-3.26.3-windows-x86_64\bin\cmake.exe"' with args '^"--build^",^"--preset^",^"ninja-multi-vcpkg-debug^"' in current directory 'D:\a\openblack\openblack'.
  [1/138] Building CXX object externals\CMakeFiles\imgui_user.dir\Debug\imgui_user\imgui_bitfield.cpp.obj
  FAILED: externals/CMakeFiles/imgui_user.dir/Debug/imgui_user/imgui_bitfield.cpp.obj 
  C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1436~1.325\bin\Hostx64\x64\cl.exe  /nologo /TP -DIMGUI_DEFINE_MATH_OPERATORS -DCMAKE_INTDIR=\"Debug\" -ID:\a\openblack\openblack\externals\imgui_user -external:ID:\a\openblack\openblack\cmake-build-presets\ninja-multi-vcpkg\vcpkg_installed\x64-windows\include -external:ID:\a\openblack\openblack\cmake-build-presets\ninja-multi-vcpkg\vcpkg_installed\x64-windows\include\SDL2 -external:W0 /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -std:c++20 -MDd /showIncludes /Foexternals\CMakeFiles\imgui_user.dir\Debug\imgui_user\imgui_bitfield.cpp.obj /Fdexternals\CMakeFiles\imgui_user.dir\Debug\imgui_user.pdb /FS -c D:\a\openblack\openblack\externals\imgui_user\imgui_bitfield.cpp
  Error: D:\a\openblack\openblack\cmake-build-presets\ninja-multi-vcpkg\vcpkg_installed\x64-windows\include\imgui.h(65): fatal error C1083: Cannot open include file: 'float.h': No such file or directory

https://github.com/openblack/openblack/actions/runs/5266766498/jobs/9521754716

I'm pretty sure it's because Setup MSVC C/C++ toolset environment variables is not being setup in the two build invocations. Only in the configuration action.

These issues do not happen with:

  1. ubuntu-latest
  2. macos-latest
  3. ubuntu-latest + cc=clang, cxx=clang++
  4. windows-latest + cc=clang, cxx=clang++
  5. Cross compilation for android
lukka commented 1 year ago

@bwrsandman thanks, this was a long standing problem indeed, that is the MSVC environment is setup only when the configure preset being used. I pushed on run-cmake@main a version that fixes this, and I plan to publish it soon.

bwrsandman commented 1 year ago

Tested it in https://github.com/openblack/openblack/pull/608 and it works now

lukka commented 1 year ago

Fixed in https://github.com/lukka/run-cmake/releases/tag/v10.6