cmake: add build for the rpc directory#87
Merged
Merged
Conversation
The //rpc tree only had a Bazel build. Add a CMake build that mirrors it:
build the subspace_rpc protoc plugin (the IDL compiler), generate the
protobuf C++ code and the subspace RPC client/server stubs from
rpc/proto/rpc_test.proto, and define the rpc_common/rpc_server/rpc_client
libraries, the generated-stub libraries, the tests, and the example
binaries.
Generated files are emitted under ${CMAKE_BINARY_DIR}/rpc/proto so the
existing include paths resolve via the project-wide include directories.
Native builds use the freshly built plugin; cross-compiles fall back to a
host protoc and a host plugin supplied via -DSUBSPACE_RPC_PLUGIN, mirroring
how proto/CMakeLists.txt handles a host protoc. Tests start the server
in-process via libserver like the other CMake tests.
The subspace_rpc plugin must run on the build host to generate the RPC stubs. When cross-compiling (e.g. the Android NDK build) a target-arch plugin can't run on the host, and the cmake-android CI doesn't supply one, so the previous FATAL_ERROR failed the configure. Skip the rpc tree gracefully in that case (it isn't part of the cross-compiled deliverables, matching the Bazel build which doesn't build //rpc for Android); a host plugin can still be supplied via -DSUBSPACE_RPC_PLUGIN to build it.
Add rpc/Android.bp mirroring the Bazel/CMake builds: the subspace_rpc host
plugin, the librpc_server/librpc_client runtime libraries, the generated
test-service proto and stub libraries, and the device tests/examples.
Verified by building the modules in an AOSP tree (aosp_arm64): the host
plugin links and all static libraries compile and archive; test/example
sources compile. This surfaced and fixed two issues:
* Soong rejects generated headers in `generated_sources`, so each codegen
genrule is split into a .cc-only rule (feeding generated_sources) and a
.h-only rule (feeding generated_headers).
* librpc_test_subspace_rpc transitively includes proto/subspace.pb.h via
client.h, so it must depend on libsubspace_proto.
Also add the missing absl/strings/str_cat.h include in service_gen.cc; the
plugin uses absl::StrCat but only got the declaration transitively under
Bazel/CMake, which the stricter AOSP host compile caught.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
//rpctree only had a Bazel build; this adds a parallel CMake build (rpc/CMakeLists.txt) and wires it into the top-levelCMakeLists.txtviaadd_subdirectory(rpc).subspace_rpcprotoc plugin (the IDL compiler), generates the protobuf C++ code and the subspace RPC client/server stubs fromrpc/proto/rpc_test.proto, and defines therpc_common/rpc_server/rpc_clientlibraries, the generated-stub libraries, the tests (rpc_client_test,rpc_server_test,rpc_test), and the example binaries.${CMAKE_BINARY_DIR}/rpc/protoso the existing include paths (e.g.rpc/proto/rpc_test.subspace.rpc_client.h) resolve via the project-wide include directories.protocand a host plugin supplied via-DSUBSPACE_RPC_PLUGIN, mirroring howproto/CMakeLists.txthandles a hostprotoc. Tests start the server in-process vialibserver, like the other CMake tests.Test plan
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debugconfigures.cmake --build buildbuilds the plugin, codegen, libraries, tests, and example binaries..pb.{cc,h}and.subspace.rpc_{client,server}.{cc,h}files.ctest -R "rpc_test|rpc_client_test|rpc_server_test"passes (3/3).