bytecodealliance / cargo-wasi

A lightweight Cargo subcommand to build Rust code for the `wasm32-wasi` target
https://bytecodealliance.github.io/cargo-wasi/
Apache License 2.0
444 stars 29 forks source link

Refactor get_tool and run_or_download logic #117

Closed jeffcharles closed 2 years ago

jeffcharles commented 2 years ago

Context

To have a downloaded wasm-opt work correctly on MacOS, multiple files need to be extracted (the binary and the binaryen dylib) and those files have to extracted into different directories. Specifically the binaryen archive needs to be extracted into an adjacent lib directory. This seems to necessitate having get_wasm_opt return a cache path that would be an ancestor of the path to the executable file. Logic in run_or_download relies on the path to the binary and the cache path being the same to detect if the path to the tool has been overridden. Switching get_wasm_opt to return an ancestor path of the executable would break this check.

What this PR does

To simplify upcoming PRs, I'd like to refactor the stack of code between get_tool and download_and_run logic to explicitly track whether the path to the executable has been overridden. Replacing the current requested != cache_path check will be necessary if cache_path will have to be different than requested in a situation where there isn't an override.

Why this approach

The cache_path doesn't seem to be used outside the check to see if the path has been overridden. So replacing it with a boolean simplifies the data being passed around.

Alternatives I've considered

alexcrichton commented 2 years ago

Seems reasonable to me, thanks!