diff --git a/MODULE.bazel b/MODULE.bazel index 4273421772f..84cf44c97b3 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -16,7 +16,20 @@ python.toolchain( ) bazel_dep(name = "zlib", version = "1.3") -bazel_dep(name = "rules_go", version = "0.46.0", repo_name = "io_bazel_rules_go") +bazel_dep(name = "rules_go", version = "0.47.0", repo_name = "io_bazel_rules_go") +archive_override( + module_name = "rules_go", + integrity = "sha256-r0fzDpy9cK405Jhm4gGz93Bpq7ERGD8sApfn50umu8A=", + patch_strip = 1, + patches = [ + # TODO(sluongng): remove after https://github.com/bazelbuild/rules_go/pull/3929 + "@@//buildpatches:rules_go_signal.patch", + ], + urls = [ + "https://github.com/bazelbuild/rules_go/releases/download/v0.47.0/rules_go-v0.47.0.zip", + ], +) + bazel_dep(name = "gazelle", version = "0.35.0", repo_name = "bazel_gazelle") archive_override( module_name = "gazelle", @@ -31,29 +44,8 @@ archive_override( ], ) -# TODO: Remove explicit `goarch`/`goos` once rules_go v0.47.0 is released: -# https://github.com/bazelbuild/rules_go/commit/145b042e21a073fa3637c096bf9779cdbcac6f75 go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk") -go_sdk.download( - goarch = "arm64", - goos = "linux", - version = "1.22.1", -) -go_sdk.download( - goarch = "amd64", - goos = "linux", - version = "1.22.1", -) -go_sdk.download( - goarch = "arm64", - goos = "darwin", - version = "1.22.1", -) -go_sdk.download( - goarch = "amd64", - goos = "darwin", - version = "1.22.1", -) +go_sdk.download(version = "1.22.2") go_sdk.nogo(nogo = "@//:vet") use_repo( go_sdk, diff --git a/WORKSPACE b/WORKSPACE index 8afbeaac79f..5752533a5e9 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -20,10 +20,15 @@ http_archive( # keep in sync with go.mod http_archive( name = "io_bazel_rules_go", - sha256 = "80a98277ad1311dacd837f9b16db62887702e9f1d1c4c9f796d0121a46c8e184", + patch_args = ["-p1"], + patches = [ + # TODO(sluongng): remove after https://github.com/bazelbuild/rules_go/pull/3929 + "//buildpatches:rules_go_signal.patch", + ], + sha256 = "af47f30e9cbd70ae34e49866e201b3f77069abb111183f2c0297e7e74ba6bbc0", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip", + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.47.0/rules_go-v0.47.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.47.0/rules_go-v0.47.0.zip", ], ) diff --git a/buildpatches/rules_go_signal.patch b/buildpatches/rules_go_signal.patch new file mode 100644 index 00000000000..f61bc160433 --- /dev/null +++ b/buildpatches/rules_go_signal.patch @@ -0,0 +1,32 @@ +commit 1e8d3b15930fc2d97c6b2a53e862bcb52c6d81f9 +Author: Son Luong Ngoc +Date: Mon Apr 29 11:35:20 2024 +0200 + + bzltestutil: restore timeout signal handler + + In https://github.com/bazelbuild/rules_go/pull/3920, a new mechanism to + handle test timeout was introduced. However this broke existing tests + that use SIGTERM inside. + + Restore the original behavior. + +diff --git a/go/tools/builders/generate_test_main.go b/go/tools/builders/generate_test_main.go +index f5b5fcce..b85614ba 100644 +--- a/go/tools/builders/generate_test_main.go ++++ b/go/tools/builders/generate_test_main.go +@@ -247,7 +247,14 @@ func main() { + // period (15s) expires. + // If TEST_TIMEOUT is not set (e.g., when the test binary is run by Delve for debugging), we don't + // ignore SIGTERM so it can be properly terminated. +- signal.Ignore(syscall.SIGTERM) ++ // We do not panic (like native go test does) because users may legitimately want to use SIGTERM ++ // in tests. ++ // See https://github.com/golang/go/blob/e816eb50140841c524fd07ecb4eaa078954eb47c/src/testing/testing.go#L2351 ++ c := make(chan os.Signal, 1) ++ signal.Notify(c, syscall.SIGTERM) ++ go func() { ++ <-c ++ }() + } + + {{if not .TestMain}}