Fix build-wasm on Windows

This commit is contained in:
Amin Yahyaabadi 2021-04-04 19:07:16 -05:00
parent 234bd79591
commit 919eab023f
3 changed files with 38 additions and 3 deletions

19
Cargo.lock generated
View file

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "0.7.15"
@ -180,6 +182,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "form_urlencoded"
version = "1.0.1"
@ -664,6 +672,7 @@ dependencies = [
"tree-sitter-tags",
"walkdir",
"webbrowser",
"which",
]
[[package]]
@ -835,6 +844,16 @@ dependencies = [
"winapi",
]
[[package]]
name = "which"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b55551e42cbdf2ce2bedd2203d0cc08dba002c27510f86dab6d0ce304cba3dfe"
dependencies = [
"either",
"libc",
]
[[package]]
name = "widestring"
version = "0.4.3"

View file

@ -38,6 +38,7 @@ smallbitvec = "2.3.0"
tiny_http = "0.8"
walkdir = "2.3"
webbrowser = "0.5.1"
which = "4.1.0"
[dependencies.tree-sitter]
version = ">= 0.17.0"

View file

@ -4,6 +4,7 @@ use std::ffi::{OsStr, OsString};
use std::fs;
use std::path::Path;
use std::process::Command;
use which::which;
pub fn get_grammar_name(src_dir: &Path) -> Result<String> {
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
let output_filename = format!("tree-sitter-{}.wasm", grammar_name);
let mut command;
if !force_docker && Command::new("emcc").output().is_ok() {
command = Command::new("emcc");
command.current_dir(&language_dir);
if !force_docker {
let emcc_bin;
if cfg!(windows) {
emcc_bin = "emcc.bat"
} else {
emcc_bin = "emcc"
};
let emcc_which = which(emcc_bin).unwrap();
let emcc_path = emcc_which.to_str().unwrap();
if Command::new(emcc_path).output().is_ok() {
command = Command::new(emcc_path);
command.current_dir(&language_dir);
} else {
return Error::err(
"You must have either emcc or docker on your PATH to run this command".to_string(),
);
}
} else if Command::new("docker").output().is_ok() {
command = Command::new("docker");
command.args(&["run", "--rm"]);