prost
prost copied to clipboard
prost-build triggers rebuild on arbitrary file change
Hello
Let's say I have some rust project and have done cargo build. Now I touch an arbitrary file around there, eg touch x. If I run cargo build now, it is very fast and mostly figures out it doesn't need to do anything.
However, this changes if I introduce prost-build into the project. Now the cargo build will rebuild the whole crate (and all the tests and other things if it is not cargo build but eg. cargo test --all).
My guess is, this has something to do with the fact that the file change provokes build.rs to be re-run. That one, in turn, overwrites the rs files generated from protobufs, which triggers the rebuild (even though the produced files are the same).
If my guess is correct, would it make sense to generate them to some temporary file first (eg. generated_file.rs.tmp), compare with the previous version (if present) and then move it into place only if it differs?
Hmm. That workaround doesn't seem to help :-(, must be something else.
@vorner perhaps this todo is related? I admit I didn’t try and chase down the ‘correct’ way of handling this after punting and writing the todo.
It's most likely related to this, yes.
I tried to look through the cc repository, but it seems it contains no mention of rerun-if, so likely no, they don't have it figured out. On the other hand, cc is mostly used in -sys crates and these are not changed that often, so the motivation may be smaller there.
I don't see what the problem indicated in the todo is. Shouldn't replacing the crate root be the goal here, because otherwise we'd still always rebuild? Also note that if other build scripts emit their own paths, prost currently doesn't rebuild if the .proto changes, which seems undesirable
It seems like it's worth documenting this at the very least. AFAICT setting it has caused no problems for me (it's not like cargo no longer detects changes in src/blah.rs after setting it).
Not sure what you mean by it changes the crate root though.
I was referring to the link to the todo comment above. I have used this feature manually in my program and have seen no problems with it, still definitely in favor of implementing this.
Sorry got my bug numbers wrong - it actually fixes #231 - not sure if it fixes this.
Shouldn't this solve the issue?
println!("cargo:rerun-if-changed=proto/schema.proto");
prost_build::compile_protos(&["proto/schema.proto"], &["proto/"]).unwrap();
Shouldn't this solve the issue?
I think it should. I'd support adding an option to prost_build::Config to do that for each argument to compile_protos. It maybe should even be enabled by default. Would love if someone with more Cargo expertise could weigh in here, since I suspect there are subtleties at play.