@@ -6,11 +6,13 @@ use std::{
6 process::Command,
6 process::Command,
9−use std::sync::mpsc::channel;
9+use helix_core::syntax::DYLIB_EXTENSION;
11+const BUILD_TARGET: &str = env!("BUILD_TARGET");
11−fn collect_tree_sitter_dirs(ignore: &[String]) -> Result<Vec<String>> {
13+pub fn collect_tree_sitter_dirs(ignore: &[String]) -> Result<Vec<String>> {
12 let mut dirs = Vec::new();
14 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");
15 for entry in fs::read_dir(path)? {
17 for entry in fs::read_dir(path)? {
16 let entry = entry?;
18 let entry = entry?;
@@ -32,12 +34,6 @@ fn collect_tree_sitter_dirs(ignore: &[String]) -> Result<Vec<String>> {
36−const DYLIB_EXTENSION: &str = "so";
39−const DYLIB_EXTENSION: &str = "dll";
41fn build_library(src_path: &Path, language: &str) -> Result<()> {
37fn build_library(src_path: &Path, language: &str) -> Result<()> {
42 let header_path = src_path;
38 let header_path = src_path;
43 // let grammar_path = src_path.join("grammar.json");
39 // let grammar_path = src_path.join("grammar.json");
@@ -65,7 +61,12 @@ fn build_library(src_path: &Path, language: &str) -> Result<()> {
65 return Ok(());
61 return Ok(());
67 let mut config = cc::Build::new();
63 let mut config = cc::Build::new();
68− config.cpp(true).opt_level(2).cargo_metadata(false);
67+ .cargo_metadata(false)
69+ .target(BUILD_TARGET);
69 let compiler = config.get_compiler();
70 let compiler = config.get_compiler();
70 let mut command = Command::new(compiler.path());
71 let mut command = Command::new(compiler.path());
71 command.current_dir(src_path);
72 command.current_dir(src_path);
@@ -148,9 +149,10 @@ fn mtime(path: &Path) -> Result<SystemTime> {
148 Ok(fs::metadata(path)?.modified()?)
149 Ok(fs::metadata(path)?.modified()?)
151−fn build_dir(dir: &str, language: &str) {
152+pub fn build_dir(dir: &str, language: &str) {
152 println!("Build language {}", language);
153 println!("Build language {}", language);
153− if PathBuf::from("languages")
154+ if PathBuf::from(env!("CARGO_MANIFEST_DIR"))
155+ .join("../helix-syntax/languages")
154 .join(dir)
156 .join(dir)
155 .read_dir()
157 .read_dir()
156 .unwrap()
158 .unwrap()
@@ -158,49 +160,16 @@ fn build_dir(dir: &str, language: &str) {
158 .is_none()
160 .is_none()
160 eprintln!(
162 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'?",
164 std::process::exit(1);
166 std::process::exit(1);
167 let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
169 let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
168− .join("languages")
170+ .join("../helix-syntax/languages")
169 .join(dir)
171 .join(dir)
170 .join("src");
172 .join("src");
172 build_library(&path, language).unwrap();
174 build_library(&path, language).unwrap();
177− "tree-sitter-typescript".to_string(),
178− "tree-sitter-ocaml".to_string(),
180− let dirs = collect_tree_sitter_dirs(&ignore).unwrap();
183− let pool = threadpool::Builder::new().build(); // by going through the builder, it'll use num_cpus
184− let (tx, rx) = channel();
187− let tx = tx.clone();
190− pool.execute(move || {
191− let language = &dir.strip_prefix("tree-sitter-").unwrap();
192− build_dir(&dir, language);
195− tx.send(1).unwrap();
200− assert_eq!(rx.try_iter().sum::<usize>(), n_jobs);
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")