I am trying to build a Go application with brazel. It is an existing private GitHub repo (with this location: github.xyz.com/repo-name) that I am working on, and my aim is to create a binary out of a main.go file that depends on some other Go files for it's methods. This is my BUILD.bazel file inside the folder called e2e where all these go files are present:
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_binary(
name = "e2e",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
go_library(
name = "go_default_library",
srcs = ["main.go"],
data = [
"//cmd/iasd",
"//migrations:migration_files",
"//test/iamd:client-ca-bundle.pem",
] + glob(
["testdata/**"],
),
importpath = "github.xyz.com/repo-name/test/e2e",
visibility = ["//visibility:public"],
deps = [
"//test:go_default_library",
"//vendor/github.com/bazelbuild/rules_go/go/tools/bazel:go_default_library",
"//vendor/github.com/golang-migrate/migrate:go_default_library",
"//vendor/github.com/golang-migrate/migrate/database/cockroachdb:go_default_library",
"//vendor/github.com/golang-migrate/migrate/source/file:go_default_library",
"//vendor/github.com/google/uuid:go_default_library",
"//vendor/github.com/lib/pq:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/google.golang.org/grpc:go_default_library",
"//vendor/google.golang.org/grpc/credentials:go_default_library",
"//api/grpc/v1/applications:go_default_library",
"//api/grpc/v1/clients:go_default_library",
"//pkg/oauth2/mtls:go_default_library",
"//vendor/github.com/coreos/go-oidc:go_default_library",
"//vendor/github.com/dgrijalva/jwt-go:go_default_library",
"//vendor/golang.org/x/oauth2:go_default_library",
],
)
and this is how the imports look in my main.go file:
import (
"context"
"crypto/tls"
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"
"log"
"fmt"
"io"
"os"
"github.com/pkg/errors"
"github.com/coreos/go-oidc"
"github.com/dgrijalva/jwt-go"
"github.xyz.com/repo-name/api/grpc/v1/applications"
"github.xyz.com/repo-name/api/grpc/v1/clients"
"github.xyz.com/repo-name/pkg/oauth2/mtls"
"github.xyz.com/repo-name/test/e2e"
"github.xyz.com/repo-name/test"
"golang.org/x/oauth2"
"google.golang.org/grpc"
)
Now on executing the command bazel run //test/e2e:e2e, I get the following error:
compilepkg: missing strict dependencies:
/private/var/tmp/_bazel_<myname>/a9b32769d59e90b5398bc5d8a988c877/sandbox/darwin-sandbox/394/execroot/github_xyz_com_repo_name/test/e2e/main.go: import of "github.xyz.com/repo-name/test/e2e"
No dependencies were provided.
This is because of the import github.xyz.com/repo-name/test/e2e in my main file. To include the import, if I add this to my BUILD.bazel file in deps: "//test/e2e:go_default_library" it ends up with this error:
"//test/e2e:go_default_library: cycle in dependency graph:
//test/e2e:e2e
.-> //test/e2e:go_default_library [self-edge]"
I understand the context of errors, but I cannot figure out a suitable way to resolve it. What changes should I make in my BUILD.bazel file to get include the dependency correctly?