From 4d09fd68d8da13d2ee678c7b6cf30e373c49ea79 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sat, 26 Sep 2026 14:30:16 -0400 Subject: [PATCH] Reset Go build modes for the Nogo tool Nogo's exec dependencies select the execution platform but retain the Go build modes of the package being analyzed. A static target can therefore make the analyzer link statically against the execution toolchain. This fails with the hermetic GNU toolchain, which provides shared glibc linking stubs rather than static archives [1]. Route all four Nogo tool dependencies through rules_go's go_reset_target [2], retaining their exec transitions for platform selection. This resets Go build modes before configuring the analyzer, independently of the package's static, race, or other mode settings. Keep the existing nogo binary and its analysis target available for direct use. [1]: https://app.buildbuddy.io/invocation/00d0c051-3fef-4fcb-b279-b158879c216e [2]: https://github.com/bazel-contrib/rules_go/blob/v0.57.0/go/private/rules/transition.bzl#L312-L339 Assisted-by: Codex --- tools/bazeldefs/go.bzl | 3 ++- tools/defs.bzl | 3 ++- tools/nogo/BUILD | 10 +++++++++- tools/nogo/defs.bzl | 8 ++++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tools/bazeldefs/go.bzl b/tools/bazeldefs/go.bzl index 5d539ebec11..0be97741ddc 100644 --- a/tools/bazeldefs/go.bzl +++ b/tools/bazeldefs/go.bzl @@ -3,13 +3,14 @@ load("@bazel_gazelle//:def.bzl", _gazelle = "gazelle") load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//lib:shell.bzl", "shell") -load("@io_bazel_rules_go//go:def.bzl", "GoArchive", "GoLibrary", _go_binary = "go_binary", _go_context = "go_context", _go_library = "go_library", _go_path = "go_path", _go_test = "go_test") +load("@io_bazel_rules_go//go:def.bzl", "GoArchive", "GoLibrary", _go_binary = "go_binary", _go_context = "go_context", _go_library = "go_library", _go_path = "go_path", _go_reset_target = "go_reset_target", _go_test = "go_test") load("@io_bazel_rules_go//proto:def.bzl", _go_grpc_library = "go_grpc_library", _go_proto_library = "go_proto_library") load("//tools/bazeldefs:defs.bzl", "select_arch", "select_system") gazelle = _gazelle go_path = _go_path +go_reset_target = _go_reset_target go_cov = native.genrule cov_available = True diff --git a/tools/defs.bzl b/tools/defs.bzl index 71740da620c..5ab64eb5cd3 100644 --- a/tools/defs.bzl +++ b/tools/defs.bzl @@ -8,7 +8,7 @@ change for Google-internal and bazel-compatible rules. load("//tools:arch.bzl", "arch_genrule", "arch_transition_impl") load("//tools/bazeldefs:cc.bzl", _cc_binary = "cc_binary", _cc_flags_supplier = "cc_flags_supplier", _cc_grpc_library = "cc_grpc_library", _cc_library = "cc_library", _cc_proto_library = "cc_proto_library", _cc_test = "cc_test", _cc_toolchain = "cc_toolchain", _gbenchmark = "gbenchmark", _gbenchmark_internal = "gbenchmark_internal", _grpcpp = "grpcpp", _gtest = "gtest", _select_gtest = "select_gtest") load("//tools/bazeldefs:defs.bzl", _BuildSettingInfo = "BuildSettingInfo", _bool_flag = "bool_flag", _bpf_program = "bpf_program", _build_test = "build_test", _bzl_library = "bzl_library", _coreutil = "coreutil", _default_net_util = "default_net_util", _more_shards = "more_shards", _most_shards = "most_shards", _proto_library = "proto_library", _select_arch = "select_arch", _select_system = "select_system", _short_path = "short_path", _version = "version") -load("//tools/bazeldefs:go.bzl", _cov_available = "cov_available", _gazelle = "gazelle", _go_binary = "go_binary", _go_binary_nogo_dep = "go_binary_nogo_dep", _go_cov = "go_cov", _go_grpc_and_proto_libraries = "go_grpc_and_proto_libraries", _go_imports = "go_imports", _go_library = "go_library", _go_path = "go_path", _go_proto_library = "go_proto_library", _go_test = "go_test", _gotsan_flag_values = "gotsan_flag_values", _gotsan_values = "gotsan_values", _select_goarch = "select_goarch", _select_goos = "select_goos") +load("//tools/bazeldefs:go.bzl", _cov_available = "cov_available", _gazelle = "gazelle", _go_binary = "go_binary", _go_binary_nogo_dep = "go_binary_nogo_dep", _go_cov = "go_cov", _go_grpc_and_proto_libraries = "go_grpc_and_proto_libraries", _go_imports = "go_imports", _go_library = "go_library", _go_path = "go_path", _go_proto_library = "go_proto_library", _go_reset_target = "go_reset_target", _go_test = "go_test", _gotsan_flag_values = "gotsan_flag_values", _gotsan_values = "gotsan_values", _select_goarch = "select_goarch", _select_goos = "select_goos") load("//tools/bazeldefs:pkg.bzl", _pkg_deb = "pkg_deb", _pkg_tar = "pkg_tar") load("//tools/bazeldefs:platforms.bzl", _default_platform = "default_platform", _platform_capabilities = "platform_capabilities", _platforms = "platforms", _save_restore_platforms = "save_restore_platforms") load("//tools/bazeldefs:tags.bzl", _go_suffixes = "go_suffixes", _local_test_tags = "local_test_tags") @@ -48,6 +48,7 @@ select_gtest = _select_gtest cov_available = _cov_available gazelle = _gazelle go_path = _go_path +go_reset_target = _go_reset_target go_cov = _go_cov select_goos = _select_goos select_goarch = _select_goarch diff --git a/tools/nogo/BUILD b/tools/nogo/BUILD index cfcfd35c926..f4e74e91d62 100644 --- a/tools/nogo/BUILD +++ b/tools/nogo/BUILD @@ -1,4 +1,4 @@ -load("//tools:defs.bzl", "bzl_library", "go_binary", "select_goarch", "select_goos") +load("//tools:defs.bzl", "bzl_library", "go_binary", "go_reset_target", "select_goarch", "select_goos") load("//tools/nogo:defs.bzl", "nogo_stdlib", "nogo_target") package( @@ -25,6 +25,14 @@ go_binary( deps = ["//tools/nogo/cli"], ) +# The exec transition selects the tool platform but preserves Go build modes. +# Reset those modes so that analyzed targets do not configure the analyzer. +go_reset_target( + name = "nogo_tool", + dep = ":nogo", + visibility = ["//visibility:public"], +) + bzl_library( name = "defs_bzl", srcs = ["defs.bzl"], diff --git a/tools/nogo/defs.bzl b/tools/nogo/defs.bzl index 171d809aba1..713b24cbf25 100644 --- a/tools/nogo/defs.bzl +++ b/tools/nogo/defs.bzl @@ -116,7 +116,7 @@ nogo_stdlib = go_rule( implementation = _nogo_stdlib_impl, attrs = { "_nogo": attr.label( - default = "//tools/nogo:nogo", + default = "//tools/nogo:nogo_tool", cfg = "exec", ), "_target": attr.label( @@ -359,7 +359,7 @@ nogo_aspect = go_rule( ], attrs = { "_nogo": attr.label( - default = "//tools/nogo:nogo", + default = "//tools/nogo:nogo_tool", cfg = "exec", ), "_target": attr.label( @@ -453,7 +453,7 @@ nogo_test = rule( doc = "Relevant src files. This is ignored except to make the nogo_test directly affected by the files.", ), "_nogo": attr.label( - default = "//tools/nogo:nogo", + default = "//tools/nogo:nogo_tool", cfg = "exec", ), "_target": attr.label( @@ -534,7 +534,7 @@ nogo_facts_render = go_rule( default = False, ), "_nogo": attr.label( - default = "//tools/nogo:nogo", + default = "//tools/nogo:nogo_tool", cfg = "exec", ), # See _nogo_aspect, above.