bazel-contrib / bazel-contrib/rules_go

gopackagesdriver ignores the GOEXPERIMENT config of the Go toolchain

Open
#4,115 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

When using Go SDK >= 1.20, `nocoverageredesign` is always used in **GOEXPERIMENT** ([go/private/sdk.bzl#L504-L508](https://github.com/bazelbuild/rules_go/blob/master/go/private/sdk.bzl#L504-L508)).
And the `stdlib` and `stdliblist` is generated using this Go env:

``` bash
$ bazel build \
--aspects=@rules_go//go/tools/gopackagesdriver:aspect.bzl%go_pkg_info_aspect \
--output_groups=go_pkg_driver_stdlib_json_file \
@rules_go//:stdlib
$ jq -r 'select(.Name == "goexperiment") | .GoFiles[]' <'bazel-bin/external/rules_go+/stdlib_/stdlib.pkg.json' | \
grep coverageredesign
__BAZEL_OUTPUT_BASE__/external/rules_go++go_sdk+go_sdk/src/internal/goexperiment/exp_coverageredesign_off.go
```

But `gopackagesdriver` does not return this source file of the `goexperiment` stdlib package:

``` bash
$ echo '{}' | bazel run @rules_go//go/tools/gopackagesdriver builtin | \
jq -r '.Packages[] | select(.Name == "goexperiment") | .GoFiles[]' | \
grep coverageredesign
...
# exp_coverageredesign_off.go file is missing
```
`gopackagesdriver` (and maybe `//go/tools/go_bin_runner` ?) should use the **GOEXPERIMENT** (and certainly also **CGO_ENABLED**) env variable of the Go SDK to initialize the build context to filter all files.

This breach breaks the load of a package with `packages.Load()` with tests:

``` text
/external/rules_go++go_sdk+go_sdk/src/testing/cover.go:50:18: undefined: goexperiment.CoverageRedesign
/external/rules_go++go_sdk+go_sdk/src/testing/cover.go:85:18: undefined: goexperiment.CoverageRedesign
/external/rules_go++go_sdk+go_sdk/src/testing/newcover.go:40:19: undefined: goexperiment.CoverageRedesign
/external/rules_go++go_sdk+go_sdk/src/testing/testing.go:670:18: undefined: goexperiment.CoverageRedesign
````

A dirty hack solution is to manually add `export GOEXPERIMENT=nocoverageredesign` in the `gopackagesdriver` wrapper script.

---

- **rules_go**: `v0.50.1`
- **bazel**: `7.3.1`
- **go_sdk**: `1.23.1`

Contributor guide

Open the contributing guide

Research direction

Start with the GOEXPERIMENT setup in go/private/sdk.bzl#L504-L508 and the go/tools/gopackagesdriver entry point; reproduce the stdlib and builtin commands from the issue. Check whether go/tools/go_bin_runner is also involved, then verify that the generated goexperiment files and packages.Load() no longer produce the listed CoverageRedesign errors while respecting the Go SDK environment.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.