rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

rules_go doesn't compile org_golang_google_api

Open FilipNikolovski opened this issue 1 year ago • 2 comments

What version of rules_go are you using?

v0.40.1

What version of gazelle are you using?

v0.30.0

What version of Bazel are you using?

6.2.1

Does this issue reproduce with the latest releases of all the above?

Yes, I'm using the latest releases. Tried with older releases as well, it doesn't work.

What operating system and processor architecture are you using?

Fedora Linux 38 (Workstation Edition) Linux 6.3.12-200.fc38.x86_64

Any other potentially useful information about your toolchain?

What did you do?

google.golang.org/api is imported as a indirect dependency, from github.com/awa/go-iap.

The versions that are in go.mod are the following:

github.com/awa/go-iap v1.20.0

golang.org/x/oauth2 v0.10.0 // indirect google.golang.org/api v0.131.0 // indirect

Using gazelle I am updating the WORKSPACE file like so:

bazelisk run gazelle -- update-repos -from_file=go.mod -prune

In the WORKSPACE file the repositories show up correctly:

go_repository(
    name = "com_github_awa_go_iap",
    importpath = "github.com/awa/go-iap",
    sum = "h1:e2jrO0ZpMOe++TMk/oLENtN5YY1ep11fxk5j00zYZuk=",
    version = "v1.20.0",
)

go_repository(
    name = "org_golang_x_oauth2",
    importpath = "golang.org/x/oauth2",
    sum = "h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8=",
    version = "v0.10.0",
)

go_repository(
    name = "org_golang_google_api",
    importpath = "google.golang.org/api",
    sum = "h1:AcgWS2edQ4chVEt/SxgDKubVu/9/idCJy00tBGuGB4M=",
    version = "v0.131.0",
)

What did you expect to see?

Running bazelisk build //... should build the Go programs correctly.

What did you see instead?

ERROR: ~/.cache/bazel/_bazel_/2d74203f21675cf2d82239d122954e21/external/org_golang_google_api/internal/BUILD.bazel:3:11: GoCompilePkg external/org_golang_google_api/internal/internal.a failed: (Exit 1): builder failed: error executing command (from target @org_golang_google_api//internal:internal) 
  (cd ~/.cache/bazel/_bazel_/2d74203f21675cf2d82239d122954e21/sandbox/linux-sandbox/2185/execroot/__main__ && \
  exec env - \
    CGO_ENABLED=0 \
    GOARCH=amd64 \
    GOEXPERIMENT=nocoverageredesign \
    GOOS=linux \
    GOPATH='' \
    GOROOT=bazel-out/k8-fastbuild-ST-117c271ba47d/bin/external/io_bazel_rules_go/stdlib_ \
    GOROOT_FINAL=GOROOT \
  bazel-out/k8-opt-exec-2B5CBBC6-ST-9f03a228ad69/bin/external/go_sdk/builder_reset/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src external/org_golang_google_api/internal/cba.go -src external/org_golang_google_api/internal/conn_pool.go -src external/org_golang_google_api/internal/creds.go -src external/org_golang_google_api/internal/s2a.go -src external/org_golang_google_api/internal/settings.go -src external/org_golang_google_api/internal/version.go -embedroot '' -embedroot bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin -embedlookupdir external/org_golang_google_api/internal -arc 'google.golang.org/api/internal/cert=google.golang.org/api/internal/cert=bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin/external/org_golang_google_api/internal/cert/cert.x' -arc 'google.golang.org/api/internal/impersonate=google.golang.org/api/internal/impersonate=bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin/external/org_golang_google_api/internal/impersonate/impersonate.x' -arc 'github.com/google/s2a-go=github.com/google/s2a-go=bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin/external/com_github_google_s2a_go/s2a-go.x' -arc 'github.com/google/s2a-go/fallback=github.com/google/s2a-go/fallback=bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin/external/com_github_google_s2a_go/fallback/fallback.x' -arc 'cloud.google.com/go/compute/metadata=cloud.google.com/go/compute/metadata=bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin/external/com_google_cloud_go_compute_metadata/metadata.x' -arc 'google.golang.org/grpc=google.golang.org/grpc=bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin/external/org_golang_google_grpc/grpc.x' -arc 'google.golang.org/grpc/credentials=google.golang.org/grpc/credentials=bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin/external/org_golang_google_grpc/credentials/credentials.x' -arc 'golang.org/x/oauth2=golang.org/x/oauth2=bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin/external/org_golang_x_oauth2/oauth2.x' -arc 'golang.org/x/oauth2/google=golang.org/x/oauth2/google=bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin/external/org_golang_x_oauth2/google/google.x' -importpath google.golang.org/api/internal -p google.golang.org/api/internal -package_list bazel-out/k8-opt-exec-2B5CBBC6-ST-9f03a228ad69/bin/external/go_sdk/packages.txt -o bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin/external/org_golang_google_api/internal/internal.a -x bazel-out/k8-fastbuild-ST-3fe94e20a0cf/bin/external/org_golang_google_api/internal/internal.x -gcflags '' -asmflags '')
# Configuration: 541965a0131a92f42d5ecdba6c8d000b52a3d56cc4043a56f2bf4d1c984cc17a
# Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
external/org_golang_google_api/internal/creds.go:89:20: undefined: google.CredentialsParams
external/org_golang_google_api/internal/creds.go:107:22: undefined: google.CredentialsFromJSONWithParams
external/org_golang_google_api/internal/creds.go:148:17: undefined: google.JWTAccessTokenSourceWithScope
external/org_golang_google_api/internal/creds.go:196:35: undefined: google.MTLSTokenURL
compilepkg: error running subcommand external/go_sdk/pkg/tool/linux_amd64/compile: exit status 2
(12:46:14) INFO: Elapsed time: 440.160s, Critical Path: 121.64s
(12:46:14) INFO: 2276 processes: 91 internal, 2185 linux-sandbox.

FilipNikolovski avatar Jul 13 '23 10:07 FilipNikolovski

Ultimately I tracked this down to gazelle including a very old golang.org/x/oauth2 by default.

I was able to work around it by following Gazelle's instructions to include my own go_repository rules before pulling in Gazelle dependencies:

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

############################################################
# Define your own dependencies here using go_repository.
# Else, dependencies declared by rules_go/gazelle will be used.
# The first declaration of an external repository "wins".
############################################################

go_rules_dependencies()

go_register_toolchains(version = "1.20.5")

gazelle_dependencies()

I honestly think these instructions have evolved since I first started using rules_go/gazelle in my repo.

bdhess avatar Sep 26 '23 13:09 bdhess

Adding:

go_repository(
    name = "org_golang_x_oauth2",
    importpath = "golang.org/x/oauth2",
    sum = "h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4=",
    version = "v0.12.0",
)

before go_rules_dependencies() and gazelle_dependencies() seems to have fixed the issue. Thanks!

FilipNikolovski avatar Sep 27 '23 08:09 FilipNikolovski