github.com/prysmaticlabs/prysm@v1.4.4/tools/go/def.bzl (about) 1 load("@io_bazel_rules_go//go/private/rules:library.bzl", _go_library = "go_library") 2 load("@io_bazel_rules_go//go/private/rules:test.bzl", "go_test_kwargs") 3 load("@bazel_gazelle//:deps.bzl", _go_repository = "go_repository") 4 5 def _go_test_transition_impl(settings, attr): 6 """Edge transition to add minimal or mainnet build tags""" 7 settings = dict(settings) 8 9 if attr.eth_network == "minimal": 10 settings["//proto:network"] = "minimal" 11 settings["@io_bazel_rules_go//go/config:tags"] += ["minimal"] 12 elif attr.eth_network == "mainnet": # Default / optional 13 settings["//proto:network"] = "mainnet" 14 settings["@io_bazel_rules_go//go/config:tags"] += ["mainnet"] 15 16 if attr.gotags: 17 settings["@io_bazel_rules_go//go/config:tags"] += attr.gotags 18 19 return settings 20 21 go_test_transition = transition( 22 implementation = _go_test_transition_impl, 23 inputs = [ 24 "@io_bazel_rules_go//go/config:tags", 25 "//proto:network", 26 ], 27 outputs = [ 28 "@io_bazel_rules_go//go/config:tags", 29 "//proto:network", 30 ], 31 ) 32 33 def _go_test_transition_rule(**kwargs): 34 """A wrapper around go_test to add an eth_network attribute and incoming edge transition to support compile time configuration""" 35 kwargs = dict(kwargs) 36 attrs = dict(kwargs["attrs"]) 37 attrs.update({ 38 "eth_network": attr.string(values = ["mainnet", "minimal"]), 39 "_whitelist_function_transition": attr.label( 40 default = "@bazel_tools//tools/whitelists/function_transition_whitelist", 41 ), 42 }) 43 kwargs["attrs"] = attrs 44 kwargs["cfg"] = go_test_transition 45 return rule(**kwargs) 46 47 go_test = _go_test_transition_rule(**go_test_kwargs) 48 49 def go_library(name, **kwargs): 50 gc_goopts = [] 51 52 if "gc_goopts" in kwargs: 53 go_goopts = kwargs["gc_goopts"] 54 55 gc_goopts += select({ 56 "@prysm//tools/go:libfuzz_enabled": ["-d=libfuzzer,checkptr"], 57 "//conditions:default": [], 58 }) 59 60 kwargs["gc_goopts"] = gc_goopts 61 _go_library(name = name, **kwargs) 62 63 # Maybe download a repository rule, if it doesn't exist already. 64 def maybe(repo_rule, name, **kwargs): 65 if name not in native.existing_rules(): 66 repo_rule(name = name, **kwargs) 67 68 # A wrapper around go_repository to add gazelle directives. 69 def go_repository(name, **kwargs): 70 # Some third party go tools may be used by the fuzzing pipeline to generate code. This causes 71 # an issue when running with --config=fuzz and is not necessary since the dependency is not 72 # part of the final binary. 73 if "nofuzz" in kwargs: 74 kwargs.pop("nofuzz", None) 75 return maybe(_go_repository, name, **kwargs) 76 77 directives = [] 78 if "build_directives" in kwargs: 79 directives = kwargs["build_directives"] 80 81 directives += [ 82 "gazelle:map_kind go_library go_library @prysm//tools/go:def.bzl", 83 ] 84 kwargs["build_directives"] = directives 85 maybe(_go_repository, name, **kwargs)