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

Deps for go_proto_library not generated when proto file name matches package name #1926

Open
davidbyttow opened this issue Sep 17, 2024 · 1 comment · May be fixed by #1927
Open

Deps for go_proto_library not generated when proto file name matches package name #1926

davidbyttow opened this issue Sep 17, 2024 · 1 comment · May be fixed by #1927

Comments

@davidbyttow
Copy link
Contributor

davidbyttow commented Sep 17, 2024

What version of gazelle are you using?

0.38.0

What version of rules_go are you using?

0.50.1

What version of Bazel are you using?

7.3.1

Does this issue reproduce with the latest releases of all the above?

yes

What operating system and processor architecture are you using?

mac m2

Setup

  • Ensure gazelle proto mode is file mode
  • Create two protos file in the workspace, in this case: proto/example/example.proto (note the same name as the package) and proto/example/other.proto

One important note: and probably related, is that the target go_package does not match the proto package that is inferred. So it attempts to generate an empty package for the example go_proto_library, which seems to overwrite the rule generated before with the appropriate imports.

Here are the files:
example.proto

syntax = "proto3";

package bazelsandbox.proto.example.example;

option go_package = "github.com/davidbyttow/bazel-sandbox/gen/proto/example/example";

import "google/type/date.proto";

message Example {
  google.type.Date date = 1;
}

other.proto

syntax = "proto3";

package bazelsandbox.proto.example.other;

option go_package = "github.com/davidbyttow/bazel-sandbox/gen/proto/example/other";

import "google/type/date.proto";

message Other {
  google.type.Date date = 1;
}

Problem

After running Gazelle, the example_go_proto does not get its dependencies, unlike other_go_proto.

load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")

proto_library(
    name = "example_proto",
    srcs = ["example.proto"],
    visibility = ["//visibility:public"],
    deps = ["@com_google_googleapis//google/type:date_proto"],
)

proto_library(
    name = "other_proto",
    srcs = ["other.proto"],
    visibility = ["//visibility:public"],
    deps = ["@com_google_googleapis//google/type:date_proto"],
)

go_proto_library(
    name = "example_go_proto",
    importpath = "github.com/davidbyttow/bazel-sandbox/gen/proto/example/example",
    proto = ":example_proto",
    visibility = ["//visibility:public"],

    # PROBLEM: missing deps
)

go_proto_library(
    name = "other_go_proto",
    importpath = "github.com/davidbyttow/bazel-sandbox/gen/proto/example/other",
    proto = ":other_proto",
    visibility = ["//visibility:public"],
    deps = ["@com_google_googleapis//google/type:date_go_proto"], # OK
)

What am I missing here? :)

@davidbyttow davidbyttow changed the title Deps for generated go_proto_library missing when proto file name matches package name Deps for go_proto_library not generated when proto file name matches package name Sep 17, 2024
davidbyttow added a commit to davidbyttow/bazel-gazelle that referenced this issue Sep 17, 2024
@davidbyttow
Copy link
Contributor Author

Well, I'm not sure if this is the appropriate fix, but seems to work. #1927

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant