Fix build-wasm command on latest emscripten

This commit is contained in:
Max Brunsfeld 2020-05-12 15:42:11 -07:00
parent da7bf8debb
commit cdc973866f
2 changed files with 16 additions and 24 deletions

View file

@ -759,7 +759,7 @@ impl Generator {
&& state.terminal_entries.len() == 1
&& *state.terminal_entries.iter().next().unwrap().0 == Symbol::end()
{
add_line!(self, "[{}] = {{-1}},", i,);
add_line!(self, "[{}] = {{(TSStateId)(-1)}},", i,);
} else if state.external_lex_state_id > 0 {
add_line!(
self,

View file

@ -59,7 +59,9 @@ pub fn compile_language_to_wasm(language_dir: &Path, force_docker: bool) -> Resu
// Run `emcc` in a container using the `emscripten-slim` image
command.args(&["trzeci/emscripten-slim", "emcc"]);
} else {
return Error::err("You must have either emcc or docker on your PATH to run this command".to_string());
return Error::err(
"You must have either emcc or docker on your PATH to run this command".to_string(),
);
}
command.args(&[
@ -81,31 +83,21 @@ pub fn compile_language_to_wasm(language_dir: &Path, force_docker: bool) -> Resu
"src",
]);
// Find source files to pass to emscripten
let src_entries = fs::read_dir(&src_dir).map_err(Error::wrap(|| {
format!("Failed to read source directory {:?}", src_dir)
}))?;
let parser_c_path = src_dir.join("parser.c");
let scanner_c_path = src_dir.join("scanner.c");
let scanner_cc_path = src_dir.join("scanner.cc");
let scanner_cpp_path = src_dir.join("scanner.cpp");
for entry in src_entries {
let entry = entry?;
let file_name = entry.file_name();
// Do not compile the node.js binding file.
if file_name
.to_str()
.map_or(false, |s| s.starts_with("binding"))
{
continue;
}
// Compile any .c, .cc, or .cpp files
if let Some(extension) = Path::new(&file_name).extension().and_then(|s| s.to_str()) {
if extension == "c" || extension == "cc" || extension == "cpp" {
command.arg(Path::new("src").join(entry.file_name()));
}
}
if scanner_cc_path.exists() {
command.arg("-xc++").arg(&scanner_cc_path);
} else if scanner_cpp_path.exists() {
command.arg("-xc++").arg(&scanner_cpp_path);
} else if scanner_c_path.exists() {
command.arg(&scanner_c_path);
}
command.arg(&parser_c_path);
let output = command
.output()
.map_err(Error::wrap(|| "Failed to run emcc command"))?;