Allow disabling nogo stdlib facts.

Rebuilding the set of standard library facts can be time consuming. Allow this
to be disabled for faster iteration. This is done by provided a build setting
which can be toggled directly, for example:

bazel build --//tools/nogo:fast ...

PiperOrigin-RevId: 426562548
This commit is contained in:
Adin Scannell
2022-02-04 22:41:23 -08:00
committed by gVisor bot
parent 1ebb4fd367
commit 6c2d9a2359
4 changed files with 31 additions and 8 deletions
+3
View File
@@ -2,9 +2,12 @@
load("@bazel_skylib//rules:build_test.bzl", _build_test = "build_test")
load("@bazel_skylib//:bzl_library.bzl", _bzl_library = "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", _BuildSettingInfo = "BuildSettingInfo", _bool_flag = "bool_flag")
build_test = _build_test
bzl_library = _bzl_library
bool_flag = _bool_flag
BuildSettingInfo = _BuildSettingInfo
more_shards = 4
most_shards = 8
version = "//tools/bazeldefs:version"
+3 -1
View File
@@ -8,7 +8,7 @@ change for Google-internal and bazel-compatible rules.
load("//tools/go_stateify:defs.bzl", "go_stateify")
load("//tools/go_marshal:defs.bzl", "go_marshal", "marshal_deps", "marshal_test_deps")
load("//tools/nogo:defs.bzl", "nogo_test")
load("//tools/bazeldefs:defs.bzl", _amd64_config = "amd64_config", _arch_config = "arch_config", _arm64_config = "arm64_config", _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", _transition_allowlist = "transition_allowlist", _version = "version")
load("//tools/bazeldefs:defs.bzl", _BuildSettingInfo = "BuildSettingInfo", _amd64_config = "amd64_config", _arch_config = "arch_config", _arm64_config = "arm64_config", _bool_flag = "bool_flag", _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", _transition_allowlist = "transition_allowlist", _version = "version")
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", _vdso_linker_option = "vdso_linker_option")
load("//tools/bazeldefs:go.bzl", _gazelle = "gazelle", _go_binary = "go_binary", _go_embed_data = "go_embed_data", _go_grpc_and_proto_libraries = "go_grpc_and_proto_libraries", _go_library = "go_library", _go_path = "go_path", _go_proto_library = "go_proto_library", _go_rule = "go_rule", _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")
@@ -18,6 +18,8 @@ load("//tools/bazeldefs:tags.bzl", "go_suffixes")
# Core rules.
build_test = _build_test
bzl_library = _bzl_library
bool_flag = _bool_flag
BuildSettingInfo = _BuildSettingInfo
default_net_util = _default_net_util
select_arch = _select_arch
select_system = _select_system
+6 -1
View File
@@ -1,8 +1,13 @@
load("//tools:defs.bzl", "bzl_library", "go_binary", "select_goarch", "select_goos")
load("//tools:defs.bzl", "bool_flag", "bzl_library", "go_binary", "select_goarch", "select_goos")
load("//tools/nogo:defs.bzl", "nogo_stdlib", "nogo_target")
package(licenses = ["notice"])
bool_flag(
name = "fast",
build_setting_default = False,
)
nogo_target(
name = "target",
goarch = select_goarch(),
+19 -6
View File
@@ -1,5 +1,6 @@
"""Nogo rules."""
load("//tools/bazeldefs:defs.bzl", "BuildSettingInfo")
load("//tools/bazeldefs:go.bzl", "go_context", "go_embed_libraries", "go_importpath", "go_rule")
NogoConfigInfo = provider(
@@ -63,6 +64,13 @@ NogoStdlibInfo = provider(
)
def _nogo_stdlib_impl(ctx):
# If this is disabled, return nothing.
if ctx.attr._fast[BuildSettingInfo].value:
return [NogoStdlibInfo(
facts = None,
raw_findings = [],
)]
# Build the configuration for the stdlib.
go_ctx, args, inputs, raw_findings = _nogo_config(ctx, deps = [])
@@ -109,12 +117,16 @@ nogo_stdlib = go_rule(
attrs = {
"_nogo": attr.label(
default = "//tools/nogo:nogo",
cfg = "exec",
cfg = "host",
),
"_target": attr.label(
default = "//tools/nogo:target",
cfg = "target",
),
"_fast": attr.label(
default = "//tools/nogo:fast",
cfg = "host",
),
},
)
@@ -216,8 +228,9 @@ def _nogo_package_config(ctx, deps, importpath = None, target = None):
# Add the standard library facts.
stdlib_info = ctx.attr._nogo_stdlib[NogoStdlibInfo]
stdlib_facts = stdlib_info.facts
inputs.append(stdlib_facts)
args.append("-bundle=%s" % stdlib_facts.path)
if stdlib_facts:
inputs.append(stdlib_facts)
args.append("-bundle=%s" % stdlib_facts.path)
# Flatten all findings from all dependencies.
#
@@ -314,7 +327,7 @@ nogo_aspect = go_rule(
attrs = {
"_nogo": attr.label(
default = "//tools/nogo:nogo",
cfg = "exec",
cfg = "host",
),
"_target": attr.label(
default = "//tools/nogo:target",
@@ -400,7 +413,7 @@ nogo_test = rule(
),
"_nogo": attr.label(
default = "//tools/nogo:nogo",
cfg = "exec",
cfg = "host",
),
"_target": attr.label(
default = "//tools/nogo:target",
@@ -478,7 +491,7 @@ nogo_facts = go_rule(
),
"_nogo": attr.label(
default = "//tools/nogo:nogo",
cfg = "exec",
cfg = "host",
),
# See _nogo_aspect, above.
"_nogo_stdlib": attr.label(