Correctly download libbinaryen.dylib on macos

master
printfn 3 years ago
parent f73b53c5ab
commit 30f2b0a262
  1. 6
      src/install/mod.rs
  2. 5
      src/wasm_opt.rs
  3. 27
      tests/all/download.rs

@ -148,7 +148,11 @@ pub fn download_prebuilt(
}
}
Tool::WasmOpt => {
let binaries = &["wasm-opt", "libbinaryen"];
let binaries: &[&str] = match Os::get()? {
Os::MacOS => &["bin/wasm-opt", "lib/libbinaryen.dylib"],
Os::Linux => &["bin/wasm-opt"],
Os::Windows => &["bin/wasm-opt.exe"],
};
match cache.download(install_permitted, "wasm-opt", binaries, &url)? {
Some(download) => Ok(Status::Found(download)),
// TODO(ag_dubs): why is this different? i forget...

@ -1,7 +1,7 @@
//! Support for downloading and executing `wasm-opt`
use crate::child;
use crate::install::{self, Tool};
use crate::install;
use crate::PBAR;
use anyhow::Result;
use binary_install::{Cache, Download};
@ -23,7 +23,7 @@ pub fn run(cache: &Cache, out_dir: &Path, args: &[String], install_permitted: bo
}
};
let wasm_opt_path = wasm_opt.binary(&Tool::WasmOpt.to_string())?;
let wasm_opt_path = wasm_opt.binary("bin/wasm-opt")?;
PBAR.info("Optimizing wasm binaries with `wasm-opt`...");
for file in out_dir.read_dir()? {
@ -36,7 +36,6 @@ pub fn run(cache: &Cache, out_dir: &Path, args: &[String], install_permitted: bo
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);
cmd.env("DYLD_LIBRARY_PATH", &wasm_opt_path.parent().unwrap());
child::run(cmd, "wasm-opt")?;
std::fs::rename(&tmp, &path)?;
}

@ -1,5 +1,3 @@
use binary_install::Cache;
use tempfile;
use wasm_pack::install::{self, Arch, Os, Tool};
#[test]
@ -10,7 +8,7 @@ use wasm_pack::install::{self, Arch, Os, Tool};
))]
fn can_download_prebuilt_wasm_bindgen() {
let dir = tempfile::TempDir::new().unwrap();
let cache = Cache::at(dir.path());
let cache = binary_install::Cache::at(dir.path());
if let install::Status::Found(dl) =
install::download_prebuilt(&Tool::WasmBindgen, &cache, "0.2.74", true).unwrap()
{
@ -30,7 +28,7 @@ fn can_download_prebuilt_wasm_bindgen() {
fn downloading_prebuilt_wasm_bindgen_handles_http_errors() {
let dir = tempfile::TempDir::new().unwrap();
let bad_version = "0.2.74-some-trailing-version-stuff-that-does-not-exist";
let cache = Cache::at(dir.path());
let cache = binary_install::Cache::at(dir.path());
let result = install::download_prebuilt(&Tool::WasmBindgen, &cache, bad_version, true);
assert!(result.is_err());
let error = result.err().unwrap();
@ -47,7 +45,7 @@ fn downloading_prebuilt_wasm_bindgen_handles_http_errors() {
))]
fn can_download_prebuilt_cargo_generate() {
let dir = tempfile::TempDir::new().unwrap();
let cache = Cache::at(dir.path());
let cache = binary_install::Cache::at(dir.path());
if let install::Status::Found(dl) =
install::download_prebuilt(&Tool::CargoGenerate, &cache, "latest", true).unwrap()
{
@ -57,6 +55,25 @@ fn can_download_prebuilt_cargo_generate() {
}
}
#[test]
#[cfg(any(
all(target_os = "linux", target_arch = "x86_64"),
all(target_os = "macos", target_arch = "x86_64"),
all(target_os = "macos", target_arch = "aarch64"),
all(windows, target_arch = "x86_64"),
))]
fn can_download_prebuilt_wasm_opt() {
let dir = tempfile::TempDir::new().unwrap();
let cache = binary_install::Cache::at(dir.path());
if let install::Status::Found(dl) =
install::download_prebuilt(&Tool::WasmOpt, &cache, "latest", true).unwrap()
{
assert!(dl.binary("bin/wasm-opt").unwrap().is_file());
} else {
assert!(false, "Download Failed");
}
}
#[test]
fn all_latest_tool_download_urls_valid() {
let mut errors = Vec::new();

Loading…
Cancel
Save