Skip to content

rust: replace bash script with build script#347

Merged
ice1000 merged 3 commits intopingcap:masterfrom
nrc:build-rs
Feb 1, 2019
Merged

rust: replace bash script with build script#347
ice1000 merged 3 commits intopingcap:masterfrom
nrc:build-rs

Conversation

@nrc
Copy link
Copy Markdown
Contributor

@nrc nrc commented Jan 28, 2019

With this change, preparing the Rust code becomes the idiomatic cargo build, rather than requiring a script. We would like to migrate from rust-protobuf to Prost, and this change should make that easier.

The Cargo build script is pretty much a 1:1 re-implementation of the old script.

cc @ice1000

@nrc nrc requested review from BusyJay and Hoverbear January 28, 2019 03:29
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 28, 2019

CLA assistant check
All committers have signed the CLA.

overvenus
overvenus previously approved these changes Jan 28, 2019
Copy link
Copy Markdown
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 Jan 28, 2019
Copy link
Copy Markdown
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

@ice1000 ice1000 mentioned this pull request Jan 29, 2019
1 task
@siddontang
Copy link
Copy Markdown
Member

LGTM

PTAL @BusyJay

Copy link
Copy Markdown
Contributor

@BusyJay BusyJay left a comment

Choose a reason for hiding this comment

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

Rest LGTM

@BusyJay
Copy link
Copy Markdown
Contributor

BusyJay commented Jan 30, 2019

Another thought: it may be bad to modify the source directory. It's more natural to generate sources into the target build directory and link it into source directory. For example, for now whenever do a cargo clean && cargo build, git status will show that the workspace is in dirty state.

@nrc
Copy link
Copy Markdown
Contributor Author

nrc commented Jan 30, 2019

Another thought: it may be bad to modify the source directory

@BusyJay agree. I address this in #349 by making code generation opt-in, so a regular cargo build does not rebuild. I thought this is better than generating into the OUT_DIR because it means you can see the code and that might be helpful when debugging and so forth.

@ice1000
Copy link
Copy Markdown
Contributor

ice1000 commented Jan 30, 2019

prost support will generate codes in OUT_DIR and use include! macro to get them compiled.

@brson
Copy link
Copy Markdown

brson commented Jan 30, 2019

Awesome start @nrc.

@nrc
Copy link
Copy Markdown
Contributor Author

nrc commented Jan 30, 2019

prost support will generate codes in OUT_DIR and use include! macro to get them compiled.

I don't think we have to do this - we could copy the files from the OUT_DIR to the src directory rather than use include!. I'm not sure which approach is better - using OUT_DIR is more idiomatic, but using src lets users see the generated code, which I think is valuable.

@BusyJay
Copy link
Copy Markdown
Contributor

BusyJay commented Jan 30, 2019

I'm not familiar with how cargo compile dependencies. If I compile several projects in parallel, which all depend on kvproto, will kvproto also be compiled in parallel? So will the source files get written concurrently? Is it a race condition that can lead to corrupted files?

@BusyJay
Copy link
Copy Markdown
Contributor

BusyJay commented Jan 30, 2019

...when debugging and so forth

Do you mean to debug it in the dependent project or inside kvproto? If debugging in dependent project, it may be easier to look at when the code is under target directory instead of $HOME/.cargo.

@nrc
Copy link
Copy Markdown
Contributor Author

nrc commented Jan 30, 2019

I'm not familiar with how cargo compile dependencies. If I compile several projects in parallel, which all depend on kvproto, will kvproto also be compiled in parallel? So will the source files get written concurrently? Is it a race condition that can lead to corrupted files?

It will be rebuilt for each project in the project's target directory - compiled code is not shared between projects, although there is work in the pipeline to do so

Do you mean to debug it in the dependent project or inside kvproto? If debugging in dependent project, it may be easier to look at when the code is under target directory instead of $HOME/.cargo.

Both. And actually just writing code as a downstream user - it is nice to look on GitHub and see the generated code.

@BusyJay
Copy link
Copy Markdown
Contributor

BusyJay commented Jan 31, 2019

compiled code is not shared between projects,

What I mean is the generated code, as they are flushed into the source directory.

@nrc
Copy link
Copy Markdown
Contributor Author

nrc commented Jan 31, 2019

What I mean is the generated code, as they are flushed into the source directory.

Oh I see, if there are several projects using kvptoto via a path dependency, then I think you could have issues. But I don't think that should happen (it would mean a path dep which points outside of its own repo), so I don't think we should worry.

In any case #349 changes things to opt-in regeneration so it will not be an issue. If you like we can close this PR and discuss #349, but I thought it would be easier to land one piece at a time.

@BusyJay
Copy link
Copy Markdown
Contributor

BusyJay commented Jan 31, 2019

OK, I will give my approval when mod_names is sorted.

nrc added 3 commits February 1, 2019 09:52
Makes generating Rust code easier and should help with the Prost migration
The changes are due to:

* change in version of rust-protobuf
* non-determinism in file generation (stepancheg/rust-protobuf#256)
* formatting
@nrc
Copy link
Copy Markdown
Contributor Author

nrc commented Jan 31, 2019

@BusyJay comment addressed and rebased PTAL

Copy link
Copy Markdown
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.

Giving my approval back

@ice1000 ice1000 merged commit f9b9e7d into pingcap:master Feb 1, 2019
sticnarf pushed a commit to sticnarf/kvproto that referenced this pull request Oct 27, 2019
* Replace generate_rust with build script

Makes generating Rust code easier and should help with the Prost migration

* Commit generated files

The changes are due to:

* change in version of rust-protobuf
* non-determinism in file generation (stepancheg/rust-protobuf#256)
* formatting

* rust: sort module names
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.

7 participants