build_defs.bzl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. # copybara:insert_for_google3_begin
  26. # load("//tools/build_defs/proto/cpp:cc_proto_library.bzl", _cc_proto_library="cc_proto_library")
  27. # copybara:insert_end
  28. # copybara:strip_for_google3_begin
  29. _cc_proto_library = native.cc_proto_library
  30. # copybara:strip_end
  31. def proto_library(**kwargs):
  32. native.proto_library(
  33. # copybara:insert_for_google3_begin
  34. # cc_api_version = 2,
  35. # copybara:insert_end
  36. **kwargs,
  37. )
  38. def tmpl_cc_binary(name, gen, args, replacements = [], **kwargs):
  39. srcs = [name + ".cc"]
  40. native.genrule(
  41. name = name + "_gen_srcs",
  42. tools = [gen],
  43. outs = srcs,
  44. cmd = "$(location " + gen + ") " + " ".join(args) + " > $@",
  45. )
  46. native.cc_binary(
  47. # copybara:insert_for_google3_begin
  48. # malloc="//base:system_malloc",
  49. # features = ["-static_linking_mode"],
  50. # copybara:insert_end
  51. name = name,
  52. srcs = srcs,
  53. **kwargs,
  54. )
  55. def cc_optimizefor_proto_library(name, srcs, outs, optimize_for):
  56. if len(srcs) != 1:
  57. fail("Currently srcs must have exactly 1 element")
  58. native.genrule(
  59. name = name + "_gen_proto",
  60. srcs = srcs,
  61. outs = outs,
  62. cmd = "cp $< $@ && chmod a+w $@ && echo 'option optimize_for = " + optimize_for + ";' >> $@",
  63. )
  64. proto_library(
  65. name = name + "_proto",
  66. srcs = outs,
  67. )
  68. _cc_proto_library(
  69. name = name,
  70. deps = [":" + name + "_proto"],
  71. )
  72. def expand_suffixes(vals, suffixes):
  73. ret = []
  74. for val in vals:
  75. for suffix in suffixes:
  76. ret.append(val + suffix)
  77. return ret