File tree Expand file tree Collapse file tree 5 files changed +17
-6
lines changed
Expand file tree Collapse file tree 5 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ CARGO_HOME=$CARGO_HOME cargo test --lib --bins --tests
6868CARGO_HOME=$CARGO_HOME cargo publish --dry-run
6969
7070cd $EXAMPLE_ROOT
71- CARGO_HOME=$CARGO_HOME cargo test
71+ CARGO_HOME=$CARGO_HOME cargo test --features run-protobuf-codegen
7272# TODO: Cannot enable this dry-run yet because it checks that the versions of
7373# its dependencies are published on crates.io, which they are definitely not
7474# in this case.
Original file line number Diff line number Diff line change @@ -64,8 +64,7 @@ impl CodeGen {
6464 self
6565 }
6666
67- /// Generate Rust, upb, and upb minitables. Build and link the C code.
68- pub fn compile ( & self ) -> Result < ( ) , String > {
67+ pub fn generate_and_compile ( & self ) -> Result < ( ) , String > {
6968 let libupb_version = std:: env:: var ( "DEP_LIBUPB_VERSION" ) . expect ( "DEP_LIBUPB_VERSION should have been set, make sure that the Protobuf crate is a dependency" ) ;
7069 if VERSION != libupb_version {
7170 panic ! (
@@ -112,7 +111,11 @@ impl CodeGen {
112111 println ! ( "{}" , std:: str :: from_utf8( & output. stdout) . unwrap( ) ) ;
113112 eprintln ! ( "{}" , std:: str :: from_utf8( & output. stderr) . unwrap( ) ) ;
114113 assert ! ( output. status. success( ) ) ;
114+ self . compile_only ( )
115+ }
115116
117+ /// Builds and links the C code.
118+ pub fn compile_only ( & self ) -> Result < ( ) , String > {
116119 let mut cc_build = cc:: Build :: new ( ) ;
117120 cc_build
118121 . include (
Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ edition = "2021"
55description = " Example use of Rust Protocol Buffers bindings"
66license = " BSD-3-Clause"
77
8+ [features ]
9+ run-protobuf-codegen = []
10+
811[dependencies ]
912protobuf = { version = " {VERSION}" , path = " ../protobuf" , package = " staging-protobuf" }
1013
Original file line number Diff line number Diff line change @@ -3,5 +3,9 @@ use protobuf_codegen::CodeGen;
33fn main ( ) {
44 let mut codegen = CodeGen :: new ( ) ;
55 codegen. inputs ( [ "foo.proto" , "bar/bar.proto" ] ) . include ( "proto" ) ;
6- codegen. compile ( ) . unwrap ( ) ;
6+ if std:: env:: var ( "CARGO_FEATURE_RUN_PROTOBUF_CODEGEN" ) . is_ok ( ) {
7+ codegen. generate_and_compile ( ) . unwrap ( ) ;
8+ } else {
9+ codegen. compile_only ( ) . unwrap ( ) ;
10+ }
711}
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ CARGO_HOME=$CARGO_HOME CARGO_REGISTRY_TOKEN=$AUTH_TOKEN cargo publish
6464
6565# The example crate cannot be published due to it having a build.rs that
6666# modifies files outside of the OUT_DIR.
67- # cd $EXAMPLE_ROOT
68- # CARGO_HOME=$CARGO_HOME CARGO_REGISTRY_TOKEN=$AUTH_TOKEN cargo publish
67+ cd $EXAMPLE_ROOT
68+ CARGO_HOME=$CARGO_HOME cargo build --features run-protobuf-codegen
69+ CARGO_HOME=$CARGO_HOME CARGO_REGISTRY_TOKEN=$AUTH_TOKEN cargo publish
6970
You can’t perform that action at this time.
0 commit comments