Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Batch file that creates the appropriate C++ code from a .proto file
@echo off
echo Generating API files...
:VARIABLES_DEFINITIONS
set PROTO_FILENAME=api
set SCRIPT_FOLDER=%cd%
set GRPC_BIN_ROOT=%SCRIPT_FOLDER%\bin
set OUTPUT_DIRECTORY=%SCRIPT_FOLDER%\api_cpp
:CHECK_GRPC_BINARIES
IF "%GRPC_BIN_ROOT%" == "" (echo "Could not find the gRPC binaries" && GOTO ABORT)
:CREATE_OUTPUT_DIRECTORY
IF EXIST %OUTPUT_DIRECTORY% (rd /s /q %OUTPUT_DIRECTORY%)
md %OUTPUT_DIRECTORY%
:CREATE_API
call %GRPC_BIN_ROOT%\protoc --proto_path=%SCRIPT_FOLDER% --grpc_out=%OUTPUT_DIRECTORY% --plugin=protoc-gen-grpc=%GRPC_BIN_ROOT%/grpc_cpp_plugin.exe %PROTO_FILENAME%.proto
call %GRPC_BIN_ROOT%\protoc --proto_path=%SCRIPT_FOLDER% --cpp_out=%OUTPUT_DIRECTORY% %PROTO_FILENAME%.proto
REM SUCCESS!
GOTO GRACEFULEXIT
:ABORT
pause
echo Aborted...
:GRACEFULEXIT
echo API creation done!
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment