on master help sign in
fix windows build (#6834)
13cc44cPascal Kuthe
helix-loader/src/grammar.rs+34−2
@@ -443,10 +443,42 @@ fn build_tree_sitter_library(
443 .arg(header_path)
443 .arg(header_path)
444 .arg("/Od")
444 .arg("/Od")
445 .arg("/utf-8")
445 .arg("/utf-8")
446− .arg("/std:c++14")
447 .arg("/std:c11");
446 .arg("/std:c11");
448 if let Some(scanner_path) = scanner_path.as_ref() {
447 if let Some(scanner_path) = scanner_path.as_ref() {
448+ if scanner_path.extension() == Some("c".as_ref()) {
449− command.arg(scanner_path);
449+ command.arg(scanner_path);
450+ } else {
451+ let mut cpp_command = Command::new(compiler.path());
452+ cpp_command.current_dir(src_path);
453+ for (key, value) in compiler.env() {
454+ cpp_command.env(key, value);
455+ }
456+ cpp_command.args(compiler.args());
457+ let object_file =
458+ library_path.with_file_name(format!("{}_scanner.o", &grammar.grammar_id));
459+ cpp_command
460+ .args(["/nologo", "/LD", "/I"])
461+ .arg(header_path)
462+ .arg("/Od")
463+ .arg("/utf-8")
464+ .arg("/std:c++14")
465+ .arg("/o")
466+ .arg(&object_file)
467+ .arg("/c")
468+ .arg(scanner_path);
469+ let output = cpp_command
470+ .output()
471+ .context("Failed to execute C++ compiler")?;
472+ if !output.status.success() {
473+ return Err(anyhow!(
474+ "Parser compilation failed.\nStdout: {}\nStderr: {}",
475+ String::from_utf8_lossy(&output.stdout),
476+ String::from_utf8_lossy(&output.stderr)
477+ ));
478+ }
479+ command.arg(&object_file);
480+ _path_guard = TempPath::from_path(object_file);
481+ }
450 }
482 }
451
483
452 command
484 command