Skip to content

Commit

Permalink
Fix path in include_file function when outdir used (#544)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucio Franco <[email protected]>
Co-authored-by: Lucio Franco <[email protected]>
  • Loading branch information
3 people authored Oct 7, 2021
1 parent db9cd5c commit 1825b38
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,11 @@ impl Config {
written += subwritten;
if subwritten != matching.len() {
let modname = matching[0][..=depth].join(".");
if let Some(buf) = basepath {
if let Some(_) = basepath {
self.write_line(
outfile,
depth + 1,
&format!("include!(\"{}/{}.rs\");", buf.display(), modname),
&format!("include!(\"{}.rs\");", modname),
)?;
} else {
self.write_line(
Expand Down
6 changes: 6 additions & 0 deletions tests/single-include/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ fn main() {
.include_file("lib.rs")
.compile_protos(&["protos/search.proto"], &["protos"])
.unwrap();

Config::new()
.out_dir("src/outdir")
.include_file("mod.rs")
.compile_protos(&["protos/outdir.proto"], &["protos"])
.unwrap();
}
9 changes: 9 additions & 0 deletions tests/single-include/protos/outdir.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";

package outdir;

message OutdirRequest {
string query = 1;
int32 page_number = 2;
int32 result_per_page = 3;
}
1 change: 1 addition & 0 deletions tests/single-include/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include!(concat!(env!("OUT_DIR"), "/lib.rs"));
include!("./outdir/mod.rs");
2 changes: 2 additions & 0 deletions tests/single-include/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
fn main() {
let _search_req = single_include::search::SearchRequest::default();

let _out_dir_test = single_include::outdir::OutdirRequest::default();
}
3 changes: 3 additions & 0 deletions tests/single-include/src/outdir/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod outdir {
include!("outdir.rs");
}
9 changes: 9 additions & 0 deletions tests/single-include/src/outdir/outdir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct OutdirRequest {
#[prost(string, tag="1")]
pub query: ::prost::alloc::string::String,
#[prost(int32, tag="2")]
pub page_number: i32,
#[prost(int32, tag="3")]
pub result_per_page: i32,
}

0 comments on commit 1825b38

Please sign in to comment.