Wrong go package version downloaded - why?

324 views
Skip to first unread message

Filip Filmar

unread,
Sep 7, 2023, 11:00:52 AM9/7/23
to bazel-discuss
Hi folks!

I am seeing a very curious behavior in my test project at: https://github.com/filmil/bazel-experiments/tree/main/wasm

Nominally, the project is using the package `golang.org/x/oauth2` (see here)

When I try to compile the project, I get the following error:

```
┬─[filmil@instance-3:~/code/bazel-experiments/wasm]─[10:05:08]
│ (g/b:main)
╰─>$ bazel run //server
INFO: Analyzed target //server:server (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /home/filmil/.cache/bazel/_bazel_filmil/0a5db0d5b5a6ce76c9fc901c2683ec4b/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) bazel-out/k8-opt-exec-2B5CBBC6/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 ... (remaining 47 arguments skipped)

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
Target //server:server failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.821s, Critical Path: 0.29s
INFO: 17 processes: 17 internal.
FAILED: Build did NOT complete successfully
ERROR: Build failed. Not running target
┬─[filmil@instance-3:~/code/bazel-experiments/wasm]─[10:05:11]
│ (g/b:main)
╰─>$ 
```

Examining the file `default.go` from the external repos, one can see that the file `default.go` is obviously *not* the correct file. It's *much* older than what was released in v0.12.0.


This is what bazel has provided. You can note that the import list is different, and the adcSetupURL does not exist etc.  The file downloaded by bazel is from at least ~November 2018 apparently: https://cs.opensource.google/go/x/oauth2/+/5a69e67f3fa6ce11b512c271912d08ac74da7c7f:google/default.go;bpv=1 vs. what it should be (Aug 2023).

`go.mod` declares the need for v0.12.0 as it should, and the .bzl file generated by gazelle seems to match.  But neither of the two seem to correspond to what's being downloaded.

Ideas as to what is going on? This doesn't seem like correct behavior, and I'm not seeing an obvious issue with the bazel setup. It should be easy to corroborate by cloning my repo and running "bazel run //server from the wasm dir".

┬─[filmil@instance-3:~/code/bazel-experiments/wasm/bazel-wasm/external/org_golang_x_oauth2/google]─[10:02:19]
╰─>$ cat default.go | head -n 30
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package google

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"runtime"

"cloud.google.com/go/compute/metadata"
"golang.org/x/net/context"
"golang.org/x/oauth2"
)

// DefaultClient returns an HTTP Client that uses the
// DefaultTokenSource to obtain authentication credentials.
func DefaultClient(ctx context.Context, scope ...string) (*http.Client, error) {
ts, err := DefaultTokenSource(ctx, scope...)
if err != nil {
return nil, err
}
return oauth2.NewClient(ctx, ts), nil
}

┬─[filmil@instance-3:~/code/bazel-experiments/wasm/bazel-wasm/external/org_golang_x_oauth2/google]─[10:02:30]
╰─>$ 

Bradley Hess

unread,
Sep 20, 2023, 9:59:10 AM9/20/23
to bazel-discuss
This looks the same as https://github.com/bazelbuild/rules_go/issues/3624 - I am also curious about how it can be resolved.

Fabian Meumertzheim

unread,
Sep 20, 2023, 11:50:53 AM9/20/23
to Bradley Hess, bazel-discuss
rules_go and gazelle used to hardcode resolutions for "go_googleapis", but stopped doing so in recent releases precisely because of perplexing issues like this.

Could you try updating rules_go and gazelle to the latest version? That may require adding some more Gazelle directives to control proto resolution, but once you have figured those out, updating any repo should just work without having to update rules.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/496e6571-3655-4126-bb17-fcc95b944693n%40googlegroups.com.

Bradley Hess

unread,
Sep 20, 2023, 12:56:12 PM9/20/23
to Fabian Meumertzheim, bazel-discuss
This is with the latest rules_go (v0.41.0) and gazelle (v0.33.0).

Note that the dependency that's failing here is google.golang.org/api - not github.com/googleapis/googleapis (the historic go_googleapis)

Bradley Hess

unread,
Sep 20, 2023, 12:57:56 PM9/20/23
to Fabian Meumertzheim, Chris Smith, bazel-discuss
Reply all
Reply to author
Forward
0 new messages