-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[protobuf][protoc][grpc] Better support when cross compiling #26621
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
This file was deleted.
Oops, something went wrong.
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
39 changes: 39 additions & 0 deletions
39
ports/offscale-libetcd-cpp/fix-crosscompile-protobuf-grpc.patch
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
| index 62ae7c4..45a4175 100644 | ||
| --- a/CMakeLists.txt | ||
| +++ b/CMakeLists.txt | ||
| @@ -4,8 +4,9 @@ project(libetcd-cpp VERSION 0.0.1) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 17) | ||
|
|
||
| -find_package(gRPC REQUIRED) | ||
| -find_package(protobuf REQUIRED) | ||
| +find_package(gRPC CONFIG REQUIRED) | ||
| +find_package(Protobuf CONFIG REQUIRED) | ||
| +find_program(gRPC_CPP_PLUGIN grpc_cpp_plugin REQUIRED) | ||
|
|
||
| file(GLOB_RECURSE protos LIST_DIRECTORIES false "proto/*.proto") | ||
| file(GLOB main_proto LIST_DIRECTORIES false "proto/rpc.proto") | ||
| @@ -28,17 +29,17 @@ endforeach() | ||
|
|
||
| add_custom_command( | ||
| OUTPUT ${rpc_protofiles} | ||
| - COMMAND protobuf::protoc | ||
| - ARGS --grpc_out=${generated_path} -I ${protodir_path} --plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin> ${main_proto} | ||
| - DEPENDS gRPC::grpc_cpp_plugin protobuf::protoc ${main_proto} | ||
| + COMMAND "${Protobuf_PROTOC_EXECUTABLE}" | ||
| + ARGS --grpc_out=${generated_path} -I ${protodir_path} "--plugin=protoc-gen-grpc=${gRPC_CPP_PLUGIN}" ${main_proto} | ||
| + DEPENDS ${main_proto} | ||
| COMMENT "Running grpc protocol buffer compiler on ${main_proto}" | ||
| VERBATIM ) | ||
|
|
||
| add_custom_command( | ||
| OUTPUT ${common_protofiles} | ||
| - COMMAND protobuf::protoc | ||
| + COMMAND "${Protobuf_PROTOC_EXECUTABLE}" | ||
| ARGS --cpp_out=${generated_path} -I ${protodir_path} ${protos} | ||
| - DEPENDS ${protos} protobuf::protoc | ||
| + DEPENDS ${protos} | ||
| COMMENT "Running cpp protocol buffer compiler on ${protos}" | ||
| VERBATIM ) | ||
|
|
||
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
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
29 changes: 29 additions & 0 deletions
29
ports/protobuf/fix-crosscompile-protoc-generate-cmake-config.patch
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| diff --git a/cmake/protobuf-config.cmake.in b/cmake/protobuf-config.cmake.in | ||
| index 61669118c..5e32d4ecb 100644 | ||
| --- a/cmake/protobuf-config.cmake.in | ||
| +++ b/cmake/protobuf-config.cmake.in | ||
| @@ -7,6 +7,12 @@ include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake") | ||
| # Imported targets | ||
| include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake") | ||
|
|
||
| +set(_protobuf_generate_compiler protobuf::protoc) | ||
| +if(CMAKE_CROSSCOMPILING) | ||
| + find_program(Protobuf_PROTOC_EXECUTABLE protoc DOC "Host protobuf compiler path") | ||
| + set(_protobuf_generate_compiler "${Protobuf_PROTOC_EXECUTABLE}") | ||
| +endif() | ||
| + | ||
| function(protobuf_generate) | ||
| include(CMakeParseArguments) | ||
|
|
||
| @@ -146,9 +152,9 @@ function(protobuf_generate) | ||
|
|
||
| add_custom_command( | ||
| OUTPUT ${_generated_srcs} | ||
| - COMMAND protobuf::protoc | ||
| + COMMAND "${_protobuf_generate_compiler}" | ||
| ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_plugin_options}:${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file} | ||
| - DEPENDS ${_abs_file} protobuf::protoc | ||
| + DEPENDS ${_abs_file} "${_protobuf_generate_compiler}" | ||
| COMMENT ${_comment} | ||
| VERBATIM ) | ||
| endforeach() |
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.
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 we not simply fix the target
protobuf::protocfor crosscompiling instead of patching everyone 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.
Good question. I'm unsure of the best solution, and I'm still trying to wrap my head around CMake cross compilation best practices and what vcpkg is doing.
I was under the impression that it's probably best to expect that any exported targets from a
find_packagecall are all the same architecture, OS, etc... However, as I keep investigating all of this, I wonder how useful an exported executable target is if it needs to be replaced or goes unused during cross compilation. It seems like a cross-compilation-compatible solution would either:find_programto find all host executables that will be run during the build*_DIRpath to the host config file or (after much testing) rely onfind_packagewithNO_CMAKE_PATH,NO_CMAKE_FIND_ROOT_PATH, andHINTS ${CMAKE_SYSTEM_PREFIX_PATH}options to search only the host directories,1 i.e.,I believe what you're describing is attempted with these lines
vcpkg/ports/protobuf/vcpkg-cmake-wrapper.cmake
Line 14 in 1eb4c7f
vcpkg/ports/protobuf/protobuf-targets-vcpkg-protoc.cmake
Lines 4 to 8 in 1eb4c7f
I've removed these files in my PR, but I should investigate this again as you suggest. However, these files, being only in vcpkg, would hide downstream projects' issues if they tried to cross compile outside of vcpkg without also fixing the target. What I mean is that I think there is room for a patch in upstream protobuf for better cross compilation support, and I'm wondering what a good solution is and want to test it here.
Footnotes
Vcpkg currently doesn't touch
CMAKE_SYSTEM_PREFIX_PATH, so we'd want to add the path to the host triplet installation root. I've done very light testing locally by adding the following toscripts/buildsystem/vcpkg.cmake: ↩