Repository navigation
cmake: make Threads package optional #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the code does not look platform-dependent.
According to the docs,
FindThreadsis capable of figuring out:Therefore, I don't see this change is necessary.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #354 (comment)
The docs are wrong. The REQUIRED keyword here hides useful error messages and replaces them with misleading "Could NOT find Threads" messages. This has happened to me on multiple occasions as described in the commit message and misled me and wasted my time.
If you think there is an advantage
REQUIREDprovides here, it would be good to know what it is. The only thing I see REQUIRED doing here is replacing real errors with fake and misleading ones. It seems clear to mefind_package(Threads)is a helpful way to add thread dependencies andfind_package(Threads REQUIRED)is a footgun.re: #354 (comment)
That's a bold prediction! It does not happen on current master, but it happened to me twice on different occasions changing the policy version and can easily happen with changes to platforms, toolchain files or any of the spaghetti code module files distributed with cmake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there something we can report upstream? Can you share the situation and output of the suppressed diagnostics?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the replies! I will close this PR because as obnoxious as
find_package(Threads REQUIRED)behavior is for producing misleading error and hiding useful debug information, theREQUIREDkeyword actually does seem to be used in bitcoin core and leveldb, so maybe it is not as much as a problem for others as it has been for me. And there could be other ways of avoiding harms like #352, or maybe moving thefind_packagecall later so more useful errors can be triggered earlier. When I first made this change a year ago as part of #209, I didn't know techniques for debuggingfind_packageerrors and found this very confusing, but now I won't have this problem anymore.Sorry for pushing back earlier. I pushed back because review comments were arguing against removing
REQUIREDwithout acknowledging the harms it caused or pointing to any benefits it offered. But thinking about it more, one real benefit thatREQUIREDoffers is more predictability and less variance between builds. For example with 45c7dca, if libmultiprocess is built on two openbsd systems, and one hasclang-scan-depsinstalled and one doesn't,find_packagemay succeed on one system and fail on the other causing the library to be built with slightly different threading flags even if both builds succeed and are usable.I still think 45c7dca is a correct change, just that benefits may not outweigh this cost. It is correct because the cmake
FindThreadsmodule is not a hard dependency of libmultiprocess (unlike Cap'n Proto).FindThreadsis just a convenience module provided with cmake to help with portability and it is perfectly possible to write multithreaded code without it, avoiding its warts and bugs.re: purpleKarrot #354 (comment)
I encountered these errors a year ago but you can see the error output in 45c7dca commit message and the
CMAKE_CXX_SCAN_FOR_MODULESbug is reported upstream https://gitlab.kitware.com/cmake/cmake/-/work_items/27228. I described the badCMAKE_TRY_COMPILE_NO_PLATFORM_VARIABLES/FindThreadsinteraction in #163 (comment) with steps to reproduce and you actually replied to that and seemed to think it was the same underlying bug.re: maflcko #354 (comment)
I don't think this is true because these errors depend on individual platform configurations. The same policies can work on one platform and cause problems on other platforms and this is exactly what we seen with
FindThreadswhere the bug isn't even really triggered by the platform, but just by what packages are currently installed. Better error output is better for everyone and is not just a temporary development need.re: hebasto #354 (review)
That example seems to be artificial (setup is not described) unlike the real examples in the commit message, and even in that case
cannot find -lpthreadseems like a much better error thanCould NOT find Threads (missing: Threads_FOUND)would be because it points to a clear cause.