Skip to content

cmake: add build for the rpc directory#87

Merged
dallison merged 3 commits into
mainfrom
rpc-cmake-build
Jun 10, 2026
Merged

cmake: add build for the rpc directory#87
dallison merged 3 commits into
mainfrom
rpc-cmake-build

Conversation

@dallison

Copy link
Copy Markdown
Owner

Summary

  • The //rpc tree only had a Bazel build; this adds a parallel CMake build (rpc/CMakeLists.txt) and wires it into the top-level CMakeLists.txt via add_subdirectory(rpc).
  • Builds the subspace_rpc protoc plugin (the IDL compiler), generates the protobuf C++ code and the subspace RPC client/server stubs from rpc/proto/rpc_test.proto, and defines the rpc_common/rpc_server/rpc_client libraries, the generated-stub libraries, the tests (rpc_client_test, rpc_server_test, rpc_test), and the example binaries.
  • Generated files are emitted under ${CMAKE_BINARY_DIR}/rpc/proto so the existing include paths (e.g. rpc/proto/rpc_test.subspace.rpc_client.h) 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.

Test plan

  • cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug configures.
  • cmake --build build builds the plugin, codegen, libraries, tests, and example binaries.
  • Codegen emits the expected .pb.{cc,h} and .subspace.rpc_{client,server}.{cc,h} files.
  • ctest -R "rpc_test|rpc_client_test|rpc_server_test" passes (3/3).

dallison added 3 commits June 10, 2026 09:49
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.
@dallison dallison merged commit 3e02bbf into main Jun 10, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant