Rediscover toolchain as needed#12
Open
MathiasMagnus wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10
I got to the bottom of the issue and prepared a fix that suits my use case and likely that of others.
The problem
Apple decided to put some important/critical system components into encrypted, read-only disk images which are mounted on demand. The Metal toolchain is one such component. It is not mounted until either Xcode is launched or some
xcrunet al. command is run.The reason why after reboots the first configuration fails, is that the mount location has a random hash component, but the full path to the Metal compiler is baked into
<binary_dir>/CMakeFiles/<cmake_ver>/CMakeMetalCompiler.cmake. Upon first post-reboot configuration, whenproject(A LANGUAGES Metal)is called, the module-suppliedCMakeDetermineMetalCompiler.cmakeisn't consulted because the cached results are found on disk. The cached path is stale and some check fails resulting in a configuration time error and the deletion of the stale cache file. Thus during the second post-reboot configurationCMakeDetermineMetalCompiler.cmakeis consulted again, which in turn callsxcrun --find metalmounting the toolchain again.Solutions
Detecting the staleness of the cached compiler path in theory could be done elegantly from
MetalShaderSupport.cmake, however the variableCMAKE_PLATFORM_INFO_DIRused to find the location of the toolchain cache file isn't defined when non-CMake machinery runs. Otherwise detecting the staleness there and deleting the file beforeproject()is reached for a clean toolchain detection would be nice. The workaround is the reiterate some of the detection logic in the cache file itself. If the compiler "disappeared" and if it finds a compiler of the same version as previously, then it overwrites the cached variable.