Skip to content

Conflict proto files with diffrent package name #717

@YeahhhhzZ

Description

@YeahhhhzZ

project directories

tree .
.
├── build.rs
├── Cargo.toml
├── demo
│   └── main.rs
└── proto
    ├── common
    │   └── header.proto
    ├── mod.rs
    └── module
        ├── header.proto
        └── items.proto

common/header.proto:

syntax = "proto2";

package common.header;

message Header {
  optional uint64 id = 1;
  optional uint64 timestamp_ms = 2;
}

module/header.proto:

syntax = "proto2";

package module.header;

message Header {
  optional string source = 1;
}

module/items.proto:

syntax = "proto2";

import "proto/common/header.proto";

package module.items;

message Items {
  optional common.header.Header header = 1;
  optional string name = 2;
}

build.rs

use protobuf_codegen::Codegen;

fn main() {
    let mut codegen = Codegen::new();
    codegen
        .protoc()
        .cargo_out_dir("proto")
        .includes(&["./"])
        .inputs(&[
            "./proto/common/header.proto",
            "./proto/module/header.proto",
            "./proto/module/items.proto",
        ]);
    if let Ok(protoc_env) = std::env::var("PROTOC") {
        codegen.protoc_path(std::path::Path::new(&protoc_env));
    }
    codegen.run_from_script();
}

build output:
image

mod.rs:

// @generated

pub mod header;
pub mod header;
pub mod items;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions