Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit cargo:rerun-if-changed directives automatically for protobuf builds #1926

Merged
merged 1 commit into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base_layer/core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn main() {
"src/base_node/proto",
"src/transactions/transaction_protocol/proto",
])
.emit_rerun_if_changed_directives()
.compile()
.unwrap();
}
1 change: 1 addition & 0 deletions base_layer/core/src/base_node/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#[cfg(feature = "base_node_proto")]
pub use crate::proto::generated::base_node;

#[cfg(feature = "base_node")]
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/proto/generated/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

//! Imports of rust files generated from protos

#[cfg(feature = "base_node")]
#[cfg(feature = "base_node_proto")]
#[path = "tari.base_node.rs"]
pub mod base_node;
#[path = "tari.core.rs"]
Expand Down
3 changes: 1 addition & 2 deletions base_layer/p2p/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ fn main() {
tari_common::protobuf_build::ProtoCompiler::new()
.proto_paths(&["src/proto"])
.out_dir("src/proto")
.emit_rerun_if_changed_directives()
.compile()
.unwrap();
println!("cargo:rerun-if-changed=src/proto/liveness.proto");
println!("cargo:rerun-if-changed=src/proto/message_type.proto");
}
13 changes: 13 additions & 0 deletions common/src/protobuf_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub struct ProtoCompiler {
field_attributes: HashMap<&'static str, &'static str>,
proto_paths: Vec<PathBuf>,
include_paths: Vec<PathBuf>,
emit_rerun_if_changed_directives: bool,
}

impl ProtoCompiler {
Expand All @@ -67,6 +68,7 @@ impl ProtoCompiler {
field_attributes: HashMap::new(),
proto_paths: Vec::new(),
include_paths: Vec::new(),
emit_rerun_if_changed_directives: false,
}
}

Expand All @@ -92,6 +94,11 @@ impl ProtoCompiler {
self
}

pub fn emit_rerun_if_changed_directives(&mut self) -> &mut Self {
self.emit_rerun_if_changed_directives = true;
self
}

pub fn include_paths<P: AsRef<Path>>(&mut self, include_paths: &[P]) -> &mut Self {
self.include_paths
.extend(include_paths.iter().map(|p| p.as_ref().to_path_buf()));
Expand Down Expand Up @@ -166,6 +173,12 @@ impl ProtoCompiler {

fs::remove_dir_all(&tmp_out_dir).map_err(|err| format!("Failed to remove temporary dir: {}", err))?;

if self.emit_rerun_if_changed_directives {
for p in &protos {
println!("cargo:rerun-if-changed={}", p.to_string_lossy());
}
}

Ok(())
}
}
1 change: 1 addition & 0 deletions comms/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn main() {
tari_common::protobuf_build::ProtoCompiler::new()
.proto_paths(&["src/proto"])
.out_dir("src/proto")
.emit_rerun_if_changed_directives()
.compile()
.unwrap();
}
5 changes: 1 addition & 4 deletions comms/dht/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ fn main() {
tari_common::protobuf_build::ProtoCompiler::new()
.proto_paths(&["src/proto"])
.out_dir("src/proto")
.emit_rerun_if_changed_directives()
.compile()
.unwrap();
println!("cargo:rerun-if-changed=src/proto/dht.proto");
println!("cargo:rerun-if-changed=src/proto/envelope.proto");
println!("cargo:rerun-if-changed=src/proto/message_header.proto");
println!("cargo:rerun-if-changed=src/proto/store_forward.proto");
}