Skip to content
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

Aggressively clean up the Protobuf CMake dependency. #4543

Merged
merged 1 commit into from
May 21, 2024

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Mar 16, 2024

Now that we are mandating Protobuf 3.25 try to simplify the use of extra variables and workarounds for our Protobuf dependency.

  • Use protobuf_generate instead our own custom command. This way we can rely on the canonical definitions instead of having to maintain our own generators.
  • Do not use ${Protobuf_LIBRARY}, instead use the aliased versions protobuf::
  • Do not use PROTOBUF_PROTOC_INCLUDES, instead use Protobuf_INCLUDE_DIRS only.
  • Also clean up some unnecessary include directories in the top-level CMakeLists. Try to simplify things.

With CMake 3.24 we may also be able to override find_package with FetchContent: https://cmake.org/cmake/help/latest/module/FetchContent.html

Fixes #4477.

@fruffy fruffy force-pushed the fruffy/protobuf_cleanup branch 3 times, most recently from 5b54ad8 to 805b683 Compare March 23, 2024 22:27
@fruffy fruffy changed the title [WiP] Aggressively clean up the Protobuf CMake dependency. Aggressively clean up the Protobuf CMake dependency. Mar 24, 2024
@fruffy
Copy link
Collaborator Author

fruffy commented Mar 24, 2024

@jkhsjdhjs We are trying to refresh our Protobuf dependency and simplify it but I know you had some trouble with setting the right variables in Arch Protobuf. If we mandate a recent version do these build settings work for you? Or do we still need to keep the compatibility variables?

@fruffy fruffy marked this pull request as ready for review March 24, 2024 16:33
@fruffy fruffy added run-ubuntu18 Use this tag to trigger a Ubuntu-18 CI run. run-sanitizer Use this tag to run a Clang+Sanitzers CI run. labels Mar 24, 2024
@jkhsjdhjs
Copy link
Contributor

@fruffy Yep, it doesn't build for me with the changes of this PR:

CMake Error at cmake/Protobuf.cmake:14 (find_package):
  Could not find a configuration file for package "Protobuf" that is
  compatible with requested version "25.3".

  The following configuration files were considered but not accepted:

    /usr/lib/cmake/protobuf/protobuf-config.cmake, version: 25.3.0
    /lib/cmake/protobuf/protobuf-config.cmake, version: 25.3.0

Call Stack (most recent call first):
  CMakeLists.txt:185 (p4c_obtain_protobuf)

It works if I remove the 25.3 from the find_package() call.

However, I then get these errors:

CMake Error at control-plane/CMakeLists.txt:53 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:protoc>

  No target "protoc"


CMake Error at backends/dpdk/CMakeLists.txt:29 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:protoc>

  No target "protoc"


CMake Error at control-plane/CMakeLists.txt:53 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:protoc>

  No target "protoc"


CMake Error at backends/dpdk/CMakeLists.txt:29 (add_custom_command):
  Error evaluating generator expression:

    $<TARGET_FILE:protoc>

  No target "protoc"

@fruffy
Copy link
Collaborator Author

fruffy commented Mar 25, 2024

Thanks for checking this! Maybe using 25.3.0 as the required version works? Or just not using CONFIG. There is some reason why that particular build is considered but not accepted...

@jkhsjdhjs
Copy link
Contributor

Not using CONFIG doesn't work due to cmake's find_protobuf still not being compatible with recent protobuf versions:

CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Protobuf: Found unsuitable version "4.25.3", but required is
  at least "25.3" (found /usr/lib/libprotobuf.so)
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:598 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake/Modules/FindProtobuf.cmake:749 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  cmake/Protobuf.cmake:14 (find_package)
  CMakeLists.txt:185 (p4c_obtain_protobuf)

Using 25.3.0 with CONFIG works, but I suggest not requiring a specific version here, as with P4C_USE_PREINSTALLED_PROTOBUF you'll want to use whatever version is available. Requiring a minimum version doesn't seem to work, maybe due to https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-version-selection

@fruffy fruffy marked this pull request as draft March 25, 2024 21:18
@fruffy fruffy force-pushed the fruffy/protobuf_cleanup branch 14 times, most recently from 0909166 to 2ad6ebe Compare April 1, 2024 20:09
@fruffy fruffy marked this pull request as ready for review April 4, 2024 18:50
@fruffy
Copy link
Collaborator Author

fruffy commented Apr 4, 2024

@jkhsjdhjs I tested this locally and on MacOS, and I believe things should now work. Took me a lot of trial and error.

@fruffy fruffy requested review from vlstill and asl and removed request for vlstill April 4, 2024 18:51
@fruffy fruffy force-pushed the fruffy/protobuf_cleanup branch 2 times, most recently from 759b06d to 112546d Compare April 4, 2024 19:05
Copy link
Contributor

@jkhsjdhjs jkhsjdhjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a lot of trial and error.

Yes, I can see that :D

fruffy force-pushed a lot

I just tested a build with the changes on latest Arch Linux using system protobuf and abseil and it works fine. LGTM 👍

@fruffy
Copy link
Collaborator Author

fruffy commented Apr 4, 2024

Took me a lot of trial and error.

Yes, I can see that :D

fruffy force-pushed a lot

I just tested a build with the changes on latest Arch Linux using system protobuf and abseil and it works fine. LGTM 👍

Great! Yeah, a lot of this was me banging my head against the wall trying to figure out why the MacOS build can not find Protobuf. Only to realize that it requires path hints.

Copy link
Contributor

@vlstill vlstill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two things I've noticed. (I got little lost in all the changes so I did not fully review it, but it looks reasonable overall).

README.md Outdated Show resolved Hide resolved
cmake/Protobuf.cmake Outdated Show resolved Hide resolved
@fruffy fruffy force-pushed the fruffy/protobuf_cleanup branch 4 times, most recently from 8b4d5e5 to 0fb6e74 Compare April 5, 2024 19:20
@fruffy fruffy requested a review from vlstill April 5, 2024 19:21
@fruffy fruffy force-pushed the fruffy/protobuf_cleanup branch 2 times, most recently from 91e1a5f to d78d418 Compare May 14, 2024 14:15
Copy link
Contributor

@vlstill vlstill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am no familiar with protobuf and how it should be used in CMake. Nor am I familiar with the P4C control plane. But I don't see any problems with the code.

@fruffy
Copy link
Collaborator Author

fruffy commented May 21, 2024

I am no familiar with protobuf and how it should be used in CMake. Nor am I familiar with the P4C control plane. But I don't see any problems with the code.

fwiw I have been testing this PR in downstream dependencies for months now.

@fruffy fruffy added this pull request to the merge queue May 21, 2024
Merged via the queue into main with commit 5b9c0cc May 21, 2024
17 checks passed
@fruffy fruffy deleted the fruffy/protobuf_cleanup branch May 21, 2024 14:02
@fruffy fruffy added the infrastructure Topics related to code style and build and test infrastructure. label Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Topics related to code style and build and test infrastructure. run-sanitizer Use this tag to run a Clang+Sanitzers CI run. run-ubuntu18 Use this tag to trigger a Ubuntu-18 CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revisit Protobuf include directory policy
3 participants