@@ -8,6 +8,7 @@ use std::{
8 process::Command,
8 process::Command,
9 sync::mpsc::channel,
9 sync::mpsc::channel,
11+use tempfile::TempPath;
11use tree_sitter::Language;
12use tree_sitter::Language;
13#[cfg(unix)]
14#[cfg(unix)]
@@ -446,13 +447,17 @@ fn build_tree_sitter_library(
446 command.env(key, value);
447 command.env(key, value);
448 command.args(compiler.args());
449 command.args(compiler.args());
450+ // used to delay dropping the temporary object file until after the compilation is complete
450 if cfg!(all(windows, target_env = "msvc")) {
453 if cfg!(all(windows, target_env = "msvc")) {
452 .args(["/nologo", "/LD", "/I"])
455 .args(["/nologo", "/LD", "/I"])
453 .arg(header_path)
456 .arg(header_path)
454 .arg("/Od")
457 .arg("/Od")
455− .arg("/utf-8");
458+ .arg("/utf-8")
456 if let Some(scanner_path) = scanner_path.as_ref() {
461 if let Some(scanner_path) = scanner_path.as_ref() {
457 command.arg(scanner_path);
462 command.arg(scanner_path);
@@ -466,20 +471,49 @@ fn build_tree_sitter_library(
466 .arg("-shared")
471 .arg("-shared")
467 .arg("-fPIC")
472 .arg("-fPIC")
468 .arg("-fno-exceptions")
473 .arg("-fno-exceptions")
470 .arg("-I")
474 .arg("-I")
471 .arg(header_path)
475 .arg(header_path)
472 .arg("-o")
476 .arg("-o")
473− .arg(&library_path)
477+ .arg(&library_path);
475 if let Some(scanner_path) = scanner_path.as_ref() {
479 if let Some(scanner_path) = scanner_path.as_ref() {
476 if scanner_path.extension() == Some("c".as_ref()) {
480 if scanner_path.extension() == Some("c".as_ref()) {
477− command.arg("-xc").arg("-std=c99").arg(scanner_path);
481+ command.arg("-xc").arg("-std=c11").arg(scanner_path);
483+ let mut cpp_command = Command::new(compiler.path());
484+ cpp_command.current_dir(src_path);
485+ for (key, value) in compiler.env() {
486+ cpp_command.env(key, value);
488+ cpp_command.args(compiler.args());
490+ library_path.with_file_name(format!("{}_scanner.o", &grammar.grammar_id));
493+ .arg("-fno-exceptions")
479− command.arg(scanner_path);
500+ .arg(scanner_path);
501+ let output = cpp_command
503+ .context("Failed to execute C++ compiler")?;
504+ if !output.status.success() {
506+ "Parser compilation failed.\nStdout: {}\nStderr: {}",
507+ String::from_utf8_lossy(&output.stdout),
508+ String::from_utf8_lossy(&output.stderr)
512+ command.arg(&object_file);
513+ _path_guard = TempPath::from_path(object_file);
482− command.arg("-xc").arg(parser_path);
516+ command.arg("-xc").arg("-std=c11").arg(parser_path);
483 if cfg!(all(
517 if cfg!(all(
485 not(any(target_os = "macos", target_os = "illumos"))
519 not(any(target_os = "macos", target_os = "illumos"))