build.rs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. fn main() {
  2. napi_build::setup();
  3. // Kotlin grammar — vendored C, compiled here instead of a crate dep: the
  4. // crates.io tree-sitter-kotlin 0.3.8 pins `tree-sitter >= 0.21, < 0.23`
  5. // (the kernel links 0.25) and tree-sitter-kotlin-ng is a DIFFERENT
  6. // grammar (8 fields vs 0, renamed kinds — extractor-breaking). Sources
  7. // are the fwcd 0.3.8 tag's checked-in generated artifacts, sha-matched
  8. // against the crates.io tarball (kotlin checklist §Grammar prep):
  9. // parser.c 54104a7ef1555c265b746c790e0f8bb953cc17806e9df0c3af82f7f62c06a70a
  10. // scanner.c 27f73337ec357fc341fa57538f34c14277b0346980c3405dc30beab6202ec6d0
  11. // Flags crib the tarball's own bindings/rust/build.rs.
  12. let mut c = cc::Build::new();
  13. c.include("grammars/kotlin");
  14. c.file("grammars/kotlin/parser.c");
  15. c.file("grammars/kotlin/scanner.c");
  16. c.flag_if_supported("-Wno-unused-parameter");
  17. c.flag_if_supported("-Wno-unused-but-set-variable");
  18. c.flag_if_supported("-Wno-trigraphs");
  19. c.flag_if_supported("-utf-8"); // msvc
  20. c.compile("tree-sitter-kotlin");
  21. println!("cargo:rerun-if-changed=grammars/kotlin");
  22. // Lua grammar — vendored C (second vendored-grammar-C language): the
  23. // vendored wasm is tree-sitter-grammars/tree-sitter-lua v0.4.1 (tag
  24. // 816840c592), which is NOT on crates.io (only 0.1/0.2/0.5 exist; 0.5.0
  25. // adds Lua-5.5 `global` — a future bump with its own gate). Sources are
  26. // the v0.4.1 tag's checked-in generated artifacts, sha-recorded in the
  27. // lua-luau checklist §Grammar prep:
  28. // parser.c b34a362e43f0311f405721f3089e94f97f31da403b154d456d093e64609a4081
  29. // scanner.c 35bbd630b5a7421d46d2e91185eeea09bf78565d44cb676b63ca20d0f1b54bbd
  30. let mut lua = cc::Build::new();
  31. lua.include("grammars/lua");
  32. lua.file("grammars/lua/parser.c");
  33. lua.file("grammars/lua/scanner.c");
  34. lua.flag_if_supported("-Wno-unused-parameter");
  35. lua.flag_if_supported("-Wno-unused-but-set-variable");
  36. lua.flag_if_supported("-Wno-trigraphs");
  37. lua.flag_if_supported("-utf-8"); // msvc
  38. lua.compile("tree-sitter-lua");
  39. println!("cargo:rerun-if-changed=grammars/lua");
  40. // Scala grammar — vendored C (third vendored-grammar-C language): the
  41. // vendored wasm is tree-sitter/tree-sitter-scala master@0aca5d0a6f (the
  42. // 2026-04-22 generation sync — 30 states PAST the v0.26.0 tag/crate, so a
  43. // crate pin would be a silent downgrade). Sources are that commit's
  44. // checked-in generated artifacts, sha-recorded in the scala checklist
  45. // §Grammar prep:
  46. // parser.c bc3c3c794f19461d99d04de6c31d57fa3e41243509b9ab023a9b88ed3273d102
  47. // scanner.c e4ba242568ee3493015598997bf60f613802616eade62717c21109287ef64752
  48. // parser.c is 35 MB — the biggest grammar in the tree; expect a slow cc
  49. // step on clean builds.
  50. let mut scala = cc::Build::new();
  51. scala.include("grammars/scala");
  52. scala.file("grammars/scala/parser.c");
  53. scala.file("grammars/scala/scanner.c");
  54. scala.flag_if_supported("-Wno-unused-parameter");
  55. scala.flag_if_supported("-Wno-unused-but-set-variable");
  56. scala.flag_if_supported("-Wno-trigraphs");
  57. scala.flag_if_supported("-utf-8"); // msvc
  58. scala.compile("tree-sitter-scala");
  59. println!("cargo:rerun-if-changed=grammars/scala");
  60. // Dart grammar — vendored C (fourth vendored-grammar-C language): the
  61. // production wasm is the tree-sitter-wasms 0.1.13 artifact, whose dart
  62. // dependency is an UNPINNED github:UserNobody14/tree-sitter-dart — the
  63. // vendored wasm byte-copy (src/extraction/wasm/) plus these same-commit
  64. // sources kill that hazard. crates.io tree-sitter-dart is the nielsenko
  65. // FORK (different lineage) — rejected. Sources are
  66. // UserNobody14/tree-sitter-dart master@d4d8f3e337d8 (dart checklist
  67. // §Grammar prep):
  68. // parser.c 5a42b47abb4d494f125dbdee9138979248041689b1aa36355550fa3e28dcb8b8
  69. // scanner.c 07a7b7818b175e9460523e705dd88d20f7b5141bac95c593d4426e6d52284996
  70. // scanner.c is load-bearing: string-template char classes and /** */ doc
  71. // comments are external tokens.
  72. let mut dart = cc::Build::new();
  73. dart.include("grammars/dart");
  74. dart.file("grammars/dart/parser.c");
  75. dart.file("grammars/dart/scanner.c");
  76. dart.flag_if_supported("-Wno-unused-parameter");
  77. dart.flag_if_supported("-Wno-unused-but-set-variable");
  78. dart.flag_if_supported("-Wno-trigraphs");
  79. dart.flag_if_supported("-Wno-unused-function");
  80. dart.flag_if_supported("-utf-8"); // msvc
  81. dart.compile("tree-sitter-dart");
  82. println!("cargo:rerun-if-changed=grammars/dart");
  83. }