Skip to content

Commit 2ab4d50

Browse files
committed
Generated files are now compatible only with the same version
I. e. if `protbuf-codegen=10.20.30` was used to generate `.rs` files, these files will be only compatible with `protobuf=10.20.30`.
1 parent 2162bb5 commit 2ab4d50

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

protobuf-codegen/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ fn gen_file(
170170

171171
w.write_line("");
172172
w.write_line(&format!("//! Generated file from `{}`", file.get_name()));
173+
if customize.inside_protobuf != Some(true) {
174+
w.write_line("");
175+
w.write_line("/// Generated files are compatible only with the same version");
176+
w.write_line("/// of protobuf runtime.");
177+
w.write_line(&format!("const _PROTOBUF_VERSION_CHECK: () = {}::{};",
178+
protobuf_crate_path(&customize), protobuf::VERSION_IDENT));
179+
}
173180

174181
for message in &scope.get_messages() {
175182
// ignore map entries, because they are not used in map fields

protobuf/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ pub const VERSION: &str = "";
8585
/// This symbol is in generated `version.rs`, include here for IDE
8686
#[cfg(never)]
8787
#[doc(hidden)]
88-
pub const VERSION_SYMBOL: &str = "";
88+
pub const VERSION_IDENT: &str = "";
8989
include!(concat!(env!("OUT_DIR"), "/version.rs"));

0 commit comments

Comments
 (0)