Skip to content

Commit

Permalink
cleanup: remain compatible with old releases
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko committed Oct 17, 2024
1 parent ce41044 commit 7c6553d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions bin/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) struct Optimizer<'a> {
}

fn find_deps() -> PathBuf {
if let Ok(path) = std::env::var("EXTISM_PYTHON_USR_DIR") {
if let Ok(path) = std::env::var("EXTISM_PYTHON_WASI_DEPS_DIR") {
return PathBuf::from(path);
}

Expand Down Expand Up @@ -63,14 +63,25 @@ impl<'a> Optimizer<'a> {
pub fn write_optimized_wasm(self, dest: impl AsRef<Path>) -> Result<(), Error> {
let python_path = std::env::var("PYTHONPATH").unwrap_or_else(|_| String::from("."));
let paths: Vec<&str> = python_path.split(':').collect();

// Ensure compatibility with old releases
let mut deps = find_deps().join("usr");
if !deps.exists() {
let parent = deps.parent().unwrap();
if parent.join("local").exists() {
deps = parent.to_path_buf();
} else {
anyhow::bail!("wasi-deps path doesn't exist: {}", deps.display());
}
}

if self.wizen {
println!("DEPS IN: {:?}", find_deps());
let mut w = Wizer::new();
w.allow_wasi(true)?
.inherit_stdio(true)
.inherit_env(true)
.wasm_bulk_memory(true)
.map_dir("/usr", find_deps().join("usr"));
.map_dir("/usr", deps);
for path in paths {
if path.is_empty() {
continue;
Expand Down

0 comments on commit 7c6553d

Please sign in to comment.