Skip to content

Commit 919eab0

Browse files
committed
Fix build-wasm on Windows
1 parent 234bd79 commit 919eab0

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ smallbitvec = "2.3.0"
3838
tiny_http = "0.8"
3939
walkdir = "2.3"
4040
webbrowser = "0.5.1"
41+
which = "4.1.0"
4142

4243
[dependencies.tree-sitter]
4344
version = ">= 0.17.0"

cli/src/wasm.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::ffi::{OsStr, OsString};
44
use std::fs;
55
use std::path::Path;
66
use std::process::Command;
7+
use which::which;
78

89
pub fn get_grammar_name(src_dir: &Path) -> Result<String> {
910
let grammar_json_path = src_dir.join("grammar.json");
@@ -22,9 +23,23 @@ pub fn compile_language_to_wasm(language_dir: &Path, force_docker: bool) -> Resu
2223
let output_filename = format!("tree-sitter-{}.wasm", grammar_name);
2324

2425
let mut command;
25-
if !force_docker && Command::new("emcc").output().is_ok() {
26-
command = Command::new("emcc");
27-
command.current_dir(&language_dir);
26+
if !force_docker {
27+
let emcc_bin;
28+
if cfg!(windows) {
29+
emcc_bin = "emcc.bat"
30+
} else {
31+
emcc_bin = "emcc"
32+
};
33+
let emcc_which = which(emcc_bin).unwrap();
34+
let emcc_path = emcc_which.to_str().unwrap();
35+
if Command::new(emcc_path).output().is_ok() {
36+
command = Command::new(emcc_path);
37+
command.current_dir(&language_dir);
38+
} else {
39+
return Error::err(
40+
"You must have either emcc or docker on your PATH to run this command".to_string(),
41+
);
42+
}
2843
} else if Command::new("docker").output().is_ok() {
2944
command = Command::new("docker");
3045
command.args(&["run", "--rm"]);

0 commit comments

Comments
 (0)