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

gopackagesdriver ignores the GOEXPERIMENT config of the Go toolchain #4115

Open
lbcjbb opened this issue Sep 21, 2024 · 0 comments
Open

gopackagesdriver ignores the GOEXPERIMENT config of the Go toolchain #4115

lbcjbb opened this issue Sep 21, 2024 · 0 comments

Comments

@lbcjbb
Copy link
Contributor

lbcjbb commented Sep 21, 2024

When using Go SDK >= 1.20, nocoverageredesign is always used in GOEXPERIMENT (go/private/sdk.bzl#L504-L508).
And the stdlib and stdliblist is generated using this Go env:

$ 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:

$ 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:

<output_base>/external/rules_go++go_sdk+go_sdk/src/testing/cover.go:50:18: undefined: goexperiment.CoverageRedesign
<output_base>/external/rules_go++go_sdk+go_sdk/src/testing/cover.go:85:18: undefined: goexperiment.CoverageRedesign
<output_base>/external/rules_go++go_sdk+go_sdk/src/testing/newcover.go:40:19: undefined: goexperiment.CoverageRedesign
<output_base>/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant