bazel: bazel golang dependency build error
Description of the bug:
I’m trying to build a third party dependency with bazel (github.com/microsoftgraph/msgraph-sdk-go v0.42.0) https://github.com/microsoftgraph/msgraph-sdk-go. However, this third party dependency has a folder called “external” in it, which I think is bugging the bazel build system out. I reproduced the issue in a minimal bazel build configuration to confirm. I tried to build with the --experimental_sibling_repository_layout and --experimental_disable_external_package flags but neither fixed the error. The exact message when trying to create a bazel project and include the msgraph-sdk-go as a dependency is:
ERROR: /private/var/tmp/_bazel_user/66fd3004f0bb0404166f2e3be708ec70/external/com_github_microsoftgraph_msgraph_sdk_go/BUILD.bazel:3:11: no such target '//external:external': target 'external' not declared in package 'ext
ernal' defined by /Users/user/Desktop/bztest/WORKSPACE and referenced by '@com_github_microsoftgraph_msgraph_sdk_go//:msgraph-sdk-go'
ERROR: Analysis of target '//src:src' failed; build aborted:
I think the fix should be simple and involves passing one of those flags on the command line, but all the documentation I’ve seen does not seem to address the issue when it is a third party dependency using the external name. How might I build such a project?
What’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Create a bazel golang project and attempt to include github.com/microsoftgraph/msgraph-sdk-go v0.42.0 as a dependency in the go.mod file, then attempt to run bazel build //....
Which operating system are you running Bazel on?
macOS
What is the output of bazel info release?
release 5.3.0-homebrew
If bazel info release returns development version or (@non-git), tell us how you built Bazel.
No response
What’s the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?
fatal: not a git repository (or any of the parent directories): .git
Have you found anything relevant by searching the web?
I think this issue is related: https://github.com/bazelbuild/bazel/issues/16220
Any other information, logs, or outputs that you want to share?
root BUILD.bazel:
load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:prefix src/main.go
gazelle(name = "gazelle")
gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=go.mod",
"-to_macro=deps.bzl%go_dependencies",
"-prune",
],
command = "update-repos",
)
WORKSPACE:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "io_bazel_rules_go",
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
],
)
http_archive(
name = "bazel_gazelle",
sha256 = "501deb3d5695ab658e82f6f6f549ba681ea3ca2a5fb7911154b5aa45596183fa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.26.0/bazel-gazelle-v0.26.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.26.0/bazel-gazelle-v0.26.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("//:deps.bzl", "go_dependencies")
# gazelle:repository_macro deps.bzl%go_dependencies
go_dependencies()
go_rules_dependencies()
go_register_toolchains(version = "1.19.1")
gazelle_dependencies()
src/BUILD.bazel:
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:prefix github.com/example/project
gazelle(name = "gazelle")
go_library(
name = "project_lib",
srcs = ["main.go"],
importpath = "github.com/example/project",
visibility = ["//visibility:private"],
deps = [
"@com_github_azure_azure_sdk_for_go_sdk_azidentity//:go_default_library",
"@com_github_microsoftgraph_msgraph_sdk_go//:go_default_library",
],
)
go_binary(
name = "src",
embed = [":project_lib"],
visibility = ["//visibility:public"],
)
src/main.go:
package main
import (
azidentity "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
// a "github.com/microsoft/kiota-authentication-azure-go"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
"context"
"fmt"
)
func main() {
fmt.Println("running!\n")
cred, err := azidentity.NewDeviceCodeCredential(&azidentity.DeviceCodeCredentialOptions{
TenantID: "<the tenant id from your app registration>",
ClientID: "<the client id from your app registration>",
UserPrompt: func(ctx context.Context, message azidentity.DeviceCodeMessage) error {
fmt.Println(message.Message)
return nil
},
})
if err != nil {
fmt.Printf("Error creating credentials: %v\n", err)
}
_ , err = msgraphsdk.NewGraphServiceClientWithCredentials(cred, []string{"Files.Read"})
if err != nil {
fmt.Printf("Error creating client: %v\n", err)
return
}
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (10 by maintainers)
The module query mechanism is entirely based on the new Bzlmod resolution result, we don’t require the
//externalpackage.bindis also not supported in Bzlmod. So I don’t see any blocker from Bzlmod side.I think we can try to rename this with an incompatible flag, the migration would only be easier if Bzlmod is widely adopted.