Debian Codegraph @

third_party/upb/benchmarks/build_defs.bzl

raw
1 # Copyright (c) 2009-2021, Google LLC
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution.
11 # * Neither the name of Google LLC nor the
12 # names of its contributors may be used to endorse or promote products
13 # derived from this software without specific prior written permission.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 # DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY
19 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26 # begin:google_only
27 # load("//tools/build_defs/proto/cpp:cc_proto_library.bzl", _cc_proto_library = "cc_proto_library")
28 #
29 # _is_google3 = True
30 # end:google_only
31
32 # begin:github_only
33 _cc_proto_library = native.cc_proto_library
34 _is_google3 = False
35 # end:github_only
36
37 def proto_library(**kwargs):
38 if _is_google3:
39 kwargs["cc_api_version"] = 2
40 native.proto_library(
41 **kwargs
42 )
43
44 def tmpl_cc_binary(name, gen, args, replacements = [], **kwargs):
45 srcs = [name + ".cc"]
46 native.genrule(
47 name = name + "_gen_srcs",
48 tools = [gen],
49 outs = srcs,
50 cmd = "$(location " + gen + ") " + " ".join(args) + " > $@",
51 )
52
53 if _is_google3:
54 kwargs["malloc"] = "//base:system_malloc"
55 kwargs["features"] = ["-static_linking_mode"]
56 native.cc_binary(
57 name = name,
58 srcs = srcs,
59 **kwargs
60 )
61
62 def cc_optimizefor_proto_library(name, srcs, outs, optimize_for):
63 if len(srcs) != 1:
64 fail("Currently srcs must have exactly 1 element")
65
66 native.genrule(
67 name = name + "_gen_proto",
68 srcs = srcs,
69 outs = outs,
70 cmd = "cp $< $@ && chmod a+w $@ && echo 'option optimize_for = " + optimize_for + ";' >> $@",
71 )
72
73 proto_library(
74 name = name + "_proto",
75 srcs = outs,
76 )
77
78 _cc_proto_library(
79 name = name,
80 deps = [":" + name + "_proto"],
81 )
82
83 def expand_suffixes(vals, suffixes):
84 ret = []
85 for val in vals:
86 for suffix in suffixes:
87 ret.append(val + suffix)
88 return ret