@@ -6,11 +6,13 @@ use std::{
66 process::Command,
77};
88
9−use std::sync::mpsc::channel;
9+use helix_core::syntax::DYLIB_EXTENSION;
1010
11−fn collect_tree_sitter_dirs(ignore: &[String]) -> Result<Vec<String>> {
11+const BUILD_TARGET: &str = env!("BUILD_TARGET");
12+
13+pub fn collect_tree_sitter_dirs(ignore: &[String]) -> Result<Vec<String>> {
1214 let mut dirs = Vec::new();
13− let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("languages");
15+ let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../helix-syntax/languages");
1416
1517 for entry in fs::read_dir(path)? {
1618 let entry = entry?;
@@ -32,12 +34,6 @@ fn collect_tree_sitter_dirs(ignore: &[String]) -> Result<Vec<String>> {
3234 Ok(dirs)
3335}
3436
35−#[cfg(unix)]
36−const DYLIB_EXTENSION: &str = "so";
37−
38−#[cfg(windows)]
39−const DYLIB_EXTENSION: &str = "dll";
40−
4137fn build_library(src_path: &Path, language: &str) -> Result<()> {
4238 let header_path = src_path;
4339 // let grammar_path = src_path.join("grammar.json");
@@ -65,7 +61,12 @@ fn build_library(src_path: &Path, language: &str) -> Result<()> {
6561 return Ok(());
6662 }
6763 let mut config = cc::Build::new();
68− config.cpp(true).opt_level(2).cargo_metadata(false);
64+ config
65+ .cpp(true)
66+ .opt_level(2)
67+ .cargo_metadata(false)
68+ .host(BUILD_TARGET)
69+ .target(BUILD_TARGET);
6970 let compiler = config.get_compiler();
7071 let mut command = Command::new(compiler.path());
7172 command.current_dir(src_path);
@@ -148,9 +149,10 @@ fn mtime(path: &Path) -> Result<SystemTime> {
148149 Ok(fs::metadata(path)?.modified()?)
149150}
150151
151−fn build_dir(dir: &str, language: &str) {
152+pub fn build_dir(dir: &str, language: &str) {
152153 println!("Build language {}", language);
153− if PathBuf::from("languages")
154+ if PathBuf::from(env!("CARGO_MANIFEST_DIR"))
155+ .join("../helix-syntax/languages")
154156 .join(dir)
155157 .read_dir()
156158 .unwrap()
@@ -158,49 +160,16 @@ fn build_dir(dir: &str, language: &str) {
158160 .is_none()
159161 {
160162 eprintln!(
161− "The directory {} is empty, you probably need to use 'git submodule update --init --recursive'?",
163+ "The directory {} is empty, you probably need to use './scripts/grammars sync'?",
162164 dir
163165 );
164166 std::process::exit(1);
165167 }
166168
167169 let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
168− .join("languages")
170+ .join("../helix-syntax/languages")
169171 .join(dir)
170172 .join("src");
171173
172174 build_library(&path, language).unwrap();
173175}
174−
175−fn main() {
176− let ignore = vec![
177− "tree-sitter-typescript".to_string(),
178− "tree-sitter-ocaml".to_string(),
179− ];
180− let dirs = collect_tree_sitter_dirs(&ignore).unwrap();
181−
182− let mut n_jobs = 0;
183− let pool = threadpool::Builder::new().build(); // by going through the builder, it'll use num_cpus
184− let (tx, rx) = channel();
185−
186− for dir in dirs {
187− let tx = tx.clone();
188− n_jobs += 1;
189−
190− pool.execute(move || {
191− let language = &dir.strip_prefix("tree-sitter-").unwrap();
192− build_dir(&dir, language);
193−
194− // report progress
195− tx.send(1).unwrap();
196− });
197− }
198− pool.join();
199− // drop(tx);
200− assert_eq!(rx.try_iter().sum::<usize>(), n_jobs);
201−
202− build_dir("tree-sitter-typescript/tsx", "tsx");
203− build_dir("tree-sitter-typescript/typescript", "typescript");
204− build_dir("tree-sitter-ocaml/ocaml", "ocaml");
205− build_dir("tree-sitter-ocaml/interface", "ocaml-interface")
206−}