Merge pull request #1044 from aminya/windows-build-wasm
Fix build-wasm on Windows
This commit is contained in:
commit
1ede51121b
3 changed files with 50 additions and 3 deletions
19
Cargo.lock
generated
19
Cargo.lock
generated
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ use super::generate::parse_grammar::GrammarJSON;
|
|||
use std::ffi::{OsStr, OsString};
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
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 +24,14 @@ 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_path = get_emcc_path();
|
||||
if emcc_path.is_ok() {
|
||||
command = Command::new(emcc_path.unwrap());
|
||||
command.current_dir(&language_dir);
|
||||
} else {
|
||||
return Err(emcc_path.unwrap_err());
|
||||
}
|
||||
} else if Command::new("docker").output().is_ok() {
|
||||
command = Command::new("docker");
|
||||
command.args(&["run", "--rm"]);
|
||||
|
|
@ -116,3 +123,23 @@ pub fn compile_language_to_wasm(language_dir: &Path, force_docker: bool) -> Resu
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_emcc_path() -> Result<PathBuf> {
|
||||
let emcc_bin;
|
||||
if cfg!(windows) {
|
||||
emcc_bin = "emcc.bat";
|
||||
} else {
|
||||
emcc_bin = "emcc";
|
||||
};
|
||||
let emcc_which = which(emcc_bin);
|
||||
let emcc_path;
|
||||
if emcc_which.is_ok() {
|
||||
emcc_path = emcc_which.unwrap();
|
||||
} else {
|
||||
return Error::err("emcc was not found on PATH".to_string());
|
||||
}
|
||||
if Command::new(&emcc_path).output().is_ok() {
|
||||
return Ok(emcc_path);
|
||||
}
|
||||
return Error::err("emcc binary doesn't work properly".to_string());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue