cmd/protoc-gen-go, runtime/protoimpl: enforce minimum and maximum versions
Generate the needed infrastructure to ensure that we can statically
enforce minimum and maximum versions. This enables us to have a policy
when we release v2 where it fails to build for:
* new generated code with really old runtimes
* new runtimes with really old generated code
Change-Id: Ib699ad62c06dff8f9285806394a741c18db00288
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/178546
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/testprotos/conformance/conformance.pb.go b/internal/testprotos/conformance/conformance.pb.go
index 200d5b0..a1ae3bf 100644
--- a/internal/testprotos/conformance/conformance.pb.go
+++ b/internal/testprotos/conformance/conformance.pb.go
@@ -11,7 +11,12 @@
sync "sync"
)
-const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+const (
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
+)
type WireFormat int32
diff --git a/internal/testprotos/conformance/test_messages_proto2.pb.go b/internal/testprotos/conformance/test_messages_proto2.pb.go
index c0f5d52..661b0dc 100644
--- a/internal/testprotos/conformance/test_messages_proto2.pb.go
+++ b/internal/testprotos/conformance/test_messages_proto2.pb.go
@@ -11,7 +11,12 @@
sync "sync"
)
-const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+const (
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
+)
type ForeignEnumProto2 int32
diff --git a/internal/testprotos/conformance/test_messages_proto3.pb.go b/internal/testprotos/conformance/test_messages_proto3.pb.go
index b63c506..52ae7d3 100644
--- a/internal/testprotos/conformance/test_messages_proto3.pb.go
+++ b/internal/testprotos/conformance/test_messages_proto3.pb.go
@@ -17,7 +17,12 @@
sync "sync"
)
-const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+const (
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
+)
type ForeignEnum int32
diff --git a/internal/testprotos/legacy/legacy.pb.go b/internal/testprotos/legacy/legacy.pb.go
index 24b8853..f867906 100644
--- a/internal/testprotos/legacy/legacy.pb.go
+++ b/internal/testprotos/legacy/legacy.pb.go
@@ -23,7 +23,12 @@
sync "sync"
)
-const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+const (
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
+)
type Legacy struct {
F1 *proto2_v0_0.Message `protobuf:"bytes,1,opt,name=f1,proto3" json:"f1,omitempty"`
diff --git a/internal/testprotos/test/ext.pb.go b/internal/testprotos/test/ext.pb.go
index 9f6915d..58cb656 100644
--- a/internal/testprotos/test/ext.pb.go
+++ b/internal/testprotos/test/ext.pb.go
@@ -11,7 +11,12 @@
sync "sync"
)
-const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+const (
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
+)
var file_test_ext_proto_extDescs = []protoiface.ExtensionDescV1{
{
diff --git a/internal/testprotos/test/test.pb.go b/internal/testprotos/test/test.pb.go
index cbf1c48..86c69ed 100644
--- a/internal/testprotos/test/test.pb.go
+++ b/internal/testprotos/test/test.pb.go
@@ -12,7 +12,12 @@
sync "sync"
)
-const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+const (
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
+)
type ForeignEnum int32
diff --git a/internal/testprotos/test/test_import.pb.go b/internal/testprotos/test/test_import.pb.go
index 6bbafe9..2288939 100644
--- a/internal/testprotos/test/test_import.pb.go
+++ b/internal/testprotos/test/test_import.pb.go
@@ -11,7 +11,12 @@
sync "sync"
)
-const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+const (
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
+)
type ImportEnum int32
diff --git a/internal/testprotos/test/test_public.pb.go b/internal/testprotos/test/test_public.pb.go
index 050bf76..832e324 100644
--- a/internal/testprotos/test/test_public.pb.go
+++ b/internal/testprotos/test/test_public.pb.go
@@ -11,7 +11,12 @@
sync "sync"
)
-const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+const (
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
+)
type PublicImportMessage struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
diff --git a/internal/testprotos/test/weak/test_weak.pb.go b/internal/testprotos/test/weak/test_weak.pb.go
index 187848d..ba5b8df 100644
--- a/internal/testprotos/test/weak/test_weak.pb.go
+++ b/internal/testprotos/test/weak/test_weak.pb.go
@@ -11,7 +11,12 @@
sync "sync"
)
-const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+const (
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
+)
type WeakImportMessage struct {
A *int32 `protobuf:"varint,1,opt,name=a" json:"a,omitempty"`
diff --git a/internal/testprotos/test3/test.pb.go b/internal/testprotos/test3/test.pb.go
index 88f664f..fc3df02 100644
--- a/internal/testprotos/test3/test.pb.go
+++ b/internal/testprotos/test3/test.pb.go
@@ -11,7 +11,12 @@
sync "sync"
)
-const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+const (
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
+)
type ForeignEnum int32
diff --git a/internal/testprotos/test3/test_import.pb.go b/internal/testprotos/test3/test_import.pb.go
index c36e2be..558b8b6 100644
--- a/internal/testprotos/test3/test_import.pb.go
+++ b/internal/testprotos/test3/test_import.pb.go
@@ -11,7 +11,12 @@
sync "sync"
)
-const _ = protoimpl.EnforceVersion(protoimpl.Version - 0)
+const (
+ // Verify that runtime/protoimpl is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
+ // Verify that this generated code is sufficiently up-to-date.
+ _ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
+)
type ImportEnum int32