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

rules_go now requires rulesGoStdlibPrefix to be set via -X #421

Closed
malt3 opened this issue Sep 28, 2023 · 2 comments · Fixed by #422
Closed

rules_go now requires rulesGoStdlibPrefix to be set via -X #421

malt3 opened this issue Sep 28, 2023 · 2 comments · Fixed by #422

Comments

@malt3
Copy link
Collaborator

malt3 commented Sep 28, 2023

Describe the bug

rules_go is planning a new release (0.42). This new release will contain the following change: bazel-contrib/rules_go#3701.

It leads to this error when using the go toolchain provided by rules_nixpkgs:

ERROR: /home/malte/.cache/bazel/_bazel_malte/bb1175a64d2f0f71785aea697a0484ea/external/io_bazel_rules_go/BUILD.bazel:42:7: GoStdlib external/io_bazel_rules_go/stdlib_/pkg failed: (Exit 2): builder failed: error executing command (from target @io_bazel_rules_go//:stdlib) 
  (cd /home/malte/.cache/bazel/_bazel_malte/bb1175a64d2f0f71785aea697a0484ea/sandbox/linux-sandbox/80/execroot/constellation && \
  exec env - \
    CGO_ENABLED=0 \
    GOARCH=amd64 \
    GOEXPERIMENT='' \
    GOOS=linux \
    GOPATH='' \
    GOROOT=external/go_sdk \
    GOROOT_FINAL=GOROOT \
    GOTOOLCHAIN=local \
    PATH=external/zig_sdk/tools:external/zig_sdk/tools/x86_64-linux-gnu.2.23:/bin:/usr/bin \
  bazel-out/k8-opt-exec-C7777A24-ST-e336f88b9a0e/bin/external/go_sdk/builder stdlib -sdk external/go_sdk -installsuffix linux_amd64 -tags netgo,netgo -out bazel-out/k8-opt-ST-04e6e76229c2/bin/external/io_bazel_rules_go/stdlib_ -package std -gcflags '')
# Configuration: 4114e72d42dffca035c92c4853a59204220a10d133544398bcba8b927789b8dc
# Execution platform: @rules_nixpkgs_core//platforms:host

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
panic: rulesGoStdlibPrefix should have been set via -X

goroutine 1 [running]:
main.init.0()
        ./stdliblist.go:113 +0x31

To Reproduce
Steps to reproduce the behavior.

Use rules_go >= bazel-contrib/rules_go@c2406b2
And rules_nixpkgs with nixpkgs_go_configure.

Expected behavior

Builds should succeed.

Environment

  • OS name + version: Ubuntu 22.04
  • Version of the code: 7e627d7

Additional context

Happy to provide a fix. As of now, I just don't understand where to take the stdlib prefix from (or if rules_nixpkgs even provides this)

@DolceTriade
Copy link
Contributor

For now, we just use this as a local patch which isn't great.

Do you think we can use https://github.com/bazelbuild/rules_go/blob/4211c6d32ee475a8fde1cfc91571e7c0bed67af4/go/def.bzl#L122

to optionally add the extra ldflag or not?

maybe something like (untested...)

load(@{rules_go}//go/def.bzl, "RULES_GO_VERSION")

go_tool_binary(
    name = "builder",
    srcs = ["@{rules_go}//go/tools/builders:builder_srcs"],
    ldflags = "-X main.rulesGoStdlibPrefix=@{rules_go}//stdlib:" if int(RULES_GO_VERSION.split(".")[1]) >= 42 else "",
    sdk = ":go_sdk",
)

@malt3
Copy link
Collaborator Author

malt3 commented Oct 31, 2023

Something like that may work. This is certainly not something you want to maintain forever, but maybe we could add this with a note that it should be removed after some grace period?
We could even print a warning from Starlark if an old rules_go version is detected.

avdv added a commit to avdv/replay that referenced this issue May 18, 2024
rules_haskell 0.19 depends on rules_nixpkgs 0.10, but we need the fix
tweag/rules_nixpkgs#421 to avoid error:

```
panic: rulesGoStdlibPrefix should have been set via -X
```

Also, load only the needed toolchain rules from rules_nixpkgs.
avdv added a commit to avdv/replay that referenced this issue May 18, 2024
rules_haskell 0.19 depends on rules_nixpkgs 0.10, but we need the fix
tweag/rules_nixpkgs#421 to avoid error:

```
panic: rulesGoStdlibPrefix should have been set via -X
```

Also, load only the needed toolchain rules from rules_nixpkgs.
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

Successfully merging a pull request may close this issue.

2 participants