-
Notifications
You must be signed in to change notification settings - Fork 444
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
Depend on Boost using FetchContent instead of relying on system-provided boost. #4663
base: main
Are you sure you want to change the base?
Conversation
b224bff
to
e9b0345
Compare
@fruffy How much of the boost used is not header-only? If it would be just headers, we may just extract a piece of it and vendor. |
We currently depend on
The only project out of those that is currently standalone is |
graph is used by one particular backend, so the dependency could be moved there. Everything else besides iostreams seems to be header-only and could be vendored (there is a special boost script for this, btw). |
de834be
to
eebe86c
Compare
Do we need a concrete version of boost that is newer then what is available on supported OSes? If not, I don't see a big reason to fetch boost ourselves. It can be easily installed almost everywhere. |
|
d6355d7
to
459d094
Compare
So after discussing this offline it looks like this may lead to an excessive amount of files we have to check into version control. The approach I have currently is probably the simplest. You only need to pull boost once and then can pick and choose the dependencies. There is still a problem, I am adding all the possible include paths because of the way boost is structured. This creates a bit of spam, maybe there is a better way to only add one include path, but that requires some fiddling with folders. |
b57e457
to
13dbc24
Compare
Recent versions of boost have improved their CMake support significantly. I pushed a version which only requires downloading boost and linking the appropriate targets. The required boost headers are exported with each target, comparable to Abseil. To make sure that the linked headers are included as system headers I had to do some patching, but that is fairly straightforward. If one desires to add additional boost targets, they can do so by setting |
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.
See comments. Likely some duplication and layering violations could be fixed
cmake/Boost.cmake
Outdated
set(Boost_USE_STATIC_RUNTIME OFF) | ||
endif() | ||
|
||
# The boost graph headers are optional and only required by the graphs back end. |
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.
This looks like a layering violation to me. Maybe the P4C_TARGET_BOOST_LIBRARIES
should be used here as well?
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.
It might be a tradeoff between moving a bunch of boost logic to the top-level or keeping it all contained within a single CMake file. I pushed some changes which explore the other option.
Not sure which way is preferable.
|
||
# Add boost modules. | ||
# format, multiprecision, and iostreams are needed by P4C core. | ||
set(BOOST_INCLUDE_LIBRARIES format multiprecision iostreams) |
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.
Can this be specified by caller?
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.
This is a variable that is consumed by the Boost CMakefiles to determine which libraries to enable. I think it could be specified by the caller but those three libraries are required.
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.
Consider the following case (take graph
backend as a model example): let us assume there is a backend that would require more boost modules. How these could be accomplished? It seems there should be some generic way to specify boost libraries that are to be used beyond the ones required by frontend currently.
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.
Yes, P4C_TARGET_BOOST_LIBRARIES
is intended for that. You either specify that at the command line or before invoking the Boost CMake or p4c_obtain_boost. Unfortunately, a back end can not retroactively add dependencies. Or at least I have not tried doing that.
I could make this a function parameter but that still has the same limitations from what I can see.
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.
How is P4C_TARGET_BOOST_LIBRARIES
related to ADDITIONAL_P4C_BOOST_LIBRARIES
? Also what exactly does "on commandline" mean? Ideally I would want to be able to set it from downstreams top-level cmake before including p4c
. Or at least from cmake presets for the downstream.
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.
How is P4C_TARGET_BOOST_LIBRARIES related to ADDITIONAL_P4C_BOOST_LIBRARIES
I reworded the variable, the comment is a little outdated.
Ideally I would want to be able to set it from downstreams top-level cmake before including p4c. Or at least from cmake presets for the downstream.
That should be possible, similar to how bf-p4c works. The only requirement is that once we call FetchContent_MakeAvailable
for Boost all the requested modules need to be present. The graph module for the graphs back end is currently initialized like this.
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.
In that case it should work well. I was confused by "on commandline".
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.
Yeah both options are possible. You could also just set the required modules using cmake -DADDITIONAL_P4C_BOOST_LIBRARIES=assign;filesystem;graph;...
# Reset temporary variable modifications. | ||
set(CMAKE_UNITY_BUILD ${CMAKE_UNITY_BUILD_PREV}) | ||
set(FETCHCONTENT_QUIET ${FETCHCONTENT_QUIET_PREV}) | ||
set(P4C_BOOST_LIBRARIES Boost::iostreams Boost::format Boost::multiprecision) |
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.
Looks like a duplication. The list of libraries should be specified once IMO :)
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.
This list describes the actual CMake targets which are used for includes/linking whereas the other list describes the various Boost modules to enable. Not sure whether there is a 1:1 correspondence between the two.
If yes, we could generate these using a variable like Boost::${Boost_Module}
for each list element.
171e459
to
a0d83ba
Compare
This might be a significant regression for downstream backends as it would require lots of patching of p4c cmake files. Adding some additional cmake options to build cmdline also looks a bit hacky to me – everything should be self-contained. Essentially, before the backend could just do Here, it looks like many things are hardcoded. In principle we can use in-tree |
I do not think there is any hardcoding going on, it just makes a couple implicit assumptions of the compiler build system explicit. For example, Where things are a problem is that the back ends can not really communicate their dependencies to the top-level FetchContent macro. At least I do not see an easy way to do that. Boost CMake targets are only visible after invoking One way this circular dependency could be resolved is to add a "BoostDeps.cmake" file to each extension, which is then picked up by this macro...
The original behavior is preserved with |
In light #4950 of I would like to push this forward. Any back end that does not want to use the FetchContent version can just toggle the system-provided version which will give them the same functionality as before. Fixing this problem will give us 1) C++20 2) more Ci stability as quite a few of the spurious failures are related to system-packages changing their boost version. |
…ded Boost. Signed-off-by: fruffy <[email protected]>
Signed-off-by: fruffy <[email protected]>
This PR sets up boost to be installed via FetchContent instead of depending on the system-provided version. Because a lot of Boost is header-only this is a little tricky.
Recent versions of boost have improved their CMake support significantly. I pushed a version which only requires downloading boost and linking the appropriate targets. The required boost headers are exported with each target, comparable to Abseil. To make sure that the linked headers are included as system headers I had to do some patching, but that is fairly straightforward.
If one desires to add additional boost targets, they can do so by setting P4C_TARGET_BOOST_LIBRARIES at command line or before invoking boost.
Dependencies
We currently depend on multiprecision and format as part of our core. iostreams for one particular optimization in the parser and graphs for the graphs backend.
graphs alone has an egregious amount of dependencies: https://github.com/boostorg/graph/blob/develop/CMakeLists.txt#L18
iostreams dependencies https://github.com/boostorg/iostreams/blob/develop/CMakeLists.txt#L79
format dependencies https://github.com/boostorg/format/blob/develop/CMakeLists.txt#L17
multiprecision dependencies https://github.com/boostorg/multiprecision/blob/develop/CMakeLists.txt#L30
The only project out of those that is currently standalone is multiprecision.
Because of this dependency problem we need to add almost all the different boost modules to the include path to make sure that we are including the local boost header first. We do this by globbing for theinclude
folder and adding it to the include path.