lukka / run-cmake

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

Windows MSVC build has cache hit but vcpkg still rebuilds every package? #78

Closed quyykk closed 2 years ago

quyykk commented 2 years ago

I have 4 jobs: Linux, MacOS, Windows MinGW and Windows MSVC. All using get-cmake, run-vcpkg and run-cmake. In fact, the job is basically identical for all four of them. But for the MSVC build the packages from vcpkg are being rebuilt every single time, even though there's a cache hit. So I'm really not sure what is going wrong.

From run-vcpkg:

Restore vcpkg and its artifacts from cache
  Cache key: 'runnerOS=win2220220626.1-vcpkgGitCommit=da70d4586c9534cdc2ff656aadb5a23d33e30086_vcpkgJson=872885daeddf2fdbf652ce45167027a4bb411b4a366a0eeca5bea7c37987be21'
  Cache restore keys: 'runnerOS=win2220220626.1-vcpkgGitCommit=da70d4586c9534cdc2ff656aadb5a23d33e30086'
  Cached paths: 'D:/a/endless-sky/b/vcpkg_cache,D:\a\endless-sky\endless-sky\vcpkg,!D:\a\endless-sky\endless-sky\vcpkg\installed,!D:\a\endless-sky\endless-sky\vcpkg\vcpkg_installed,!D:\a\endless-sky\endless-sky\vcpkg\packages,!D:\a\endless-sky\endless-sky\vcpkg\buildtrees,!D:\a\endless-sky\endless-sky\vcpkg\downloads'
  Cache Size: ~99 MB (103798965 B)
  C:\Windows\System32\tar.exe -z -xf D:/a/_temp/c722812d-2d84-4efa-9cd6-5996c6f27b66/cache.tgz -P -C D:/a/endless-sky/endless-sky
  Cache hit, key = 'runnerOS=win2220220626.1-vcpkgGitCommit=da70d4586c9534cdc2ff656aadb5a23d33e30086_vcpkgJson=872885daeddf2fdbf652ce45167027a4bb411b4a366a0eeca5bea7c37987be21'.

Which as far as I understand successfully downloads the cache. But then in run-cmake:

Additional packages (*) will be modified to complete this operation.
  Restored 2 packages from D:\a\endless-sky\b\vcpkg_cache in 25.29 ms. Use --debug to see more details.
  Installing 1/10 vcpkg-cmake-config:x64-windows...
  Elapsed time to handle vcpkg-cmake-config:x64-windows: 3.927 ms
  Installing 2/10 vcpkg-cmake:x64-windows...
  Elapsed time to handle vcpkg-cmake:x64-windows: 3.773 ms
  Installing 3/10 opengl:x64-windows...
  Building opengl[core]:x64-windows...

It starts building. It seems to have found 2 packages, but the rest is gone or something. (--debug would be helpful but I don't know how to specify it).

Here's a run (all green) that erroneously rebuilds the packages: https://github.com/quyykk/endless-sky/runs/7221991331 Here's the run right after that one that also fails to rebuild: https://github.com/quyykk/endless-sky/runs/7222278448

What could be going wrong? Is it an error on my end? Thanks!

quyykk commented 2 years ago

Seems like causing a deliberate cache miss fixed the issue for some reason. Sorry for this unnecessary issue.

quyykk commented 2 years ago

Nevermind, now it's the MinGW action. I figured out the problem though. It seems like the cache uses the Windows version and some other ids as cache id, but since the two jobs are both using Windows, the cache id is the same and only one cache is active.

The other doesn't get saved: https://github.com/quyykk/endless-sky/runs/7222856466?check_suite_focus=true#step:15:6

Warning: reserveCache failed: Cache already exists. Scope: refs/heads/cmake, Key: runnerOS=win2220220626.1-vcpkgGitCommit=944c880fcbeaaf41a11f3ed8099f22528b38dbf3_vcpkgJson=872885daeddf2fdbf652ce45167027a4bb411b4a366a0eeca5bea7c37987be21, Version: e2e62879311cf67fd97e14628b1f3ddba385beab6e373154a593b82a118a7806

I've found the appendedCacheKey input for run-vcpkg. Sorry for the noise.

lukka commented 2 years ago

@quyykk thanks for reporting what the root cause of the issue is! Looks like a problem with the documentation, since it does not call out what happens if you build with different compilers on the same operating system. Looks like a fix to do on the run-vcpkg repo.