orkmode/crates/org-parser/build.rs

37 lines
1.1 KiB
Rust

//! Build script to compile tree-sitter-org grammar.
use std::path::PathBuf;
fn main() {
let grammar_dir = PathBuf::from("tree-sitter-org/src");
// Check if grammar exists
if !grammar_dir.exists() {
panic!(
"tree-sitter-org grammar not found at {:?}. \
Run: git clone https://github.com/nvim-orgmode/tree-sitter-org crates/org-parser/tree-sitter-org",
grammar_dir
);
}
// Compile parser.c
let mut build = cc::Build::new();
build
.include(&grammar_dir)
.file(grammar_dir.join("parser.c"))
.warnings(false);
// Compile scanner.c if it exists (org has one)
let scanner_path = grammar_dir.join("scanner.c");
if scanner_path.exists() {
build.file(scanner_path);
}
build.compile("tree-sitter-org");
// Tell cargo to rerun if grammar files change
println!("cargo:rerun-if-changed=tree-sitter-org/src/parser.c");
println!("cargo:rerun-if-changed=tree-sitter-org/src/scanner.c");
println!("cargo:rerun-if-changed=tree-sitter-org/src/tree_sitter/parser.h");
}