Import common proto in each crate?
- Dominant language
- Rust
- Stars
- 12.5k
- Forks
- 1.3k
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 24
Description
### Version
```
tonic v0.9.2
tonic v0.9.2 (*)
tonic-build v0.9.2
tonic v0.9.2 (*)
tonic-web v0.9.2
tonic v0.9.2 (*)
```
### Platform
Win 10 64
### Description
Hi people! Thanks for your amazing work!
I have this dir structure:
```
- Cargo.toml (workspace)
- src
- common
- Cargo.toml
- src
- common.proto
- crates
- players
- Cargo.toml
- build.rs
- src
- proto
- players.proto (I would like to import src/common/src/common.proto here)
- teams
- Cargo.toml
- build.rs
- src
- proto
- teams.proto (I would like to import src/common/src/common.proto here)
- others...
```
as you can see I have many crates under `crates` dir and I have a `common.proto` which I would like to import in my crates.
I'm using a `build.rs` for each crate because I cannot (right?) use one for the entire Cargo workspace (I tried: Cargo doesn't start build.rs in workspace root dir).
So I'm trying to import common.proto in file like this:
```proto
syntax = "proto3";
package players;
import "google/protobuf/timestamp.proto";
import "src/common/src/common.proto";
```
and in my VSCode this is working.
But when I start `build.rs` throws with:
```
error: failed to run custom build command for `players v0.1.0`
Caused by:
process didn't exit successfully: `C:\prj\target\debug\build\orders-b13065cbe3fac50f\build-script-build` (exit code: 1)
--- stdout
cargo:rerun-if-changed=src/proto/players.proto
cargo:rerun-if-changed=src/proto
--- stderr
Error: Custom { kind: Other, error: "protoc failed: src/common/src/common.proto: File not found.\r\nplayers.proto:6:1: Import \"src/common/src/common.proto\" was not found or had errors.\r\nplayers.proto:29:3: \"common.Pagination\" is not defined.\r\nplayers.proto:49:9: \"common.Page\" is not defined.\r\n" }
[Finished running. Exit status: 0]
```
My `build.rs` is:
```rust
fn main() -> Result<(), Box> {
tonic_build::configure()
.out_dir("src/proto")
.compile(
&["src/proto/players.proto"],
&["src/proto"],
)?;
Ok(())
}
```
How can I fix this?
Contributor guide
Assessment
This issue has not been assessed yet.