BUILD 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
  5. package(default_visibility = ["//bazel/check_deps:__pkg__"])
  6. # See README.md for instructions on tree-sitter setup and use. These rules are
  7. # manual because the tree-sitter invocation is non-hermetic, and most developers
  8. # won't have it installed; we don't want to break "bazel test //..." if we can
  9. # avoid it.
  10. #
  11. # We use tree-sitter non-hermetically for two key reasons:
  12. #
  13. # - The main way of hermetically using npms in bazel, `aspect_rules_js`, uses
  14. # declare_symlink; we disallow that for important compatibility reasons.
  15. # - When generated, src/parser.c is over 500 KB, which is larger than we want to
  16. # check in. It should also be expected to grow if the grammar becomes more complete.
  17. # Convenience target for running all tests, including manual tests.
  18. test_suite(
  19. name = "tests",
  20. tags = ["manual"],
  21. tests = [
  22. ":explorer_tests",
  23. ":string_fail_tests",
  24. ":string_tests",
  25. ],
  26. )
  27. # Call tree-sitter to generate parser files.
  28. genrule(
  29. name = "parser_files",
  30. srcs = ["grammar.js"],
  31. outs = [
  32. "src/parser.c",
  33. "src/tree_sitter/parser.h",
  34. ],
  35. cmd = "tree-sitter generate $(location grammar.js) &&\n" +
  36. "cp src/parser.c $(location src/parser.c) &&\n" +
  37. "cp src/tree_sitter/parser.h $(location src/tree_sitter/parser.h)",
  38. tags = ["manual"],
  39. )
  40. cc_library(
  41. name = "parser",
  42. srcs = [
  43. "src/scanner.c",
  44. ":src/parser.c",
  45. ],
  46. hdrs = [":src/tree_sitter/parser.h"],
  47. copts = ["-Wno-missing-prototypes"],
  48. tags = ["manual"],
  49. deps = ["@tree-sitter-bazel//:tree-sitter"],
  50. )
  51. cc_binary(
  52. name = "test_runner",
  53. testonly = 1,
  54. srcs = ["test_runner.cpp"],
  55. tags = ["manual"],
  56. deps = [
  57. ":parser",
  58. ],
  59. )
  60. cc_test(
  61. name = "explorer_tests",
  62. size = "small",
  63. srcs = ["test_runner.cpp"],
  64. args = ["$(locations //explorer:tree_sitter_testdata)"],
  65. data = ["//explorer:tree_sitter_testdata"],
  66. tags = ["manual"],
  67. deps = [
  68. ":parser",
  69. ],
  70. )
  71. filegroup(
  72. name = "string_testdata",
  73. srcs = glob(
  74. ["testdata/string/*.carbon"],
  75. exclude = ["testdata/string/fail_*.carbon"],
  76. ),
  77. )
  78. filegroup(
  79. name = "string_fail_testdata",
  80. srcs = glob(["testdata/string/fail_*.carbon"]),
  81. )
  82. cc_test(
  83. name = "string_tests",
  84. size = "small",
  85. srcs = ["test_runner.cpp"],
  86. args = ["$(locations :string_testdata)"],
  87. data = [":string_testdata"],
  88. tags = ["manual"],
  89. deps = [
  90. ":parser",
  91. ],
  92. )
  93. cc_test(
  94. name = "string_fail_tests",
  95. size = "small",
  96. srcs = ["test_runner.cpp"],
  97. args = ["$(locations :string_fail_testdata)"],
  98. data = [":string_fail_testdata"],
  99. env = {
  100. "FAIL_TESTS": "1",
  101. },
  102. tags = ["manual"],
  103. deps = [
  104. ":parser",
  105. ],
  106. )