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

rust: use features to support Prost or rust-protobuf #349

Merged
merged 8 commits into from
Mar 5, 2019

Conversation

nrc
Copy link
Contributor

@nrc nrc commented Jan 29, 2019

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

ice1000
ice1000 previously approved these changes Jan 30, 2019
Copy link
Contributor

@ice1000 ice1000 left a 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.

build.rs Outdated Show resolved Hide resolved
@ice1000
Copy link
Contributor

ice1000 commented Jan 30, 2019

Comment for future development: the local mod name protobuf is the same as the library protobuf. If this library also uses API from the external crate protobuf, there'll be name conflict problems.
Sounds like this library doesn't, it's fine to use the name.

build.rs Outdated Show resolved Hide resolved
@nrc
Copy link
Contributor Author

nrc commented Feb 4, 2019

rebased and adds in @ice1000 's refactoring.

PTAL @overvenus and @BusyJay

@siddontang
Copy link
Member

@nrc

can we create a prost branch for all associated projects - kvproto, TiKV, grpc-rs, raft-rs

IMO, I don't want to introduce prost feature in master now.

@nrc
Copy link
Contributor Author

nrc commented Feb 4, 2019

can we create a prost branch for all associated projects - kvproto, TiKV, grpc-rs, raft-rs

Sure. How should we handle review? When we land on the branch or when we merge to master?

@siddontang
Copy link
Member

@nrc

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.

build.rs Outdated Show resolved Hide resolved
// 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");
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor

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 .protos are treated as "changed" locally so a regeneration will get triggered if we do so.

Copy link
Contributor

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.

@nrc nrc force-pushed the feature branch 2 times, most recently from 008a6a4 to a9f6579 Compare February 25, 2019 00:32
@nrc
Copy link
Contributor Author

nrc commented Feb 25, 2019

@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" }
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

@siddontang
Copy link
Member

Hi @nrc

SGTM

@nrc
Copy link
Contributor Author

nrc commented Feb 25, 2019

@BusyJay @overvenus @ice1000 PTAL I'd like to land this PR

overvenus
overvenus previously approved these changes Feb 25, 2019
Copy link
Member

@overvenus overvenus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

ice1000
ice1000 previously approved these changes Feb 25, 2019
Copy link
Contributor

@ice1000 ice1000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@nrc
Copy link
Contributor Author

nrc commented Mar 3, 2019

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.

@nrc
Copy link
Contributor Author

nrc commented Mar 4, 2019

@siddontang or @BusyJay or @overvenus please could you re-approve?

@ice1000 ice1000 merged commit ab7debc into pingcap:master Mar 5, 2019
nrc pushed a commit to tikv/raft-rs that referenced this pull request Apr 11, 2019
* 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>
sticnarf pushed a commit to sticnarf/kvproto that referenced this pull request Oct 27, 2019
* 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
shbieng pushed a commit to shbieng/raft-rs that referenced this pull request Sep 19, 2022
* 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>
siennathesane pushed a commit to shieldmaidens/pleiades that referenced this pull request Nov 4, 2023
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants