Skip to content

Commit

Permalink
Generated files are now compatible only with the same version
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
stepancheg committed May 27, 2019
1 parent a4284ee commit 427e7ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions protobuf-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,18 @@ fn gen_file(
let mut w = CodeWriter::new(&mut v);

w.write_generated_by("rust-protobuf", env!("CARGO_PKG_VERSION"));
w.write_line(&format!("//! Generated file from `{}`", file.get_name()));

w.write_line("");
w.write_line("use protobuf::Message as Message_imported_for_functions;");
w.write_line("use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions;");
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
Expand Down
2 changes: 1 addition & 1 deletion protobuf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,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"));

0 comments on commit 427e7ed

Please sign in to comment.