Merge pull request #3181 from tree-sitter/handle-wasm-oom

When loading languages via WASM, gracefully handle memory errors and leaks in external scanners
This commit is contained in:
Max Brunsfeld 2024-03-18 13:15:06 -07:00 committed by GitHub
commit 09b18fad5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 1895 additions and 2463 deletions

View file

@ -4,18 +4,6 @@ use std::{env, fs};
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
println!("cargo:rerun-if-env-changed=TREE_SITTER_STATIC_ANALYSIS");
if env::var("TREE_SITTER_STATIC_ANALYSIS").is_ok() {
if let (Some(clang_path), Some(scan_build_path)) = (which("clang"), which("scan-build")) {
let clang_path = clang_path.to_str().unwrap();
let scan_build_path = scan_build_path.to_str().unwrap();
env::set_var(
"CC",
format!("{scan_build_path} -analyze-headers --use-analyzer={clang_path} cc",),
);
}
}
#[cfg(feature = "bindgen")]
generate_bindings(&out_dir);
@ -96,16 +84,3 @@ fn generate_bindings(out_dir: &Path) {
.write_to_file(&bindings_rs)
.unwrap_or_else(|_| panic!("Failed to write bindings into path: {bindings_rs:?}"));
}
fn which(exe_name: impl AsRef<Path>) -> Option<PathBuf> {
env::var_os("PATH").and_then(|paths| {
env::split_paths(&paths).find_map(|dir| {
let full_path = dir.join(&exe_name);
if full_path.is_file() {
Some(full_path)
} else {
None
}
})
})
}