diff --git a/protobuf-codegen/src/lib.rs b/protobuf-codegen/src/lib.rs index 78d854563..fa022710a 100644 --- a/protobuf-codegen/src/lib.rs +++ b/protobuf-codegen/src/lib.rs @@ -170,6 +170,13 @@ fn gen_file( w.write_line(""); w.write_line(&format!("//! Generated file from `{}`", file.get_name())); + if customize.inside_protobuf != Some(true) { + w.write_line(""); + w.write_line("/// Generated files are compatible only with the same version"); + w.write_line("/// of protobuf runtime."); + w.write_line(&format!("const _PROTOBUF_VERSION_CHECK: () = {}::{};", + protobuf_crate_path(&customize), protobuf::VERSION_IDENT)); + } for message in &scope.get_messages() { // ignore map entries, because they are not used in map fields diff --git a/protobuf/src/lib.rs b/protobuf/src/lib.rs index f5ee9ab8d..0bb130118 100644 --- a/protobuf/src/lib.rs +++ b/protobuf/src/lib.rs @@ -85,5 +85,5 @@ pub const VERSION: &str = ""; /// This symbol is in generated `version.rs`, include here for IDE #[cfg(never)] #[doc(hidden)] -pub const VERSION_SYMBOL: &str = ""; +pub const VERSION_IDENT: &str = ""; include!(concat!(env!("OUT_DIR"), "/version.rs"));