bazel-contrib / bazel-gazelle

Gazelle is a Bazel build file generator for Bazel projects. It natively supports Go and protobuf, and it may be extended to support new languages and custom rule sets.
Apache License 2.0
1.21k stars 381 forks source link

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

Closed davidbyttow closed 1 month ago

davidbyttow commented 2 months ago

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

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 commented 2 months ago

Well, I'm not sure if this is the appropriate fix, but seems to work. https://github.com/bazelbuild/bazel-gazelle/pull/1927

davidbyttow commented 1 month ago

@fmeum any thoughts on the above?