bazel_build.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
  4. #
  5. # SPDX-License-Identifier: BSD-3-Clause
  6. #
  7. # A script that verifies various Bazel build configurations succeed.
  8. import logging
  9. import os
  10. import sys
  11. from bazel_common import (
  12. SDK_ROOT,
  13. override_picotool_arg,
  14. parse_common_args,
  15. print_framed_string,
  16. print_to_stderr,
  17. run_bazel,
  18. setup_logging,
  19. )
  20. BUILD_CONFIGURATIONS = (
  21. {
  22. "name": "host",
  23. "args": (),
  24. "extra_targets": (
  25. "@picotool//:picotool",
  26. "//tools/pioasm:pioasm",
  27. ),
  28. "exclusions": frozenset(
  29. (
  30. "//test/cmsis_test:cmsis_test",
  31. "//test/hardware_irq_test:hardware_irq_test",
  32. "//test/hardware_pwm_test:hardware_pwm_test",
  33. "//test/hardware_sync_spin_lock_test:hardware_sync_spin_lock_test",
  34. "//test/kitchen_sink:kitchen_sink",
  35. "//test/kitchen_sink:kitchen_sink_cpp",
  36. "//test/kitchen_sink:kitchen_sink_lwip_poll",
  37. "//test/kitchen_sink:kitchen_sink_lwip_background",
  38. "//test/pico_divider_test:pico_divider_test",
  39. "//test/pico_divider_test:pico_divider_nesting_test",
  40. "//test/pico_float_test:pico_double_test",
  41. "//test/pico_float_test:pico_float_test",
  42. "//test/pico_float_test:pico_float_test_hazard3",
  43. "//test/pico_sha256_test:pico_sha256_test",
  44. "//test/pico_stdio_test:pico_stdio_test",
  45. "//test/pico_time_test:pico_time_test",
  46. # Pretty much only Picotool and pioasm build on Windows.
  47. "//..." if os.name == "nt" else "",
  48. "//test/pico_sem_test:pico_sem_test" if os.name == "nt" else "",
  49. "//test/pico_stdlib_test:pico_stdlib_test" if os.name == "nt" else "",
  50. )
  51. ),
  52. "run_targets": (""),
  53. },
  54. {
  55. "name": "rp2040",
  56. "args": ("--platforms=//bazel/platform:rp2040",),
  57. "extra_targets": (),
  58. "exclusions": frozenset(
  59. (
  60. "//test/kitchen_sink:kitchen_sink_lwip_poll",
  61. "//test/kitchen_sink:kitchen_sink_lwip_background",
  62. # Host only.
  63. "//test/pico_float_test:hazard3_test_gen",
  64. # No RISC-V on RP2040.
  65. "//test/pico_float_test:pico_float_test_hazard3",
  66. # hardware_sha256 doesn't appear to work on RP2040.
  67. "//test/pico_sha256_test:pico_sha256_test",
  68. )
  69. ),
  70. },
  71. {
  72. "name": "rp2350",
  73. "args": ("--platforms=//bazel/platform:rp2350",),
  74. "extra_targets": (),
  75. "exclusions": frozenset(
  76. (
  77. "//test/kitchen_sink:kitchen_sink_lwip_poll",
  78. "//test/kitchen_sink:kitchen_sink_lwip_background",
  79. # Host only.
  80. "//test/pico_float_test:hazard3_test_gen",
  81. # TODO: RISC-V support.
  82. "//test/pico_float_test:pico_float_test_hazard3",
  83. )
  84. ),
  85. },
  86. {
  87. "name": "rp2040 clang",
  88. "args": (
  89. "--platforms=//bazel/platform:rp2040",
  90. "--@pico-sdk//bazel/config:PICO_TOOLCHAIN=clang",
  91. ),
  92. "extra_targets": (),
  93. "exclusions": frozenset(
  94. (
  95. "//test/kitchen_sink:kitchen_sink_lwip_poll",
  96. "//test/kitchen_sink:kitchen_sink_lwip_background",
  97. # Host only.
  98. "//test/pico_float_test:hazard3_test_gen",
  99. # No RISC-V on RP2040.
  100. "//test/pico_float_test:pico_float_test_hazard3",
  101. # hardware_sha256 doesn't appear to work on RP2040.
  102. "//test/pico_sha256_test:pico_sha256_test",
  103. )
  104. ),
  105. },
  106. {
  107. "name": "rp2350 clang",
  108. "args": (
  109. "--platforms=//bazel/platform:rp2350",
  110. "--@pico-sdk//bazel/config:PICO_TOOLCHAIN=clang",
  111. ),
  112. "extra_targets": (),
  113. "exclusions": frozenset(
  114. (
  115. "//test/kitchen_sink:kitchen_sink_lwip_poll",
  116. "//test/kitchen_sink:kitchen_sink_lwip_background",
  117. # Host only.
  118. "//test/pico_float_test:hazard3_test_gen",
  119. # TODO: RISC-V support.
  120. "//test/pico_float_test:pico_float_test_hazard3",
  121. )
  122. ),
  123. },
  124. {
  125. "name": "Pico W",
  126. "args": (
  127. "--platforms=//bazel/platform:rp2040",
  128. "--@pico-sdk//bazel/config:PICO_BOARD=pico_w",
  129. ),
  130. "extra_targets": (),
  131. "exclusions": frozenset(
  132. (
  133. # Host only.
  134. "//test/pico_float_test:hazard3_test_gen",
  135. # No RISC-V on RP2040.
  136. "//test/pico_float_test:pico_float_test_hazard3",
  137. # hardware_sha256 doesn't appear to work on RP2040.
  138. "//test/pico_sha256_test:pico_sha256_test",
  139. )
  140. ),
  141. },
  142. {
  143. "name": "Pico 2 W",
  144. "args": (
  145. "--platforms=//bazel/platform:rp2350",
  146. "--@pico-sdk//bazel/config:PICO_BOARD=pico2_w",
  147. ),
  148. "extra_targets": (),
  149. "exclusions": frozenset(
  150. (
  151. # Host only.
  152. "//test/pico_float_test:hazard3_test_gen",
  153. # No RISC-V on RP2040.
  154. "//test/pico_float_test:pico_float_test_hazard3",
  155. )
  156. ),
  157. },
  158. )
  159. def _find_tests(picotool_dir):
  160. """Explicitly lists out every test binary in //tests."""
  161. all_tests = (
  162. run_bazel(
  163. (
  164. "query",
  165. "kind(cc_binary, //test/...)",
  166. "--output=label",
  167. override_picotool_arg(picotool_dir) if picotool_dir else "",
  168. ),
  169. text=True,
  170. check=True,
  171. capture_output=True,
  172. )
  173. .stdout.strip()
  174. .splitlines()
  175. )
  176. # Some tests are behind a transition.
  177. return [t.replace("_actual", "") for t in all_tests]
  178. def build_all_configurations(picotool_dir):
  179. default_build_targets = [
  180. "//...",
  181. # Tests are explicitly built by name so we can catch compatibilty
  182. # regressions that cause them to vanish from the wildcard build.
  183. *_find_tests(picotool_dir),
  184. ]
  185. failed_builds = []
  186. for config in BUILD_CONFIGURATIONS:
  187. print_framed_string(f"Building {config['name']} configuration...")
  188. build_targets = [
  189. t for t in default_build_targets if t not in config["exclusions"]
  190. ]
  191. build_targets.extend(config["extra_targets"])
  192. args = list(config["args"])
  193. if picotool_dir:
  194. args.append(override_picotool_arg(picotool_dir))
  195. result = run_bazel(
  196. (
  197. "build",
  198. *args,
  199. *build_targets,
  200. ),
  201. )
  202. if result.returncode != 0:
  203. failed_builds.append(config["name"])
  204. print_to_stderr()
  205. if failed_builds:
  206. print_framed_string("ERROR: One or more builds failed.")
  207. for build in failed_builds:
  208. print_to_stderr(f" * FAILED: {build} build")
  209. return 1
  210. print_framed_string("All builds successfully passed!")
  211. return 0
  212. def main():
  213. setup_logging()
  214. args = parse_common_args()
  215. return build_all_configurations(args.picotool_dir)
  216. if __name__ == "__main__":
  217. sys.exit(main())