diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 815f9dd5d..e6d723229 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 }}' @@ -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 }}' diff --git a/.gitignore b/.gitignore index c4d5f824e..28e2c2d8f 100644 --- a/.gitignore +++ b/.gitignore @@ -446,3 +446,4 @@ install source/MaaRpc/generated/*.h source/MaaRpc/generated/*.cc +source/MaaRpc/generated/*.timestamp diff --git a/source/MaaRpc/CMakeLists.txt b/source/MaaRpc/CMakeLists.txt index 3c4e925de..37d2d9463 100644 --- a/source/MaaRpc/CMakeLists.txt +++ b/source/MaaRpc/CMakeLists.txt @@ -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) diff --git a/source/MaaRpc/scripts/gen.cmake b/source/MaaRpc/scripts/gen.cmake new file mode 100644 index 000000000..74a08a607 --- /dev/null +++ b/source/MaaRpc/scripts/gen.cmake @@ -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 () diff --git a/update-proto.bat b/update-proto.bat deleted file mode 100644 index 3fe3bc93a..000000000 --- a/update-proto.bat +++ /dev/null @@ -1,13 +0,0 @@ -@echo off - -set PROTOC=.\MaaDeps\vcpkg\installed\x64-windows\tools\protobuf\protoc -set GRPC_PLUGIN=.\MaaDeps\vcpkg\installed\x64-windows\tools\grpc\grpc_cpp_plugin.exe - -set INDIR=.\include\Interface\proto -set OUTDIR=.\source\MaaRpc\generated - -for %%s in (%INDIR%\*.proto) do ( - echo PROCESSING %%s - %PROTOC% --proto_path=%INDIR% %%s --cpp_out=%OUTDIR% - %PROTOC% --proto_path=%INDIR% %%s --grpc_out=%OUTDIR% --plugin=protoc-gen-grpc=%GRPC_PLUGIN% -) diff --git a/update-proto.sh b/update-proto.sh deleted file mode 100755 index 9240cecee..000000000 --- a/update-proto.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -if [ `uname` = Darwin ]; then - TRIPLET="x64-osx"; -else - TRIPLET="x64-linux"; -fi - -PROTOC="./MaaDeps/vcpkg/installed/${TRIPLET}/tools/protobuf/protoc" -GRPC_PLUGIN="./MaaDeps/vcpkg/installed/${TRIPLET}/tools/grpc/grpc_cpp_plugin" - -INDIR="./include/Interface/proto" -OUTDIR="./source/MaaRpc/generated" - -for src in ${INDIR}/*.proto; do - echo "PROCESSING ${src}" - ${PROTOC} --proto_path=${INDIR} "${src}" --cpp_out=${OUTDIR} - ${PROTOC} --proto_path=${INDIR} "${src}" --grpc_out=${OUTDIR} --plugin=protoc-gen-grpc=${GRPC_PLUGIN} -done