How do I Build Protocol Buffer from Source?

huangapple go评论70阅读模式
英文:

How do I Build Protocol Buffer from Source?

问题

你好!以下是重新编译 protoc 的步骤:

  1. 首先,确保你已经安装了 Go 编程语言。你可以从官方网站(https://golang.org)下载并按照指示安装。

  2. 克隆 protobuf-go 仓库到你的本地机器上。你可以使用以下命令在终端中执行克隆操作:

    git clone https://github.com/protocolbuffers/protobuf-go.git
    
  3. 进入克隆下来的 protobuf-go 目录:

    cd protobuf-go
    
  4. 在该目录下,执行以下命令来构建 protoc-gen-go 工具:

    go build google.golang.org/protobuf/cmd/protoc-gen-go
    

    这将生成一个名为 protoc-gen-go 的可执行文件。

  5. 将生成的 protoc-gen-go 可执行文件移动到你的 PATH 环境变量所指定的目录中,以便可以在任何位置使用 protoc 命令。你可以使用以下命令将其移动到 /usr/local/bin 目录:

    mv protoc-gen-go /usr/local/bin
    

    如果你的 PATH 环境变量指定了其他目录,请将可执行文件移动到相应的目录中。

现在,你已经成功重新编译了 protoc,并且可以在终端中使用 protoc 命令进行协议缓冲区的编译。希望这些步骤对你有帮助!如果你有任何其他问题,请随时提问。

英文:

I am trying to build a protocol buffer from the source code, but I could not do that. I am using Go and I would like to make some changes to the source code of the protocol buffer in Go and rebuild it again.

In the protocol buffer GitHub repository, there is a clear instruction to build protobuf binary in C++. Here is the link. In the same repository, there are no clear instructions on how to build protobuf in Go.
I used brew install protoc-gen-go to install the protoc on a mac machine. It works fine, but I have a plan to make some changes in protobuf-go.

So, I guess the question is how do I recompile protoc?
I appreciate your answer in the style of a step.

答案1

得分: 2

请参考Protocol Buffers文档中的Protocol Buffer Basics: Go

在安装了编译器和protoc-gen-go插件之后,运行以下命令来编译:

protoc -I=$SRC_DIR --go_out=$DST_DIR $SRC_DIR/addressbook.proto

$SRC_DIR 是你的应用程序代码所在的位置,$DST_DIR 是你希望生成的Go代码存放的位置。

英文:

See Protocol Buffer Basics: Go in the Protocol Buffers Documentation.

After you've installed the compiler and protoc-gen-go plugin, run the compiler...

protoc -I=$SRC_DIR --go_out=$DST_DIR $SRC_DIR/addressbook.proto

$SRC_DIR is where your application's code lives, and $DST_DIR is where you want the Go code generated from the .proto file to live.

答案2

得分: 0

你可以使用以下命令构建项目:

go test -mod=vendor -timeout=60m -count=1 integration_test.go -buildRelease

这段代码片段来自于release.bash文件。它使用Go的测试框架作为构建脚本。

英文:

You can build the project by using the following command:

go test -mod=vendor -timeout=60m -count=1 integration_test.go -buildRelease

This snippet is from release.bash. It uses Go's testing framework as a build script.

huangapple
  • 本文由 发表于 2023年3月21日 02:29:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75794034.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定