Skip to content

Commit 00986fe

Browse files
pascalkuthewes-adams
authored andcommitted
fix windows build (helix-editor#6834)
1 parent 978351c commit 00986fe

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

helix-loader/src/grammar.rs

+34-2
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,42 @@ fn build_tree_sitter_library(
443443
.arg(header_path)
444444
.arg("/Od")
445445
.arg("/utf-8")
446-
.arg("/std:c++14")
447446
.arg("/std:c11");
448447
if let Some(scanner_path) = scanner_path.as_ref() {
449-
command.arg(scanner_path);
448+
if scanner_path.extension() == Some("c".as_ref()) {
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+
}
450482
}
451483

452484
command

0 commit comments

Comments
 (0)