bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.35k stars 635 forks source link

`GoLink` for Gazelle fails on Go 1.20 or greater #3937

Open sin-ack opened 1 month ago

sin-ack commented 1 month ago

What version of rules_go are you using?

rules_go via 0.41.0 through bazel-gazelle 0.32.0, but any later version also fails.

What version of gazelle are you using?

0.32.0

What version of Bazel are you using?

7.1.1

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

Yes.

What operating system and processor architecture are you using?

Gentoo Linux amd64

Any other potentially useful information about your toolchain?

$ gcc --version
gcc (Gentoo Hardened 13.2.1_p20240210 p14) 13.2.1 20240210
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ ld.lld --version
LLD 17.0.6 (compatible with GNU linkers)

What did you do?

I am working on a ruleset that depends on Gazelle for Starlark library management. I used bazel-contrib/rules-template as a basis for my ruleset, which included bazel-gazelle 0.35.0. Running this tool on my computer always fails with the error I listed below. I've narrowed down the issue to rules_go commit 58534a2cda8e546a4dec6ea9c6b64eb0bfe824dd, which updates the Go version from 1.19.8 to 1.20.2. Reverting this change with a local_path_override will make the build work properly.

Here's the minimal set of files that cause the error on my system:

# MODULE.bazel
bazel_dep(name = "gazelle", version = "0.36.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True)

# BUILD.bazel
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")

gazelle_binary(
    name = "gazelle_bin",
    languages = ["@bazel_skylib_gazelle_plugin//bzl"],
)

gazelle(
    name = "gazelle",
    gazelle = "gazelle_bin",
)

What did you expect to see?

Gazelle running normally.

What did you see instead?

$ bazel run //:gazelle --verbose_failures                                                                                                                                                                        1 ↵
INFO: Analyzed target //:gazelle (0 packages loaded, 0 targets configured).
ERROR: /home/agni/tmp/rules-go-repro/BUILD.bazel:3:15: GoLink gazelle_bin_/gazelle_bin [for tool] failed: (Exit 1): builder failed: error executing GoLink command (from target //:gazelle_bin) 
  (cd /home/agni/.cache/bazel/_bazel_agni/98623838173c98230990c7c2732aafbc/sandbox/linux-sandbox/86/execroot/_main && \
  exec env - \
    CGO_ENABLED=1 \
    GOARCH=amd64 \
    GOEXPERIMENT=nocoverageredesign \
    GOOS=linux \
    GOPATH='' \
    GOROOT=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/rules_go~/stdlib_ \
    GOROOT_FINAL=GOROOT \
    GOTOOLCHAIN=local \
    PATH=/usr/bin:/bin \
    ZERO_AR_DATE=1 \
  bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/rules_go~~go_sdk~go_default_sdk/builder_reset/builder link -sdk external/rules_go~~go_sdk~go_default_sdk -installsuffix linux_amd64 -arc '@@gazelle~~go_deps~com_github_bazelbuild_buildtools//tables:tables=github.com/bazelbuild/buildtools/tables=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~~go_deps~com_github_bazelbuild_buildtools/tables/tables.a' -arc '@@gazelle~~go_deps~com_github_bazelbuild_buildtools//build:build=github.com/bazelbuild/buildtools/build=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~~go_deps~com_github_bazelbuild_buildtools/build/build.a' -arc '@@gazelle~//internal/module:module=github.com/bazelbuild/bazel-gazelle/internal/module=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/internal/module/module.a' -arc '@@gazelle~//internal/wspace:wspace=github.com/bazelbuild/bazel-gazelle/internal/wspace=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/internal/wspace/wspace.a' -arc '@@gazelle~//pathtools:pathtools=github.com/bazelbuild/bazel-gazelle/pathtools=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/pathtools/pathtools.a' -arc '@@gazelle~//label:label=github.com/bazelbuild/bazel-gazelle/label=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/label/label.a' -arc '@@gazelle~//rule:rule=github.com/bazelbuild/bazel-gazelle/rule=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/rule/rule.a' -arc '@@gazelle~//config:config=github.com/bazelbuild/bazel-gazelle/config=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/config/config.a' -arc '@@gazelle~~go_deps~org_golang_x_mod//internal/lazyregexp:lazyregexp=golang.org/x/mod/internal/lazyregexp=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~~go_deps~org_golang_x_mod/internal/lazyregexp/lazyregexp.a' -arc '@@gazelle~~go_deps~org_golang_x_mod//semver:semver=golang.org/x/mod/semver=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~~go_deps~org_golang_x_mod/semver/semver.a' -arc '@@gazelle~~go_deps~org_golang_x_mod//module:module=golang.org/x/mod/module=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~~go_deps~org_golang_x_mod/module/module.a' -arc '@@gazelle~~go_deps~org_golang_x_mod//modfile:modfile=golang.org/x/mod/modfile=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~~go_deps~org_golang_x_mod/modfile/modfile.a' -arc '@@gazelle~~go_deps~org_golang_x_sys//execabs:execabs=golang.org/x/sys/execabs=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~~go_deps~org_golang_x_sys/execabs/execabs.a' -arc '@@gazelle~~go_deps~org_golang_x_tools_go_vcs//:vcs=golang.org/x/tools/go/vcs=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~~go_deps~org_golang_x_tools_go_vcs/vcs.a' -arc '@@gazelle~//repo:repo=github.com/bazelbuild/bazel-gazelle/repo=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/repo/repo.a' -arc '@@gazelle~//resolve:resolve=github.com/bazelbuild/bazel-gazelle/resolve=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/resolve/resolve.a' -arc '@@gazelle~//language:language=github.com/bazelbuild/bazel-gazelle/language=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/language/language.a' -arc '@@bazel_skylib_gazelle_plugin~//bzl:bzl=github.com/bazelbuild/bazel-skylib/gazelle=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/bazel_skylib_gazelle_plugin~/bzl/bzl.a' -arc '@@gazelle~//flag:flag=github.com/bazelbuild/bazel-gazelle/flag=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/flag/flag.a' -arc '@@gazelle~//internal/version:version=github.com/bazelbuild/bazel-gazelle/internal/version=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/internal/version/version.a' -arc '@@gazelle~//language/proto:proto=github.com/bazelbuild/bazel-gazelle/language/proto=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/language/proto/proto.a' -arc '@@gazelle~~go_deps~org_golang_x_sync//errgroup:errgroup=golang.org/x/sync/errgroup=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~~go_deps~org_golang_x_sync/errgroup/errgroup.a' -arc '@@gazelle~//language/go:go=github.com/bazelbuild/bazel-gazelle/language/go=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/language/go/go.a' -arc '@@gazelle~//merger:merger=github.com/bazelbuild/bazel-gazelle/merger=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/merger/merger.a' -arc '@@gazelle~~go_deps~com_github_bmatcuk_doublestar_v4//:doublestar=github.com/bmatcuk/doublestar/v4=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~~go_deps~com_github_bmatcuk_doublestar_v4/doublestar.a' -arc '@@gazelle~//walk:walk=github.com/bazelbuild/bazel-gazelle/walk=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~/walk/walk.a' -arc '@@gazelle~~go_deps~com_github_pmezard_go_difflib//difflib:difflib=github.com/pmezard/go-difflib/difflib=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/gazelle~~go_deps~com_github_pmezard_go_difflib/difflib/difflib.a' -package_list bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/rules_go~~go_sdk~go_default_sdk/packages.txt -o bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/gazelle_bin_/gazelle_bin -main bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/gazelle_bin.a -p gazelle_bin -- -extld /usr/bin/gcc '-buildid=redacted' -s -w -extldflags '-fuse-ld=lld -B/usr/bin -Wl,-no-as-needed -Wl,-z,relro,-z,now -pass-exit-codes -Wl,--push-state,-as-needed -Wl,--pop-state -Wl,--push-state,-as-needed -lm -Wl,--pop-state')
# Configuration: 102280fdd81a7e38c52bb68961161910f5590170eb28aace553b527e00995a6b
# 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/rules_go~~go_sdk~go_default_sdk/pkg/tool/linux_amd64/link: running /usr/bin/gcc failed: exit status 1
collect2: fatal error: cannot find 'ld'
compilation terminated.

link: error running subcommand GOROOT_FINAL=GOROOT \
GOROOT=bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/rules_go~/stdlib_ \
PATH=/usr/bin:/bin \
GOPATH= \
GOEXPERIMENT=nocoverageredesign \
GOTOOLCHAIN=local \
TMPDIR=/tmp \
CGO_ENABLED=1 \
GOOS=linux \
ZERO_AR_DATE=1 \
GOARCH=amd64 \
external/rules_go~~go_sdk~go_default_sdk/pkg/tool/linux_amd64/link -importcfg /tmp/bazel-working-directory/_main/bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/gazelle_bin_/importcfg1481826981 -o /tmp/bazel-working-directory/_main/bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/gazelle_bin_/gazelle_bin -extld /usr/bin/gcc -buildid=redacted -s -w -extldflags "-fuse-ld=lld -B/usr/bin -Wl,-no-as-needed -Wl,-z,relro,-z,now -pass-exit-codes -Wl,--push-state,-as-needed -Wl,--pop-state -Wl,--push-state,-as-needed -lm -Wl,--pop-state" /tmp/bazel-working-directory/_main/bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/gazelle_bin.a: exit status 2
Target //:gazelle failed to build
INFO: Elapsed time: 0.263s, Critical Path: 0.15s
INFO: 2 processes: 2 internal.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target
sin-ack commented 1 month ago

As a workaround, gazelle version 0.31.0 works fine at the moment (because it has rules_go 0.39.1).

fmeum commented 3 weeks ago

This could be related to https://github.com/bazelbuild/bazel/issues/21334#issuecomment-1986027778.