-
Notifications
You must be signed in to change notification settings - Fork 219
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
rust: use features to support Prost or rust-protobuf #349
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! I can't wait to get this merged.
Comment for future development: the local mod name |
rebased and adds in @ice1000 's refactoring. PTAL @overvenus and @BusyJay |
can we create a IMO, I don't want to introduce prost feature in master now. |
Sure. How should we handle review? When we land on the branch or when we merge to master? |
You can drive this as fast as you can to prove it can work(you may work with @ice1000 and @overvenus ). Then you can send a PR and we can review it carefully. You already have the privilege to create the branch. |
// as a dependency. Therefore, the user must opt-in to regenerating the | ||
// Rust files. | ||
if env::var_os("CARGO_FEATURE_REGENERATE").is_none() { | ||
println!("cargo:rerun-if-changed=build.rs"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the changes inside proto
directory trigger rebuild too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think only if we are regenerating the proto files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to proto files only make sense when code is generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha, can we regenerate them all the time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to generate them all the time, we want to opt-in to building so that downstream crates don't require protoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a good idea. If we use kvproto as a dependency, all the .proto
s are treated as "changed" locally so a regeneration will get triggered if we do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my case, when building TiKV, I get this message:
--- stdout
cargo:rerun-if-changed=proto/errorpb.proto
cargo:rerun-if-changed=proto/kvrpcpb.proto
cargo:rerun-if-changed=proto/raft_serverpb.proto
cargo:rerun-if-changed=proto/coprocessor.proto
cargo:rerun-if-changed=proto/pdpb.proto
cargo:rerun-if-changed=proto/import_sstpb.proto
cargo:rerun-if-changed=proto/metapb.proto
cargo:rerun-if-changed=proto/raft_cmdpb.proto
cargo:rerun-if-changed=proto/debugpb.proto
cargo:rerun-if-changed=proto/tikvpb.proto
cargo:rerun-if-changed=proto/import_kvpb.proto
where I don't expect one.
008a6a4
to
a9f6579
Compare
@siddontang there is no Prost dep here now, do you think it's OK to land it in order to make protoc etc., not required to build? (#354) |
Cargo.toml
Outdated
protoc-rust = "2.0" | ||
protoc-grpcio = "0.3.1" | ||
regex = "1.1" | ||
kvproto-build = { git = "https://github.com/nrc/kvproto-build.git" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, but seem this repo is common for all the protobuf generated, not only for kvproto.
So maybe we can rename to protobut-build?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure!
Hi @nrc SGTM |
@BusyJay @overvenus @ice1000 PTAL I'd like to land this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
As suggested in tikv/raft-rs#175
Also removes use of features in build.rs and use cfg! instead of env var.
Rebased and using a published version of protobuf-build. No substantial changes, so I don't think this needs re-review and can be merged once CI passes. |
@siddontang or @BusyJay or @overvenus please could you re-approve? |
* Replace script with build script, use features See pingcap/kvproto#349 Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Cargo fmt Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Apply some suggestions from rust clippy Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove everything related to prost Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Refactor build.rs Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Save progress Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Refactor build.rs Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Refactor build.rs Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Save progress Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Documentation in src/lib.rs * Add [cfg(feature = "lib-rust-protobuf")] to every protobuf places * Replace common.sh with rust code Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix compilation error Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix typo Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Cargo fmt Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix typo-caused compilation error Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix compilation errors Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Add rsprost file to git repo Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Save progress * Save progress * Successfully generate! * Refactor, only one error is left now * Fix all errors occurred in `src`, start working on `tests` * Test compiles, remove rust-protobuf support * Compatible with stable rust, pass 150 tests now Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Sounds like all tests are passed Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Passing all doc-tests Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Use git dependency instead of relative path Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Partially address comments Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix tests after merge Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Rename generated mod to `prost` from `rsprost` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove `RepeatedField::from_vec` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove all uses of `protobuf::Message as Msg` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove `Codec` error and remove tests (not added for prost's errors because their constructors are private Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove even more protobuf stuff, apply some minor suggestions by clippy Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Clean up build script Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix clippy warnings Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Use `merge` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Add rust-protobuf codes back Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Revert unexpected comment changes Signed-off-by: ice1000 <ice1000kotlin@foxmail.com>
* rust: use features to support Prost or rust-protobuf * Rust: remove unnecessary `extern crate`s * Use features in generated code * Rename the feature flags and make code generation opt-in * Refactor build script As suggested in tikv/raft-rs#175 * Use kvproto-build crate * Change feature names to match GRPC-rs Also removes use of features in build.rs and use cfg! instead of env var. * Use published protobuf-build
* Replace script with build script, use features See pingcap/kvproto#349 Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Cargo fmt Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Apply some suggestions from rust clippy Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove everything related to prost Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Refactor build.rs Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Save progress Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Refactor build.rs Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Refactor build.rs Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Save progress Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Documentation in src/lib.rs * Add [cfg(feature = "lib-rust-protobuf")] to every protobuf places * Replace common.sh with rust code Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix compilation error Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix typo Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Cargo fmt Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix typo-caused compilation error Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix compilation errors Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Add rsprost file to git repo Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Save progress * Save progress * Successfully generate! * Refactor, only one error is left now * Fix all errors occurred in `src`, start working on `tests` * Test compiles, remove rust-protobuf support * Compatible with stable rust, pass 150 tests now Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Sounds like all tests are passed Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Passing all doc-tests Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Use git dependency instead of relative path Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Partially address comments Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix tests after merge Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Rename generated mod to `prost` from `rsprost` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove `RepeatedField::from_vec` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove all uses of `protobuf::Message as Msg` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove `Codec` error and remove tests (not added for prost's errors because their constructors are private Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove even more protobuf stuff, apply some minor suggestions by clippy Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Clean up build script Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix clippy warnings Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Use `merge` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Add rust-protobuf codes back Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Revert unexpected comment changes Signed-off-by: ice1000 <ice1000kotlin@foxmail.com>
* Replace script with build script, use features See pingcap/kvproto#349 Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Cargo fmt Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Apply some suggestions from rust clippy Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove everything related to prost Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Refactor build.rs Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Save progress Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Refactor build.rs Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Refactor build.rs Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Save progress Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Documentation in src/lib.rs * Add [cfg(feature = "lib-rust-protobuf")] to every protobuf places * Replace common.sh with rust code Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix compilation error Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix typo Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Cargo fmt Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix typo-caused compilation error Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix compilation errors Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Add rsprost file to git repo Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Save progress * Save progress * Successfully generate! * Refactor, only one error is left now * Fix all errors occurred in `src`, start working on `tests` * Test compiles, remove rust-protobuf support * Compatible with stable rust, pass 150 tests now Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Sounds like all tests are passed Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Passing all doc-tests Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Use git dependency instead of relative path Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Partially address comments Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix tests after merge Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Rename generated mod to `prost` from `rsprost` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove `RepeatedField::from_vec` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove all uses of `protobuf::Message as Msg` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove `Codec` error and remove tests (not added for prost's errors because their constructors are private Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Remove even more protobuf stuff, apply some minor suggestions by clippy Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Clean up build script Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Fix clippy warnings Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Use `merge` Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Add rust-protobuf codes back Signed-off-by: ice1000 <ice1000kotlin@foxmail.com> * Revert unexpected comment changes Signed-off-by: ice1000 <ice1000kotlin@foxmail.com>
This change is backwards compatible for clients, and will allow us to develop Prost support without removing rust-protobuf. Based on top of #347
cc @ice1000