google / google/certificate-transparency-go

Bazel build failed : compilepkg missing strict dependencies

Open
#1,653 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.2k
Forks
323
Avg merge
3d 4h
Merged PRs (30d)
5

Description

In our Go project, we use Bazel technology. The project indirectly references [github.com/google/certificate-transparency-go](https://github.com/google/certificate-transparency-go). However, when running Bazel, an error occurs:
```shell
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
compilepkg: missing strict dependencies:
/.cache/wangdongyang1/bazel/_bazel_XXX/sandbox/linux-sandbox/700/execroot/monorepo/external/com_github_google_certificate_transparency_go/client/multilog.go: import of "github.com/google/certificate-transparency-go/client/configpb"
No dependencies were provided.
Check that imports in Go sources match importpath attributes in deps.
Target //prod/lepton/ecp:ecp failed to build
```

After my investigation, I found that although multilog.proto is located in the directory client/configpb, the option go_package set in it is `github.com/google/certificate-transparency-go/client/multilog/configpb`, with an extra "multilog" added.

However, client/multilog.go uses the following path for the import:
```go
"github.com/google/certificate-transparency-go/client/configpb"
```
When we use Bazel, the BUILD.bazel generated in the client/configpb directory is as follows:
```bazel

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

proto_library(
name = "configpb_proto",
srcs = ["multilog.proto"],
visibility = ["//visibility:public"],
deps = ["@com_google_protobuf//:timestamp_proto"],
)

go_proto_library(
name = "configpb_go_proto",
importpath = "github.com/google/certificate-transparency-go/client/multilog/configpb",
proto = ":configpb_proto",
visibility = ["//visibility:public"],
)

go_library(
name = "configpb",
embed = [":configpb_go_proto"],
importpath = "github.com/google/certificate-transparency-go/client/multilog/configpb",
visibility = ["//visibility:public"],
)

alias(
name = "go_default_library",
actual = ":configpb",
visibility = ["//visibility:public"],
)

```
As you can see, the `importpath` in the Bazel file also includes `multilog`.
However, in the `BUILD.bazel` file in the `client` directory, the `path` of `configpb` in `deps` does not contain `multilog`.
```bazel
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "client",
srcs = [
"getentries.go",
"logclient.go",
"multilog.go",
],
importpath = "github.com/google/certificate-transparency-go/client",
visibility = ["//visibility:public"],
deps = [
"//:certificate-transparency-go",
"//jsonclient",
"//tls",
"//x509",
"@com_github_google_certificate_transparency_go//client/configpb",
"@org_golang_google_protobuf//encoding/prototext",
"@org_golang_google_protobuf//proto",
],
)

alias(
name = "go_default_library",
actual = ":client",
visibility = ["//visibility:public"],
)

go_test(
name = "client_test",
srcs = [
"logclient_test.go",
"multilog_test.go",
],
deps = [
":client",
"//:certificate-transparency-go",
"//jsonclient",
"//testdata",
"//tls",
"//x509",
"//x509util",
"@com_github_google_certificate_transparency_go//client/configpb",
"@org_golang_google_protobuf//types/known/timestamppb",
],
)

```

The `path` of `configpb` in `deps` within `client/BUILD.bazel` does not match the `path` of `configpb` in `go_library` within `client/configpb/BUILD.bazel`, which results in a failure.

### Hot To Fix

Just fix option go_package to
`github.com/google/certificate-transparency-go/client/configpb`

Contributor guide

Open the contributing guide

Research direction

Start with client/configpb/multilog.proto and compare its go_package option with the import in client/multilog.go. Review the generated BUILD.bazel files under client/configpb and client, then run the failing //prod/lepton/ecp:ecp Bazel target; done means the strict-dependencies error is gone and the client tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.