【Mac】grpc_cliをインストールする

未分類

この記事ではgrpc_cliをインストールする手順を紹介します。

スポンサーリンク

grpc_cliのインストール

当初brewを使ってgrpc_cliをインストールしようとしたのですが、grpc_cliがつくられなかったため、grpcのリポジトリをコンパイルしてgrpc_cliのバイナリを生成することにしました。

grpcリポジトリのドキュメントに手順が記載されているので、その内容にしたがって進めていきます。
https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md

まずはgrpcのリポジトリをcloneします。

$ git clone git@github.com:grpc/grpc.git

cloneしたディレクトリに移動して、submodule updateを実行します。

$ cd grpc
$ git submodule update --init

ビルド用のディレクトリを作成し、つづいてcmakeとmakeを実行して、grpc_cliをビルドします。

// cmakeがインストールされていない場合、brewを使用してcmakeをインストール
$ brew install cmake

$ mkdir -p cmake/build
$ cd cmake/build
$ cmake -DgRPC_BUILD_TESTS=ON ../..
$ make grpc_cli

ビルドしたgrpc_cliをPATHが通っているディレクトリに移動します。

$ sudo mv ./grpc_cli /usr/local/bin

最後にgrpc_cliが実行できることを確認します。

$ grpc_cli
No command specified
  grpc_cli ls ...         ; List services
  grpc_cli call ...       ; Call method
  grpc_cli type ...       ; Print type
  grpc_cli parse ...      ; Parse message
  grpc_cli totext ...     ; Convert binary message to text
  grpc_cli tojson ...     ; Convert binary message to json
  grpc_cli tobinary ...   ; Convert text message to binary
  grpc_cli help ...       ; Print this message, or per-command usage
$ grpc_cli ls localhost:9090
grpc.reflection.v1alpha.ServerReflection
helloworld.Greeter