This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Check CMAKE_CXX_STANDARD and error if it's to old
ClosedPublic

Authored by thieta on Aug 7 2022, 12:54 PM.

Details

Summary

Also nuke the old value out of the cache if it's there, otherwise
it could lead to problems when the project increases the standard
and the developer just runs the "make/ninja" program.

Diff Detail

Event Timeline

thieta created this revision.Aug 7 2022, 12:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2022, 12:54 PM
Herald added a subscriber: mgorny. · View Herald Transcript
thieta requested review of this revision.Aug 7 2022, 12:54 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2022, 12:54 PM
royjacobson accepted this revision.Aug 7 2022, 2:00 PM

Wow, that was quick, thanks!

I played with it a bit locally and it seems to solve this problem. I have one comment about the fatal error, but otherwise LGTM.

llvm/CMakeLists.txt
71

I tried to give it an explicit -DCMAKE_CXX_STANDARD=14 and it will warn and reset it to 17, but not error. It's an improvement over silently using 14 which we do now, but even with the warning it might be slightly surprising? Personally I think you can just get rid of this check.

This revision is now accepted and ready to land.Aug 7 2022, 2:00 PM

I myself stumbled upon this caching behavior, and although I knew that the minimum required standard has changed, it was surprising to notice that the project is still being built with -std=c++14.
Nevertheless, I don't find this change necessary. The minimum requirement does not change often (is this the second time?).
People will eventually clear the cache, as they once did. Active developers are already aware of the change and it will not take long for them to realize what is the cause of the issue.

I don't have strong objections, only that this slightly complicates already complex build system, and only needed once in a decade.

llvm/CMakeLists.txt
68

This resets the cache variable in the main project, but what about subprojects? Will they also be affected?

Allen added a subscriber: Allen.Aug 8 2022, 2:35 AM
thieta added a comment.Aug 8 2022, 4:19 AM

I myself stumbled upon this caching behavior, and although I knew that the minimum required standard has changed, it was surprising to notice that the project is still being built with -std=c++14.
Nevertheless, I don't find this change necessary. The minimum requirement does not change often (is this the second time?).
People will eventually clear the cache, as they once did. Active developers are already aware of the change and it will not take long for them to realize what is the cause of the issue.

I don't have strong objections, only that this slightly complicates already complex build system, and only needed once in a decade.

I agree with a lot of this. Maybe the right thing is to just check if CMAKE_CXX_STANDARD is lower than the required and skip the whole cache check. Since this is a user-configurable setting it would be good to make sure we don't hand the user a foot-gun.

thieta added inline comments.Aug 8 2022, 5:28 AM
llvm/CMakeLists.txt
68

It should be reset for every other subproject that's included with ENABLE_PROJECTS - but with runtimes I am not sure what makes it re-gen the cache there which will be needed.

thieta added a comment.Aug 8 2022, 5:51 AM

After a bit of thinking - I think we should merge this as it is now and we can always revert it later in a few weeks if we want - but for now it would self-heal a lot of local setups and bots.

This revision was landed with ongoing or failed builds.Aug 8 2022, 6:07 AM
This revision was automatically updated to reflect the committed changes.

After a bit of thinking - I think we should merge this as it is now and we can always revert it later in a few weeks if we want - but for now it would self-heal a lot of local setups and bots.

Fine with me