diff --git a/MODULE.bazel b/MODULE.bazel
index fddd15c428..0077a5ae7e 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,6 @@
module(
name = "rules_go",
- version = "0.47.0",
+ version = "0.47.1",
compatibility_level = 0,
repo_name = "io_bazel_rules_go",
)
diff --git a/docs/go/core/rules.md b/docs/go/core/rules.md
index 3dd32e775b..1cca1c7034 100644
--- a/docs/go/core/rules.md
+++ b/docs/go/core/rules.md
@@ -171,7 +171,7 @@ This builds an executable from a set of source files,
| pgoprofile | Provides a pprof file to be used for profile guided optimization when compiling go targets. A pprof file can also be provided via --@io_bazel_rules_go//go/config:pgoprofile=<label of a pprof file>
. Profile guided optimization is only supported on go 1.20+. See https://go.dev/doc/pgo for more information. | Label | optional | //go/config:empty |
| pure | Controls whether cgo source code and dependencies are compiled and linked, similar to setting CGO_ENABLED
. May be one of on
, off
, or auto
. If auto
, pure mode is enabled when no C/C++ toolchain is configured or when cross-compiling. It's usually better to control this on the command line with --@io_bazel_rules_go//go/config:pure
. See [mode attributes], specifically [pure]. | String | optional | "auto" |
| race | Controls whether code is instrumented for race detection. May be one of on
, off
, or auto
. Not available when cgo is disabled. In most cases, it's better to control this on the command line with --@io_bazel_rules_go//go/config:race
. See [mode attributes], specifically [race]. | String | optional | "auto" |
-| srcs | The list of Go source files that are compiled to create the package. Only .go
and .s
files are permitted, unless the cgo
attribute is set, in which case, .c .cc .cpp .cxx .h .hh .hpp .hxx .inc .m .mm
files are also permitted. Files may be filtered at build time using Go [build constraints]. | List of labels | optional | [] |
+| srcs | The list of Go source files that are compiled to create the package. Only .go
, .s
, and .syso
files are permitted, unless the cgo
attribute is set, in which case, .c .cc .cpp .cxx .h .hh .hpp .hxx .inc .m .mm
files are also permitted. Files may be filtered at build time using Go [build constraints]. | List of labels | optional | [] |
| static | Controls whether a binary is statically linked. May be one of on
, off
, or auto
. Not available on all platforms or in all modes. It's usually better to control this on the command line with --@io_bazel_rules_go//go/config:static
. See [mode attributes], specifically [static]. | String | optional | "auto" |
| x_defs | Map of defines to add to the go link command. See [Defines and stamping] for examples of how to use these. | Dictionary: String -> String | optional | {} |
diff --git a/go/def.bzl b/go/def.bzl
index 0e6f5ed0ce..9def94efeb 100644
--- a/go/def.bzl
+++ b/go/def.bzl
@@ -121,7 +121,7 @@ TOOLS_NOGO = [str(Label(l)) for l in _TOOLS_NOGO]
# Current version or next version to be tagged. Gazelle and other tools may
# check this to determine compatibility.
-RULES_GO_VERSION = "0.47.0"
+RULES_GO_VERSION = "0.47.1"
go_context = _go_context
gomock = _gomock
diff --git a/go/private/actions/archive.bzl b/go/private/actions/archive.bzl
index 3bf0bffdea..c518501da6 100644
--- a/go/private/actions/archive.bzl
+++ b/go/private/actions/archive.bzl
@@ -88,7 +88,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
clinkopts = [f for fs in source.clinkopts for f in fs.split(" ")]
cgo = cgo_configure(
go,
- srcs = split.go + split.c + split.asm + split.cxx + split.objc + split.headers,
+ srcs = split.go + split.c + split.asm + split.cxx + split.objc + split.headers + split.syso,
cdeps = source.cdeps,
cppopts = cppopts,
copts = copts,
@@ -101,7 +101,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
runfiles = runfiles.merge(cgo.runfiles)
emit_compilepkg(
go,
- sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers,
+ sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers + split.syso,
cover = source.cover,
embedsrcs = source.embedsrcs,
importpath = importpath,
@@ -127,7 +127,7 @@ def emit_archive(go, source = None, _recompile_suffix = "", recompile_internal_d
cgo_deps = depset()
emit_compilepkg(
go,
- sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers,
+ sources = split.go + split.c + split.asm + split.cxx + split.objc + split.headers + split.syso,
cover = source.cover,
embedsrcs = source.embedsrcs,
importpath = importpath,
diff --git a/go/private/common.bzl b/go/private/common.bzl
index 51056f65cd..c1eedc046b 100644
--- a/go/private/common.bzl
+++ b/go/private/common.bzl
@@ -72,6 +72,10 @@ cgo_exts = [
".mm",
]
+syso_exts = [
+ ".syso",
+]
+
def split_srcs(srcs):
"""Returns a struct of sources, divided by extension."""
sources = struct(
@@ -81,6 +85,7 @@ def split_srcs(srcs):
c = [],
cxx = [],
objc = [],
+ syso = [],
)
ext_pairs = (
(sources.go, go_exts),
@@ -89,6 +94,7 @@ def split_srcs(srcs):
(sources.c, c_exts),
(sources.cxx, cxx_exts),
(sources.objc, objc_exts),
+ (sources.syso, syso_exts),
)
extmap = {}
for outs, exts in ext_pairs:
@@ -106,7 +112,7 @@ def split_srcs(srcs):
def join_srcs(source):
"""Combines source from a split_srcs struct into a single list."""
- return source.go + source.headers + source.asm + source.c + source.cxx + source.objc
+ return source.go + source.headers + source.asm + source.c + source.cxx + source.objc + source.syso
def os_path(ctx, path):
path = str(path) # maybe convert from path type
diff --git a/go/private/rules/binary.bzl b/go/private/rules/binary.bzl
index 40b4011e41..40a17f4d52 100644
--- a/go/private/rules/binary.bzl
+++ b/go/private/rules/binary.bzl
@@ -18,6 +18,7 @@ load(
"asm_exts",
"cgo_exts",
"go_exts",
+ "syso_exts",
)
load(
"//go/private:context.bzl",
@@ -188,9 +189,9 @@ _go_binary_kwargs = {
"implementation": _go_binary_impl,
"attrs": {
"srcs": attr.label_list(
- allow_files = go_exts + asm_exts + cgo_exts,
+ allow_files = go_exts + asm_exts + cgo_exts + syso_exts,
doc = """The list of Go source files that are compiled to create the package.
- Only `.go` and `.s` files are permitted, unless the `cgo`
+ Only `.go`, `.s`, and `.syso` files are permitted, unless the `cgo`
attribute is set, in which case,
`.c .cc .cpp .cxx .h .hh .hpp .hxx .inc .m .mm`
files are also permitted. Files may be filtered at build time
diff --git a/go/tools/builders/compilepkg.go b/go/tools/builders/compilepkg.go
index 4a1fc5ba61..a62192a541 100644
--- a/go/tools/builders/compilepkg.go
+++ b/go/tools/builders/compilepkg.go
@@ -514,8 +514,13 @@ func compileArchive(
}
}
- // Pack .o files into the archive. These may come from cgo generated code,
- // cgo dependencies (cdeps), or assembly.
+ // Windows resource files (.syso) are treated the same as object files.
+ for _, src := range srcs.sysoSrcs {
+ objFiles = append(objFiles, src.filename)
+ }
+
+ // Pack .o and .syso files into the archive. These may come from cgo generated code,
+ // cgo dependencies (cdeps), windows resource file generation, or assembly.
if len(objFiles) > 0 {
if err := appendToArchive(goenv, outLinkObj, objFiles); err != nil {
return err
diff --git a/go/tools/builders/filter.go b/go/tools/builders/filter.go
index 328caac95b..be4c8accb3 100644
--- a/go/tools/builders/filter.go
+++ b/go/tools/builders/filter.go
@@ -48,6 +48,7 @@ const (
objcxxExt
sExt
hExt
+ sysoExt
)
type fileImport struct {
@@ -62,7 +63,7 @@ type fileEmbed struct {
}
type archiveSrcs struct {
- goSrcs, cSrcs, cxxSrcs, objcSrcs, objcxxSrcs, sSrcs, hSrcs []fileInfo
+ goSrcs, cSrcs, cxxSrcs, objcSrcs, objcxxSrcs, sSrcs, hSrcs, sysoSrcs []fileInfo
}
// filterAndSplitFiles filters files using build constraints and collates
@@ -97,6 +98,8 @@ func filterAndSplitFiles(fileNames []string) (archiveSrcs, error) {
srcs = &res.sSrcs
case hExt:
srcs = &res.hSrcs
+ case sysoExt:
+ srcs = &res.sysoSrcs
}
*srcs = append(*srcs, src)
}
@@ -131,6 +134,8 @@ func readFileInfo(bctx build.Context, input string) (fileInfo, error) {
fi.ext = sExt
case ".h", ".hh", ".hpp", ".hxx":
fi.ext = hExt
+ case ".syso":
+ fi.ext = sysoExt
default:
return fileInfo{}, fmt.Errorf("unrecognized file extension: %s", ext)
}
diff --git a/go/tools/builders/generate_test_main.go b/go/tools/builders/generate_test_main.go
index f5b5fcce38..83001fbd40 100644
--- a/go/tools/builders/generate_test_main.go
+++ b/go/tools/builders/generate_test_main.go
@@ -245,9 +245,23 @@ func main() {
// we set -test.timeout according to the TEST_TIMEOUT, we need to ignore the signal so the test has
// time to properly produce the output (e.g. stack trace). It will be killed by Bazel after the grace
// 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)
+ // ignore SIGTERM so it can be properly terminated. (1)
+ // We do not panic (like native go test does) because users may legitimately want to use SIGTERM
+ // in tests.
+ //
+ // signal.Notify is used to ensure that there is a no-op signal handler registered.
+ // Avoid using signal.Ignore here: despite the name, it's only used to unregister handlers that
+ // were previously registered by signal.Notify. See (2) for more information.
+ //
+ // (1): https://github.com/golang/go/blob/e816eb50140841c524fd07ecb4eaa078954eb47c/src/testing/testing.go#L2351
+ // (2): https://github.com/bazelbuild/rules_go/pull/3929
+ c := make(chan os.Signal, 1)
+ signal.Notify(c, syscall.SIGTERM)
+ go func() {
+ <-c
+ }()
}
{{if not .TestMain}}