Skip to content
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

Importing definitions fails because of incorrect package path #43

Closed
jpoz opened this issue Jun 22, 2015 · 1 comment
Closed

Importing definitions fails because of incorrect package path #43

jpoz opened this issue Jun 22, 2015 · 1 comment

Comments

@jpoz
Copy link

jpoz commented Jun 22, 2015

When I import some of google's proto definitions the generated code imports a package that does not exist.

Example:

syntax = "proto3";

import "google/protobuf/timestamp.proto";

package bar;

message Foo {
  google.protobuf.Timestamp start = 1;
  google.protobuf.Timestamp finish = 2;
}

Generated code:

package bar

import proto "github.com/golang/protobuf/proto"
import google_protobuf "google/protobuf"

...

The import of google_protobuf fails.

  • Should I be building the google_protobuf package and adding it manually to my GOPATH?
  • Is there a directive I'm missing to tell the protoc generator to build dependencies?
  • Bug in golang/protobuf? Where would i start looking to add a fix?
@dsymonds
Copy link
Contributor

protoc-gen-go needs to be told what import path to generate for packages that it can't guess.

The simplest option is to run protoc from a directory where the subdir holding the .proto file will be the import path (e.g. in $GOPATH/src).

The next best option is to pass one or more M parameters to specify the mapping of .proto file to import path. See protoc-gen-go/plugin/Makefile in this repo for an example of that.

@golang golang locked as resolved and limited conversation to collaborators Jun 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants