@@ -92,8 +92,12 @@ pub fn fetch_grammars() -> Result<()> {
92 run_parallel(grammars, fetch_grammar, "fetch")
92 run_parallel(grammars, fetch_grammar, "fetch")
95−pub fn build_grammars() -> Result<()> {
95+pub fn build_grammars(target: Option<String>) -> Result<()> {
96− run_parallel(get_grammar_configs()?, build_grammar, "build")
97+ get_grammar_configs()?,
98+ move |grammar| build_grammar(grammar, target.as_deref()),
99// Returns the set of grammar configurations the user requests.
103// Returns the set of grammar configurations the user requests.
@@ -124,13 +128,14 @@ fn get_grammar_configs() -> Result<Vec<GrammarConfiguration>> {
125fn run_parallel<F>(grammars: Vec<GrammarConfiguration>, job: F, action: &'static str) -> Result<()>
129fn run_parallel<F>(grammars: Vec<GrammarConfiguration>, job: F, action: &'static str) -> Result<()>
127− F: Fn(GrammarConfiguration) -> Result<()> + std::marker::Send + 'static + Copy,
131+ F: Fn(GrammarConfiguration) -> Result<()> + std::marker::Send + 'static + Clone,
129 let pool = threadpool::Builder::new().build();
133 let pool = threadpool::Builder::new().build();
130 let (tx, rx) = channel();
134 let (tx, rx) = channel();
132 for grammar in grammars {
136 for grammar in grammars {
133 let tx = tx.clone();
137 let tx = tx.clone();
138+ let job = job.clone();
135 pool.execute(move || {
140 pool.execute(move || {
136 // Ignore any SendErrors, if any job in another thread has encountered an
141 // Ignore any SendErrors, if any job in another thread has encountered an
@@ -240,7 +245,7 @@ where
243−fn build_grammar(grammar: GrammarConfiguration) -> Result<()> {
248+fn build_grammar(grammar: GrammarConfiguration, target: Option<&str>) -> Result<()> {
244 let grammar_dir = if let GrammarSource::Local { path } = &grammar.source {
249 let grammar_dir = if let GrammarSource::Local { path } = &grammar.source {
245 PathBuf::from(&path)
250 PathBuf::from(&path)
@@ -273,10 +278,14 @@ fn build_grammar(grammar: GrammarConfiguration) -> Result<()> {
274 .join("src");
279 .join("src");
276− build_tree_sitter_library(&path, grammar)
281+ build_tree_sitter_library(&path, grammar, target)
279−fn build_tree_sitter_library(src_path: &Path, grammar: GrammarConfiguration) -> Result<()> {
284+fn build_tree_sitter_library(
286+ grammar: GrammarConfiguration,
287+ target: Option<&str>,
280 let header_path = src_path;
289 let header_path = src_path;
281 let parser_path = src_path.join("parser.c");
290 let parser_path = src_path.join("parser.c");
282 let mut scanner_path = src_path.join("scanner.c");
291 let mut scanner_path = src_path.join("scanner.c");
@@ -311,7 +320,7 @@ fn build_tree_sitter_library(src_path: &Path, grammar: GrammarConfiguration) ->
311 .opt_level(3)
320 .opt_level(3)
312 .cargo_metadata(false)
321 .cargo_metadata(false)
313 .host(BUILD_TARGET)
322 .host(BUILD_TARGET)
314− .target(BUILD_TARGET);
323+ .target(target.unwrap_or(BUILD_TARGET));
315 let compiler = config.get_compiler();
324 let compiler = config.get_compiler();
316 let mut command = Command::new(compiler.path());
325 let mut command = Command::new(compiler.path());
317 command.current_dir(src_path);
326 command.current_dir(src_path);