How to add Bigtable dependency in golang using Bazel

53 views Asked by At

I have simple go program where I want to import and use bigtable sdk.

database.go

import (
"context"

"cloud.google.com/go/bigtable
)

func (s *Store) readRow(ctx context.Context) {
   _,_ = bigtable.NewAdminClient(ctx, "bt-ded", "")

}

In Build file , I have declared dependency

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
    name = "datastore_pkg",
    srcs = [
        "bigtable/database.go",
        "rpc/activity_rpc.go",
        "rpc/index_rpc.go",
        "rpc/user_rpc.go",
    ],
    importpath = "github.com/cliqueedge/go/storage/datastore",
    deps = [
        "//protos/v1:datastore_go_grpc",
        "@com_google_cloud_go//:go_default_library",
    ],
)

I am not sure why I am getting the following error:

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
compilepkg: missing strict dependencies:
        /private/var/tmp/_bazel_satyajit/bf73d00d74a5d5353f57b19b76b99eab/sandbox/darwin-sandbox/4609/execroot/__main__/storage/datastore/bigtable/database.go: import of "cloud.google.com/go/bigtable"
No dependencies were provided.
Check that imports in Go sources match importpath attributes in deps.

Changing the dependency from "@com_google_cloud_go//:go_default_library", to "@com_google_cloud_go_bigtable//:go_default_library",

is not solving the problem either.

In this case, I get following error

 no such package '@com_google_cloud_go_bigtable//': The repository '@com_google_cloud_go_bigtable' could not be resolved: Repository '@com_google_cloud_go_bigtable' is not defined and referenced by '//storage/datastore:datastore'
1

There are 1 answers

0
Hussnain Ahmad On

you are adding the wrong import path, the correct import is "@com_google_cloud_go_bigtable//:bigtable". Your go_library should be like this

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
    name = "datastore_pkg",
    srcs = [
        "bigtable/database.go",
        "rpc/activity_rpc.go",
        "rpc/index_rpc.go",
        "rpc/user_rpc.go",
    ],
    importpath = "github.com/cliqueedge/go/storage/datastore",
    deps = [
        "//protos/v1:datastore_go_grpc",
        "@com_google_cloud_go_bigtable//:bigtable",
    ],
)

You should also look into gazelle on auto-updating your dependencies https://github.com/bazelbuild/bazel-gazelle