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

Forces MSVC in MSYS MinGW environment #137

Open HunterZ opened 4 months ago

HunterZ commented 4 months ago

Trying to use this to build a C++ CMake + vcpkg project on Windows using MSYS2 MinGW64. Everything looks good until it tries to configure my actual project, where CMake then mis-detects MSVC as the compiler instead of MinGW GCC: https://github.com/HunterZ/rustLaunchSite/actions/runs/7940167541/job/21681100015#step:8:479

Possibly related to this weird step where it invokes vcpkg with a triplet of "x64-windows" instead of respecting what's in my workflow YAML and CMakePresets.json files: https://github.com/HunterZ/rustLaunchSite/actions/runs/7940167541/job/21681100015#step:8:28

Here is my repo at the corresponding commit from which the failure log was generated: https://github.com/HunterZ/rustLaunchSite/tree/daa663c0c2ceb7dde8a6ac0a754fe553d365e6f7

HunterZ commented 4 months ago

I thought maybe I wasn't being forceful enough in specifying the x64-mingw-static triplet, so I reworked things a bit to set VCPKG_DEFAULT_TRIPLET and VCPKG_DEFAULT_HOST_TRIPLET globally to the workflow. I no longer see x64-windows being passed to vcpkg at any point, yet CMake still detects MSVC instead of MinGW GCC when configuring my project.

YAML: https://github.com/HunterZ/rustLaunchSite/blob/495cc0445f117f620e186ac969ce4992f25ad0f0/.github/workflows/rustLaunchSite.yml

Log: https://github.com/HunterZ/rustLaunchSite/actions/runs/7943343192/job/21687604588#step:8:1353

lukka commented 4 months ago

@HunterZ take a look to the last block in the flowchart. When used wth vcpkg (e.g. VCPKG_ROOT defined), the action does automatically setup the MSVC environment when running on Windows and when CC and CXX are not defined. You can opt out of this behavior by setting CC and CXX to "gcc" I believe.

Hopefully this is all you need to fix your issue, let me know. Also, any feedback is welcome.

HunterZ commented 4 months ago

That sounds super awkward.

I've also got a new data point: Since I'm now setting up everything in MSYS2 and using vcpkg as a submodule, I've disabled use of run-vcpkg and get-cmake in my workflow. It turns out that run-cmake invokes C:\Program Files\CMake\bin\cmake.exe instead of respecting the PATH environment variable, which in the shell resolves to MSYS2 cmake: https://github.com/HunterZ/rustLaunchSite/actions/runs/7943786474/job/21688556621#step:4:1 https://github.com/HunterZ/rustLaunchSite/actions/runs/7943786474/job/21688556621#step:11:27

Is there a way to get run-cmake to run cmake in the default shell specified in the workflow, or is it doing more harm than good to use an Action here versus just scripting simpler run directives?

HunterZ commented 4 months ago

Update: Yeah, just running cmake natively in the shell works. Really my only issue with the workflow now is that it builds vcpkg dependencies every time, which takes up 75% of the workflow's total runtime. There's probably some way to cache stuff, but I have no idea how to do it since your Actions don't seem compatible with my environment.

Success log: https://github.com/HunterZ/rustLaunchSite/actions/runs/7944098934/job/21689210643