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
Idea: API for generating code on a cargo build script. #57
Comments
It is not that simple. Problem is in line:
On the other hand, |
I hadn't realised that the parsing is made by |
In case you haven't seen it, https://github.com/dwrensha/capnpc-rust/blob/master/src/lib.rs |
@jakerr I have seen similar, but what I had in mind was both on-build generation and no out of cargo dependencies, and I think the latter is more important. Thus without a rust implementation of the missing functionality of |
@jakerr 👍 for providing something akin to what include!(concat!(env!("OUT_DIR"), "/log.pb.rs")); and have your build script look something like this capnpc example: extern crate capnpc;
use std::path::Path;
fn main() {
let prefix = Path::new("src/");
::capnpc::compile(
&prefix,
&[
&prefix.join("log.capnp"),
],
).unwrap();
} This way shipping crates with proto files becomes easy and natural. |
I've made a small crate rust-protobuf-build which links to both It doesn't have any documentation yet, but you can find a usage in my librespot project. @stepancheg It uses |
@plietar yes, you can rely on stability of Also, could you please add readme file to the |
Sorry it took me so long, I've finally added a README to |
FYI, I've just created simple Can be used like this: build.rs. Next step would be invoking |
OK, I've implemented Closing the issue now. Please reopen if you disagree. |
Cargo has updated the way build scripts work, with the latest changes it makes sense to have a simple function for use on a
build.rs
that given a.proto
file will generate the.rs
file on build time.Usage would be something like this, inside build.rs:
Main advantage would be no need for either versioning generated
.rs
files or depending on onprotoc
.The drawback would be doubled dependency on this crate, as a dependency and build-dependency, which could probably be solved by splitting protobuf on something like protobuf-gen and protobuf-runtime.
This looks fairly simple to implement and naturally it would be completely optional to use it that way. However I wanted to share the idea before trying to implement, partially because I'm having little time to spare lately and partially because I'd like to hear what other people think about it.
The text was updated successfully, but these errors were encountered: