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

runtime.godebugDefault handling doesn't work with gazelle/rules_go #1945

Open
zecke opened this issue Oct 5, 2024 · 1 comment
Open

runtime.godebugDefault handling doesn't work with gazelle/rules_go #1945

zecke opened this issue Oct 5, 2024 · 1 comment

Comments

@zecke
Copy link

zecke commented Oct 5, 2024

What version of gazelle are you using?

0.39.1

What version of rules_go are you using?

0.51.0

What version of Bazel are you using?

7.3.2

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

These should be the latest version

What operating system and processor architecture are you using?

AARCH64 and macos

What did you do?

I want to set the default value of a GODEBUG variable. According to the documentation there are three ways to do this:

  1. Use //go:debug somevalue=X before the package declaration
  2. Include it in the go.mod
  3. (Include it in the go.work)

What did you expect to see?

Trying first and second I expected the resulting binary to include the godebugDefault

What did you see instead?

Both the directive and the go.mod file have no impact on compiling the go binary.

More details and other observations

  • Interestingly bazel/rules_go allow me to link against the internal/godebug package while go build forbids this
  • go build would warn about unknown directive and when built with bazel it does not
  • Use x_defs and setting runtime.godebugDefault is a working workaround.

Reproducer set-up

$ cat MODULE.bazel
bazel_dep(name = "rules_go", version = "0.50.1")
bazel_dep(name = "gazelle", version = "0.39.1")


go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")

# Download an SDK for the host OS & architecture as well as common remote execution platforms.
go_sdk.download(version = "1.23.1")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")

$ cat BUILD.bazel
load("@gazelle//:def.bzl", "gazelle")
load("@rules_go//go:def.bzl", "go_binary", "go_library")

gazelle(name = "gazelle")

go_library(
    name = "godebug_lib",
    srcs = ["main.go"],
    importpath = "github.com/zecke/godebug",
    visibility = ["//visibility:private"],
)

go_binary(
    name = "godebug",
    embed = [":godebug_lib"],
    visibility = ["//visibility:public"],
    #x_defs = {
    #    "runtime.godebugDefault": "tlsrsakex=1",
    #},
)

$ cat main.go
//go:debug tlsrsakex=2
package main


import (
	"fmt"
	"internal/godebug"
)

func main() {
	g := godebug.New("tlsrsakex")
	fmt.Printf("%v is %v\n", g.Name(), g.Value())
}


$ cat go.mod
module github.com/zecke/godebug

go 1.23.1

godebug tlsrsakex=3
@zecke
Copy link
Author

zecke commented Oct 5, 2024

Running go build -n -x ./main.go the first occurrence of my debug statement is inside the modinfo statement of the importcfg.link and then this is passed to the linker via the -X=runtime.godebugDefault=...

zecke added a commit to zecke/bazel-gazelle that referenced this issue Oct 5, 2024
Go 1.21 introduced support for godebug lines in go.mod and go.work
files. Skip over these lines instead of failing

Related bazel-contrib#1945
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