简体   繁体   English

混合和匹配 protoc 和 protoc-gen-go 版本

[英]Mixing and matching protoc and protoc-gen-go versions

go protobuf generated code reports (elided): go protobuf 生成的代码报告(省略):

// protoc-gen-go v1.25.0
// protoc.       v3.5.1

import "github.com/golang/protobuf/..."
import "google.golang.org/protobuf/..."

resulting in a go.mod which references two protobuf's:导致go.mod引用两个 protobuf:

require(
    github.com/golang/protobuf v1.4.3
    google.golang.org/protobuf v1.25.0
)

Is that kosher?那是犹太洁食吗? I mean it seems to work but it's like twice the code.我的意思是它似乎有效,但它就像代码的两倍。

The root cause, I believe, of this gunk is sysadmin issues (incomplete and incompatible install of protobuf generator utils) plus the fact Google couldn't just stay on one URL.我相信,这种垃圾的根本原因是系统管理员问题(protobuf 生成器实用程序的安装不完整且不兼容)以及 Google 不能只停留在一个 URL 的事实。

github.com/golang/protobuf is imported in the generated code to allow the following to be included:在生成的代码中导入github.com/golang/protobuf以允许包含以下内容:

// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4

There are further details in this issue - quoting dsnet:此问题中有更多详细信息 - 引用 dsnet:

The only reason the newly generated.pb.go files depend on the deprecated proto package is to enforce a weak dependency on a sufficiently new version of the legacy package.新生成的.pb.go 文件依赖于弃用的原型 package 的唯一原因是对旧版 ZEFE90A8E604A7C840E88D03A67F 的足够新版本实施弱依赖。 This is necessary because not everyone is using Go modules such that the Go toolchain would enforce this dependency constraint.这是必要的,因为不是每个人都在使用 Go 模块,因此 Go 工具链将强制执行此依赖关系约束。 I wasn't fond of adding it, but I think it's probably necessary to keep at least for a few months.我不喜欢添加它,但我认为至少保留几个月可能是必要的。

As per the comments on this issue the dependency should be removed in version 1.26 (when released).根据对此问题的评论,应在版本1.26 (发布时)中删除依赖项。

(found this duplicate question after answering but as I have included more detail in this answer than I did in the previous one I will leave it up) 回答后发现了这个重复的问题,但由于我在这个答案中包含的细节比我在前一个中所做的更多,所以我将保留它)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM