Skip to content

Commit

Permalink
feat: generate proto in cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Oct 8, 2023
1 parent 033fd12 commit 802eeff
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 35 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ jobs:
- name: Build MAA
run: |
cmd /C update-proto.bat
cmake --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }}" -DMAADEPS_TRIPLET="maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-windows" -DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}'
cmake --build build --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }} - Release" -j 16
Expand Down Expand Up @@ -181,7 +180,6 @@ jobs:
CC: ${{ matrix.arch == 'x86_64' && 'ccache gcc' || 'ccache aarch64-linux-gnu-gcc' }}
CXX: ${{ matrix.arch == 'x86_64' && 'ccache g++' || 'ccache aarch64-linux-gnu-g++' }}
run: |
./update-proto.sh
cmake --preset 'NinjaMulti' \
-DMAADEPS_TRIPLET='maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-linux' \
-DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}'
Expand Down Expand Up @@ -246,7 +244,6 @@ jobs:
CC: "/usr/local/opt/llvm/bin/clang"
CXX: "/usr/local/opt/llvm/bin/clang++"
run: |
./update-proto.sh
cmake --preset 'NinjaMulti' \
-DMAADEPS_TRIPLET='maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-osx' \
-DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,4 @@ install

source/MaaRpc/generated/*.h
source/MaaRpc/generated/*.cc
source/MaaRpc/generated/*.timestamp
2 changes: 2 additions & 0 deletions source/MaaRpc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include(scripts/gen.cmake)

file(GLOB maa_proto ../../include/Interface/proto/*.proto)
file(GLOB maa_proto_src generated/*.h generated/*.cc)
file(GLOB maa_rpc_src implement/*.h implement/*.cpp API/*.cpp)
Expand Down
24 changes: 24 additions & 0 deletions source/MaaRpc/scripts/gen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if (WIN32)
set(HOST_ARCH "x64-windows")
set(HOST_EXE_SUFFIX ".exe")
elseif (APPLE)
set(HOST_ARCH "x64-osx")
else ()
set(HOST_ARCH "x64-linux")
endif ()

set(PROTO_EXE ${CMAKE_SOURCE_DIR}/MaaDeps/vcpkg/installed/${HOST_ARCH}/tools/protobuf/protoc${HOST_EXE_SUFFIX})
set(PROTO_GRPC_EXE ${CMAKE_SOURCE_DIR}/MaaDeps/vcpkg/installed/${HOST_ARCH}/tools/grpc/grpc_cpp_plugin${HOST_EXE_SUFFIX})
set(PROTO_INDIR ${CMAKE_SOURCE_DIR}/include/Interface/proto)
set(PROTO_OUTDIR ${CMAKE_CURRENT_SOURCE_DIR}/generated)
file(GLOB maa_proto ${PROTO_INDIR}/*.proto)

foreach (src ${maa_proto})
string(REGEX REPLACE "^${PROTO_INDIR}" ${PROTO_OUTDIR} src_ts ${src})
if (${src} IS_NEWER_THAN ${src_ts}.timestamp)
message ("generate ${src}")
execute_process(COMMAND ${PROTO_EXE} "--proto_path=${PROTO_INDIR}" "--cpp_out=${PROTO_OUTDIR}" ${src})
execute_process(COMMAND ${PROTO_EXE} "--proto_path=${PROTO_INDIR}" "--grpc_out=${PROTO_OUTDIR}" "--plugin=protoc-gen-grpc=${PROTO_GRPC_EXE}" ${src})
file (TOUCH ${src_ts}.timestamp)
endif ()
endforeach ()
13 changes: 0 additions & 13 deletions update-proto.bat

This file was deleted.

19 changes: 0 additions & 19 deletions update-proto.sh

This file was deleted.

0 comments on commit 802eeff

Please sign in to comment.