diff --git a/.appveyor.yml b/.appveyor.yml index 7dccb660..934d6f51 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -12,7 +12,7 @@ install: - rustc -vV - cargo -vV - - script\fetch-test-fixtures.cmd + - script\fetch-fixtures.cmd test_script: - cargo build diff --git a/.travis.yml b/.travis.yml index 65c021cf..45bc26e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ env: - TREE_SITTER_TEST=1 before_install: - - ./script/fetch-test-fixtures.sh + - ./script/fetch-fixtures branches: only: diff --git a/lib/build.rs b/lib/build.rs index cee131bd..f8c19f05 100644 --- a/lib/build.rs +++ b/lib/build.rs @@ -1,26 +1,67 @@ extern crate cc; use std::env; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; +use std::fs; fn main() { let mut config = cc::Build::new(); - let src_path: PathBuf = ["src"].iter().collect(); - config .define("UTF8PROC_STATIC", "") .flag_if_supported("-std=c99") .flag_if_supported("-Wno-unused-parameter") .include("include") .include("utf8proc") - .file(src_path.join("runtime.c")); + .file(Path::new("src").join("lib.c")) + .compile("tree-sitter"); - if env::var("RUST_TREE_SITTER_TEST").is_ok() { - let parser_dir: PathBuf = ["fixtures", "tree-sitter-rust", "src"].iter().collect(); - config - .file(parser_dir.join("parser.c")) - .file(parser_dir.join("scanner.c")); + if env::var("TREE_SITTER_TEST").is_ok() { + let mut parser_config = cc::Build::new(); + parser_config + .opt_level(0) + .flag_if_supported("-Wno-unused-parameter"); + + let mut scanner_c_config = cc::Build::new(); + scanner_c_config + .flag_if_supported("-std=c99") + .flag_if_supported("-Wno-unused-parameter"); + + let mut scanner_cxx_config = cc::Build::new(); + scanner_cxx_config + .cpp(true) + .flag_if_supported("-Wno-unused-parameter"); + + let grammars_dir: PathBuf = ["..", "test", "fixtures", "grammars"].iter().collect(); + for entry in fs::read_dir(&grammars_dir).expect("Failed to list grammar directory") { + let entry = entry.expect("Failed to load grammars directory entry"); + if !entry.path().is_dir() { + continue; + } + let parser_dir_path = entry.path(); + let parser_src_path = parser_dir_path.join("src"); + let parser_c_path = parser_src_path.join("parser.c"); + let scanner_c_path = parser_src_path.join("scanner.c"); + let scanner_cc_path = parser_src_path.join("scanner.cc"); + + println!("cargo:rerun-if-changed={}", parser_c_path.to_str().unwrap()); + parser_config + .include(&parser_src_path) + .file(&parser_c_path); + if scanner_cc_path.exists() { + println!("cargo:rerun-if-changed={}", scanner_cc_path.to_str().unwrap()); + scanner_cxx_config + .include(&parser_src_path) + .file(&scanner_cc_path); + } else if scanner_c_path.exists() { + println!("cargo:rerun-if-changed={}", scanner_c_path.to_str().unwrap()); + scanner_c_config + .include(&parser_src_path) + .file(&scanner_c_path); + } + } + + parser_config.compile("fixture-parsers"); + scanner_c_config.compile("fixture-scanners-c"); + scanner_cxx_config.compile("fixture-scanners-cxx"); } - - config.compile("tree-sitter-runtime"); } diff --git a/script/fetch-fixtures b/script/fetch-fixtures index a298a4d0..94f9eddd 100755 --- a/script/fetch-fixtures +++ b/script/fetch-fixtures @@ -21,14 +21,15 @@ fetch_grammar() { ) } -fetch_grammar embedded-template master -fetch_grammar javascript master -fetch_grammar json master +fetch_grammar bash master fetch_grammar c master fetch_grammar cpp master -fetch_grammar python master +fetch_grammar embedded-template master fetch_grammar go master -fetch_grammar ruby master -fetch_grammar typescript master -fetch_grammar bash master fetch_grammar html master +fetch_grammar javascript master +fetch_grammar json master +fetch_grammar python master +fetch_grammar ruby master +fetch_grammar rust master +fetch_grammar typescript master diff --git a/script/fetch-fixtures.cmd b/script/fetch-fixtures.cmd index 0e65b0a0..98d5d578 100644 --- a/script/fetch-fixtures.cmd +++ b/script/fetch-fixtures.cmd @@ -1,16 +1,17 @@ @echo off -call:fetch_grammar embedded-template master -call:fetch_grammar javascript master -call:fetch_grammar json master +call:fetch_grammar bash master call:fetch_grammar c master call:fetch_grammar cpp master -call:fetch_grammar python master +call:fetch_grammar embedded-template master call:fetch_grammar go master -call:fetch_grammar ruby master -call:fetch_grammar typescript master -call:fetch_grammar bash master call:fetch_grammar html master +call:fetch_grammar javascript master +call:fetch_grammar json master +call:fetch_grammar python master +call:fetch_grammar ruby master +call:fetch_grammar rust master +call:fetch_grammar typescript master EXIT /B 0 :fetch_grammar diff --git a/script/fetch-test-fixtures.cmd b/script/fetch-test-fixtures.cmd deleted file mode 100755 index 33543961..00000000 --- a/script/fetch-test-fixtures.cmd +++ /dev/null @@ -1,16 +0,0 @@ -@Echo off -SETLOCAL - -Set grammar_dir=fixtures\tree-sitter-rust -Set grammar_url=https://github.com/tree-sitter/tree-sitter-rust - -@IF NOT EXIST %grammar_dir% ( - git clone %grammar_url% %grammar_dir% --depth=1 -) - -pushd %grammar_dir% -git fetch origin master --depth=1 -git reset --hard origin/master -popd - -ENDLOCAL diff --git a/script/fetch-test-fixtures.sh b/script/fetch-test-fixtures.sh deleted file mode 100755 index 24cc316a..00000000 --- a/script/fetch-test-fixtures.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -grammar_dir='fixtures/tree-sitter-rust' -grammar_url='https://github.com/tree-sitter/tree-sitter-rust' - -if [ ! -d $grammar_dir ]; then - git clone $grammar_url $grammar_dir --depth=1 -fi - -( - cd $grammar_dir; - git fetch origin master --depth=1 - git reset --hard origin/master; -)