Skip to content

Commit

Permalink
Upgrade rules_go to v0.47.0 (#6436)
Browse files Browse the repository at this point in the history
  • Loading branch information
sluongng authored Apr 30, 2024
1 parent a43d884 commit ee29cfb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 26 deletions.
38 changes: 15 additions & 23 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
32 changes: 32 additions & 0 deletions buildpatches/rules_go_signal.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
commit 1e8d3b15930fc2d97c6b2a53e862bcb52c6d81f9
Author: Son Luong Ngoc <sluongng@gmail.com>
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}}

0 comments on commit ee29cfb

Please sign in to comment.