Bazel build issue after upgrading
to repro, copy all the files below to a folder, then:
go get cloud.google.com/go/iam/credentials/apiv1@latest
bazel run :gazelle -- update-repos -from_file=go.mod -prune=true -to_macro=repositories.bzl%go_repositories
bazel run :main
you'll see two errors
ERROR: /home/srashid/.cache/bazel/_bazel_srashid/a0532da35617e32c78a02f8a1bb1886b/external/com_github_googleapis_gax_go_v2/apierror/internal/proto/BUILD.bazel:18:17:
no such package '@com_github_googleapis_gax_go_v2//google/rpc': BUILD file not found in directory 'google/rpc' of external repository @com_github_googleapis_gax_go_v2.
Add a BUILD file to a directory to mark it as a package. and referenced by '@com_github_googleapis_gax_go_v2//apierror/internal/proto:jsonerror_go_proto'
this is fixec by adding in build_file_proto_mode
here in repositories.bazel:
go_repository(
name = "com_github_googleapis_gax_go_v2",
importpath = "github.com/googleapis/gax-go/v2",
build_file_proto_mode = "disable_global",
sum = "h1:mhN09QQW1jEWeMF74zGR81R30z4VJzjZsfkUhuHF+DA=",
version = "v2.12.2",
)
- Second error appeared only after upgrading to 1.33.0 (protobuf works fine with 1.32.0)
ERROR: /home/srashid/.cache/bazel/_bazel_srashid/a0532da35617e32c78a02f8a1bb1886b/external/org_golang_google_protobuf/types/gofeaturespb/BUILD.bazel:5:14:
no such package '@com_google_protobuf//': The repository '@com_google_protobuf' could not be resolved:
Repository '@com_google_protobuf' is not defined and referenced by '@org_golang_google_protobuf//types/gofeaturespb:gofeaturespb_proto'
To fix, in repositories.bzl
, comment out
#go_repository(
# name = "org_golang_google_protobuf",
# importpath = "google.golang.org/protobuf",
# sum = "h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=",
# version = "v1.33.0",
#)
package main
import (
"fmt"
_ "cloud.google.com/go/iam/credentials/apiv1"
_ "cloud.google.com/go/iam/credentials/apiv1/credentialspb"
)
func main() {
fmt.Println("ok")
}
module main
go 1.21.2
require cloud.google.com/go/iam v1.1.7
require (
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.169.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240304161311-37d4d3c04a78 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
sha256 = "80a98277ad1311dacd837f9b16db62887702e9f1d1c4c9f796d0121a46c8e184",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip",
],
)
http_archive(
name = "bazel_gazelle",
sha256 = "d3fa66a39028e97d76f9e2db8f1b0c11c099e8e01bf363a923074784e451f809",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.33.0/bazel-gazelle-v0.33.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.33.0/bazel-gazelle-v0.33.0.tar.gz",
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("//:repositories.bzl", "go_repositories")
# gazelle:repository_macro repositories.bzl%go_repositories
go_repositories()
go_rules_dependencies()
go_register_toolchains(version = "1.21.0")
gazelle_dependencies()
http_archive(
name = "googleapis",
sha256 = "9cc324d40919f8e393a23602252ccaf43d7a7d202f114ed835e674fca87c293d",
strip_prefix = "googleapis-4eccaaf48c0ccadc6f98707d3dbe9614d47bb103",
urls = [
"https://github.com/googleapis/googleapis/archive/4eccaaf48c0ccadc6f98707d3dbe9614d47bb103.zip",
],
)
load("@googleapis//:repository_rules.bzl", "switched_rules_by_language")
switched_rules_by_language(
name = "com_google_googleapis_imports",
)
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@bazel_gazelle//:def.bzl", "gazelle")
gazelle(name = "gazelle")
go_binary(
name = "main",
out = "server",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
goos = "linux",
goarch = "amd64",
)
go_library(
name = "go_default_library",
srcs = [
"main.go",
],
importpath = "main",
visibility = ["//visibility:private"],
deps = [
"@com_google_cloud_go_iam//credentials/apiv1:go_default_library",
"@com_google_cloud_go_iam//credentials/apiv1/credentialspb:go_default_library",
],
)
load("@bazel_gazelle//:deps.bzl", "go_repository")
def go_repositories():
print('ok')