diff --git a/BUILD.bazel b/BUILD.bazel index 74750013eb..97380f9704 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -118,6 +118,7 @@ go_config( "//go/private:is_compilation_mode_dbg": "//go/private:always_true", "//conditions:default": "//go/config:debug", }), + gc_goopts = "//go/config:gc_goopts", gc_linkopts = "//go/config:gc_linkopts", gotags = "//go/config:tags", linkmode = "//go/config:linkmode", diff --git a/go/config/BUILD.bazel b/go/config/BUILD.bazel index b4a99a089b..12075e37dc 100644 --- a/go/config/BUILD.bazel +++ b/go/config/BUILD.bazel @@ -80,3 +80,9 @@ filegroup( srcs = glob(["**"]), visibility = ["//visibility:public"], ) + +string_list_flag( + name = "gc_goopts", + build_setting_default = [], + visibility = ["//visibility:public"], +) diff --git a/go/private/actions/compilepkg.bzl b/go/private/actions/compilepkg.bzl index 784539f173..93f34a8b87 100644 --- a/go/private/actions/compilepkg.bzl +++ b/go/private/actions/compilepkg.bzl @@ -119,6 +119,7 @@ def emit_compilepkg( args.add("-testfilter", testfilter) gc_flags = list(gc_goopts) + gc_flags.extend(go.mode.gc_goopts) asm_flags = [] if go.mode.race: gc_flags.append("-race") diff --git a/go/private/context.bzl b/go/private/context.bzl index 7879420b39..ac4f22f470 100644 --- a/go/private/context.bzl +++ b/go/private/context.bzl @@ -516,7 +516,6 @@ def go_context(ctx, attr = None): stamp = mode.stamp, label = ctx.label, cover_format = mode.cover_format, - # Action generators archive = toolchain.actions.archive, asm = toolchain.actions.asm, @@ -821,6 +820,7 @@ def _go_config_impl(ctx): tags = ctx.attr.gotags[BuildSettingInfo].value, stamp = ctx.attr.stamp, cover_format = ctx.attr.cover_format[BuildSettingInfo].value, + gc_goopts = ctx.attr.gc_goopts[BuildSettingInfo].value, amd64 = ctx.attr.amd64, )] @@ -868,6 +868,10 @@ go_config = rule( mandatory = True, providers = [BuildSettingInfo], ), + "gc_goopts": attr.label( + mandatory = True, + providers = [BuildSettingInfo], + ), "amd64": attr.string(), }, provides = [GoConfigInfo], diff --git a/go/private/mode.bzl b/go/private/mode.bzl index b596723e04..22e5283b56 100644 --- a/go/private/mode.bzl +++ b/go/private/mode.bzl @@ -47,6 +47,8 @@ def mode_string(mode): result.append("stripped") if not result or not mode.link == LINKMODE_NORMAL: result.append(mode.link) + if mode.gc_goopts: + result.extend(mode.gc_goopts) return "_".join(result) def _ternary(*values): @@ -83,6 +85,7 @@ def get_mode(ctx, go_toolchain, cgo_context_info, go_config_info): amd64 = go_config_info.amd64 if go_config_info else None goos = go_toolchain.default_goos if getattr(ctx.attr, "goos", "auto") == "auto" else ctx.attr.goos goarch = go_toolchain.default_goarch if getattr(ctx.attr, "goarch", "auto") == "auto" else ctx.attr.goarch + gc_goopts = go_config_info.gc_goopts if go_config_info else [] # TODO(jayconrod): check for more invalid and contradictory settings. if pure and race: @@ -116,6 +119,7 @@ def get_mode(ctx, go_toolchain, cgo_context_info, go_config_info): tags = tags, cover_format = cover_format, amd64 = amd64, + gc_goopts = gc_goopts, ) def installsuffix(mode):