Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go package driver doesn't work with Go 1.18 #3080

Closed
linzhp opened this issue Mar 5, 2022 · 5 comments · Fixed by #3157
Closed

Go package driver doesn't work with Go 1.18 #3080

linzhp opened this issue Mar 5, 2022 · 5 comments · Fixed by #3157
Labels
IDE Go package driver and IDE support

Comments

@linzhp
Copy link
Contributor

linzhp commented Mar 5, 2022

Current package driver calls builder stdliblist to get information for std libraries. stdliblist calls go list:

// stdliblist runs `go list -json` on the standard library and saves it to a file.
func stdliblist(args []string) error {

This caused two problems:

  1. essentially, std libraries are compiled twice, one by rules_go and one by go list
  2. when stdliblist calls go list, it is in Bazel's sandbox, where all Go files of std libraries are symlinks. One of the Go files in 1.18 embeds a binary file, which would break when the binary file is a symlink, leading to errors like:
ERROR: /private/var/tmp/_bazel_zplin/db67431f618bf23018777556a2edc2eb/external/io_bazel_rules_go/BUILD.bazel:44:7: GoStdlibList external/io_bazel_rules_go/stdlib_/stdlib.pkg.json failed: (Exit 1): builder failed: error executing command 
  (cd /private/var/tmp/_bazel_zplin/db67431f618bf23018777556a2edc2eb/sandbox/darwin-sandbox/7496/execroot/__main__ && \
  exec env - \
    APPLE_SDK_PLATFORM=MacOSX \
    APPLE_SDK_VERSION_OVERRIDE=12.1 \
    CGO_ENABLED=1 \
    GOARCH=arm64 \
    GOOS=darwin \
    GOPATH='' \
    GOROOT=external/go_sdk \
    GOROOT_FINAL=GOROOT \
    PATH=external/local_config_cc:/bin:/usr/bin \
    XCODE_VERSION_OVERRIDE=13.2.1.13C100 \
    ZERO_AR_DATE=1 \
  bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/go_sdk/builder stdliblist -sdk external/go_sdk -installsuffix darwin_arm64 -out bazel-out/darwin_arm64-fastbuild/bin/external/io_bazel_rules_go/stdlib_/stdlib.pkg.json)
# Configuration: 3082a7bf331eaf230f27e04497eaecbe1891da6c723270a0d9c69754da9505e4
# Execution platform: @local_config_platform//:host

Use --sandbox_debug to see verbose messages from the sandbox
external/go_sdk/src/crypto/elliptic/p256_asm.go:24:12: pattern p256_asm_table.bin: cannot embed irregular file p256_asm_table.bin
stdliblist: error running subcommand external/go_sdk/bin/go: exit status 1

What version of rules_go are you using?

0.30

What version of Bazel are you using?

5.0.0

What version of Go are you using?

Go 1.18rc1

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

Yes

What operating system and processor architecture are you using?

macOS arm64

Any other potentially useful information about your toolchain?

@bolitt
Copy link

bolitt commented Mar 18, 2022

+1, I got a very similar bug with go 1.18 (stable, darwin_amd64) + bazel 5.0.0 + rules_go 0.30.

external/go_sdk/src/crypto/elliptic/p256_asm.go:24:12: pattern p256_asm_table.bin: cannot embed irregular file p256_asm_table.bin
bazel-out/host/bin/external/org_golang_x_mobile/cmd/gomobile/gomobile_/gomobile: go build -v -buildmode=c-shared -o=/var/folders/lm/g6r0qpk15dsdklyy9w35dh040000gp/T/gomobile-work-1280566553/android/src/main/jniLibs/arm64-v8a/libgojni.so gobind failed: exit status 1

@abhinav
Copy link
Contributor

abhinav commented Mar 18, 2022

@bolitt, try my patch #3083.

@jeongukjae
Copy link
Contributor

Same here. bazel 5.0.0 and rules_go v0.31.0

@esprehn
Copy link

esprehn commented May 12, 2022

@linzhp it looks like the new release bumps the golang version to 1.18.x but this fix didn't land, does that mean auto completion is now broken with the configuration suggested in the README.md?

@linzhp
Copy link
Contributor Author

linzhp commented May 12, 2022

Yeah, sorry, @xytan0056 may work on #3083 soon.

xytan0056 pushed a commit to xytan0056/rules_go that referenced this issue May 12, 2022
The stdliblist operation that the gopackagesdriver relies on fails on
Go 1.18rc1 with the following error:

```
external/go_sdk/src/crypto/elliptic/p256_asm.go:24:12: pattern p256_asm_table.bin: cannot embed irregular file p256_asm_table.bin
```

We see this failure because Bazel builds a symlink tree of the GOROOT run
`go list` with. However, since [CL 380475][1], the Go standard library uses
`go:embed` to embed a file in `crypto/elliptic`, but `go:embed` does not
support symlinks.

[1]: https://go.dev/cl/380475

Fix this by having stdliblist copy the relevant portions of the GOROOT to
run `go list` with. This matches [what the stdlib action does][2].

[2]: https://github.com/bazelbuild/rules_go/blob/e9a7054ff11a520e3b8aceb76a3ba44bb8da4c94/go/tools/builders/stdlib.go#L54-L57

Resolves bazelbuild#3080
@linzhp linzhp added the IDE Go package driver and IDE support label May 16, 2022
linzhp pushed a commit that referenced this issue May 19, 2022
…or stdliblist.go (#3157)

* stdliblist: Fix for Go 1.18 by replicating stdlib

The stdliblist operation that the gopackagesdriver relies on fails on
Go 1.18rc1 with the following error:

```
external/go_sdk/src/crypto/elliptic/p256_asm.go:24:12: pattern p256_asm_table.bin: cannot embed irregular file p256_asm_table.bin
```

We see this failure because Bazel builds a symlink tree of the GOROOT run
`go list` with. However, since [CL 380475][1], the Go standard library uses
`go:embed` to embed a file in `crypto/elliptic`, but `go:embed` does not
support symlinks.

[1]: https://go.dev/cl/380475

Fix this by having stdliblist copy the relevant portions of the GOROOT to
run `go list` with. This matches [what the stdlib action does][2].

[2]: https://github.com/bazelbuild/rules_go/blob/e9a7054ff11a520e3b8aceb76a3ba44bb8da4c94/go/tools/builders/stdlib.go#L54-L57

Resolves #3080

* test/stdlib: Depend on _list_json

Add a dependency on `GoStdLib._list_json` to the stdlib test.
This ensures that we can successfully build the JSON data needed by the
gopackagesdriver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment