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

Add C++ proto files to the C++ SDK #2544

Merged
merged 20 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ jobs:
sudo apt-get update
sudo apt-get install -y clang-format cmake g++ clang-tidy cppcheck

- name: Check Formatting
- name: Check source Formatting
run: |
find src/cc/flwr -name '*.cc' -or -name '*.h' | xargs clang-format -i
find src/cc/flwr/src -name '*.cc' | xargs clang-format -i
git diff --exit-code

- name: Check header Formatting
run: |
find src/cc/flwr/include -name '*.h' -not -path "src/cc/flwr/include/flwr/*" | xargs clang-format -i
git diff --exit-code

- name: Build
Expand Down
131 changes: 7 additions & 124 deletions examples/quickstart-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ project(SimpleCppFlowerClient VERSION 0.10
DESCRIPTION "Creates a Simple C++ Flower client that trains a linear model on synthetic data."
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(ABSL_PROPAGATE_CXX_STD ON)

######################
### Download gRPC
Expand All @@ -27,143 +26,27 @@ else()
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:grpc_cpp_plugin>)
endif()


######################
### FLWR_GRPC_PROTO
get_filename_component(FLWR_PROTO_BASE_PATH "../../src/proto/" ABSOLUTE)
get_filename_component(FLWR_TRANS_PROTO "../../src/proto/flwr/proto/transport.proto" ABSOLUTE)
get_filename_component(FLWR_NODE_PROTO "../../src/proto/flwr/proto/node.proto" ABSOLUTE)
get_filename_component(FLWR_TASK_PROTO "../../src/proto/flwr/proto/task.proto" ABSOLUTE)
get_filename_component(FLWR_FLEET_PROTO "../../src/proto/flwr/proto/fleet.proto" ABSOLUTE)

set(FLWR_TRANS_PROTO_SRCS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/transport.pb.cc")
set(FLWR_TRANS_PROTO_HDRS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/transport.pb.h")
set(FLWR_TRANS_GRPC_SRCS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/transport.grpc.pb.cc")
set(FLWR_TRANS_GRPC_HDRS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/transport.grpc.pb.h")

set(FLWR_NODE_PROTO_SRCS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/node.pb.cc")
set(FLWR_NODE_PROTO_HDRS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/node.pb.h")
set(FLWR_NODE_GRPC_SRCS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/node.grpc.pb.cc")
set(FLWR_NODE_GRPC_HDRS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/node.grpc.pb.h")

set(FLWR_TASK_PROTO_SRCS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/task.pb.cc")
set(FLWR_TASK_PROTO_HDRS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/task.pb.h")
set(FLWR_TASK_GRPC_SRCS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/task.grpc.pb.cc")
set(FLWR_TASK_GRPC_HDRS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/task.grpc.pb.h")

set(FLWR_FLEET_PROTO_SRCS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/fleet.pb.cc")
set(FLWR_FLEET_PROTO_HDRS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/fleet.pb.h")
set(FLWR_FLEET_GRPC_SRCS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/fleet.grpc.pb.cc")
set(FLWR_FLEET_GRPC_HDRS "${CMAKE_CURRENT_BINARY_DIR}/flwr/proto/fleet.grpc.pb.h")

# External building command to generate gRPC source files.
add_custom_command(
OUTPUT "${FLWR_TRANS_PROTO_SRCS}"
"${FLWR_TRANS_PROTO_HDRS}"
"${FLWR_TRANS_GRPC_SRCS}"
"${FLWR_TRANS_GRPC_HDRS}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${FLWR_PROTO_BASE_PATH}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${FLWR_TRANS_PROTO}"
DEPENDS "${FLWR_TRANS_PROTO}"
)

add_custom_command(
OUTPUT
"${FLWR_NODE_PROTO_SRCS}"
"${FLWR_NODE_PROTO_HDRS}"
"${FLWR_NODE_GRPC_SRCS}"
"${FLWR_NODE_GRPC_HDRS}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${FLWR_PROTO_BASE_PATH}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${FLWR_NODE_PROTO}"
DEPENDS
"${FLWR_NODE_PROTO}"
)

add_custom_command(
OUTPUT
"${FLWR_TASK_PROTO_SRCS}"
"${FLWR_TASK_PROTO_HDRS}"
"${FLWR_TASK_GRPC_SRCS}"
"${FLWR_TASK_GRPC_HDRS}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${FLWR_PROTO_BASE_PATH}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${FLWR_TASK_PROTO}"
DEPENDS
"${FLWR_TASK_PROTO}"
)

add_custom_command(
OUTPUT
"${FLWR_FLEET_PROTO_SRCS}"
"${FLWR_FLEET_PROTO_HDRS}"
"${FLWR_FLEET_GRPC_SRCS}"
"${FLWR_FLEET_GRPC_HDRS}"
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
-I "${FLWR_PROTO_BASE_PATH}"
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
"${FLWR_FLEET_PROTO}"
DEPENDS
"${FLWR_FLEET_PROTO}"
)
### FLWR_LIB

add_library(flwr_grpc_proto STATIC
${FLWR_TRANS_GRPC_SRCS}
${FLWR_TRANS_GRPC_HDRS}
${FLWR_TRANS_PROTO_SRCS}
${FLWR_TRANS_PROTO_HDRS}
${FLWR_NODE_GRPC_SRCS}
${FLWR_NODE_GRPC_HDRS}
${FLWR_NODE_PROTO_SRCS}
${FLWR_NODE_PROTO_HDRS}
${FLWR_TASK_GRPC_SRCS}
${FLWR_TASK_GRPC_HDRS}
${FLWR_TASK_PROTO_SRCS}
${FLWR_TASK_PROTO_HDRS}
${FLWR_FLEET_GRPC_SRCS}
${FLWR_FLEET_GRPC_HDRS}
${FLWR_FLEET_PROTO_SRCS}
${FLWR_FLEET_PROTO_HDRS}
)
set(FLWR_SDK_PATH "../../src/cc/flwr")

file(GLOB FLWR_SRCS "${FLWR_SDK_PATH}/src/*.cc")
file(GLOB FLWR_PROTO_SRCS "${FLWR_SDK_PATH}/include/flwr/proto/*.cc")
set(FLWR_INCLUDE_DIR "${FLWR_SDK_PATH}/include")

target_include_directories(flwr_grpc_proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
add_library(flwr ${FLWR_SRCS} ${FLWR_PROTO_SRCS})

target_link_libraries(flwr_grpc_proto
target_link_libraries(flwr
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF}
)

######################
### FLWR_LIB

file(GLOB FLWR_SRCS "../../src/cc/flwr/src/*.cc")
set(FLWR_INCLUDE_DIR "../../src/cc/flwr/include")

add_library(flwr ${FLWR_SRCS})

target_include_directories(flwr PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
${FLWR_INCLUDE_DIR}
)

target_link_libraries(flwr
flwr_grpc_proto
)

######################
### FLWR_CLIENT
file(GLOB FLWR_CLIENT_SRCS src/*.cc)
Expand Down
Loading