-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v0.11.0 Locally installed wasm-opt
not found
#1247
Comments
ad hoc fix (still passes all (src/wasm_opt.rs) //! Support for downloading and executing `wasm-opt`
use crate::child;
use crate::install;
use crate::PBAR;
use anyhow::Result;
use binary_install::Cache;
use std::path::Path;
use std::process::Command;
/// Execute `wasm-opt` over wasm binaries found in `out_dir`, downloading if
/// necessary into `cache`. Passes `args` to each invocation of `wasm-opt`.
pub fn run(cache: &Cache, out_dir: &Path, args: &[String], install_permitted: bool) -> Result<()> {
let wasm_opt_path = match find_wasm_opt(cache, install_permitted)? {
Status::Found(path) => path,
Status::Install(status) => match status {
install::Status::Found(dl) => dl.binary("bin/wasm-opt")?,
install::Status::CannotInstall => {
PBAR.info("Skipping wasm-opt as no downloading was requested");
return Ok(());
}
install::Status::PlatformNotSupported => {
PBAR.info("Skipping wasm-opt because it is not supported on this platform");
return Ok(());
}
},
};
PBAR.info("Optimizing wasm binaries with `wasm-opt`...");
for file in out_dir.read_dir()? {
let file = file?;
let path = file.path();
if path.extension().and_then(|s| s.to_str()) != Some("wasm") {
continue;
}
let tmp = path.with_extension("wasm-opt.wasm");
let mut cmd = Command::new(&wasm_opt_path);
cmd.arg(&path).arg("-o").arg(&tmp).args(args);
child::run(cmd, "wasm-opt")?;
std::fs::rename(&tmp, &path)?;
}
Ok(())
}
/// Possible outcomes of attempting to find/install `wasm-opt`
pub enum Status {
/// We found `wasm-opt` at the specified path (in PATH)
Found(std::path::PathBuf),
/// Installation results
Install(install::Status),
}
/// Attempts to find `wasm-opt` in `PATH` locally, or failing that downloads a
/// precompiled binary.
///
/// Returns `Some` if a binary was found or it was successfully downloaded.
/// Returns `None` if a binary wasn't found in `PATH` and this platform doesn't
/// have precompiled binaries. Returns an error if we failed to download the
/// binary.
pub fn find_wasm_opt(cache: &Cache, install_permitted: bool) -> Result<Status> {
// First attempt to look up in PATH. If found assume it works.
if let Ok(path) = which::which("wasm-opt") {
PBAR.info(&format!("found wasm-opt at {:?}", path));
return Ok(Status::Found(path));
}
Ok(Status::Install(install::download_prebuilt(
&install::Tool::WasmOpt,
cache,
"latest",
install_permitted,
)?))
} |
Same issue here on MacOS with
Looks like it is adding an extra Going to downgrade back to |
Temporary fix is to symlink |
This is a workaround for rustwasm/wasm-pack#1247, which causes `wasm-pack` to fail to run if a local version of `wasm-opt` is installed. That in turn caused the `build_examples` CI job to break. This PR fixes that by not having it download binaryen, instead letting `wasm-pack` install it itself, which still works.
* Don't install binaryen in CI This is a workaround for rustwasm/wasm-pack#1247, which causes `wasm-pack` to fail to run if a local version of `wasm-opt` is installed. That in turn caused the `build_examples` CI job to break. This PR fixes that by not having it download binaryen, instead letting `wasm-pack` install it itself, which still works. * Put back the binaryen-installing step, but only install wasm2js instead of the whole thing. I also updated to binaryen 112 while I was at it.
Added wasm-pack configuration and necessary dependencies to enhance the packaging of rust code to WebAssembly. This change was made due to rustwasm/wasm-pack#1247. Additionally, included 'worker' as a new dependency and adjusted the release profile to optimize for size and performance.
Added wasm-pack configuration and necessary dependencies to enhance the packaging of rust code to WebAssembly. This change was made due to rustwasm/wasm-pack#1247. Additionally, included 'worker' as a new dependency and adjusted the release profile to optimize for size and performance.
Added wasm-pack configuration and necessary dependencies to enhance the packaging of rust code to WebAssembly. This change was made due to rustwasm/wasm-pack#1247. Additionally, included 'worker' as a new dependency and adjusted the release profile to optimize for size and performance.
Motivated by this bug in v0.11.0: rustwasm/wasm-pack#1247
This issue still persists on Windows to this day, @drager |
Still an issue in 0.13.0? If so, please open a new issue. |
🐛 Bug description
When I run the command
wasm-pack build --target web
, I get an error that sayswasm-opt
is not found, even thoughwasm-opt
exists in PATH.The situation is similar to #1062, but the version (and possibly the cause) is different, so I have started a new issue.
See also: #1062 (comment) #1062 (comment)
🤔 Expected Behavior
The installed
wasm-opt
will be used👟 Steps to reproduce
run
cargo new --lib hello-wasm
and implement a simple projecthello-wasm
following MDN tutorialrun
wasm-pack build --target web
and get the following error🌍 Your environment
on Windows 10:
on Fedora 37:
The text was updated successfully, but these errors were encountered: