From 62a2292c16e54fe46c1438d7629ed67831eb5018 Mon Sep 17 00:00:00 2001 From: mrxiaozhuox Date: Tue, 15 Mar 2022 17:32:42 +0800 Subject: [PATCH] feat: commit code --- src/builder.rs | 18 +++++++++++++++--- src/tools.rs | 14 +++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 870e737f0..ac9f72b13 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -95,6 +95,7 @@ pub fn build(config: &CrateConfig) -> Result<()> { }); if bindgen_result.is_err() { log::error!("Bindgen build failed! \nThis is probably due to the Bindgen version, dioxus-cli using `0.2.79` Bindgen crate."); + return Ok(()); } // check binaryen:wasm-opt tool @@ -102,8 +103,13 @@ pub fn build(config: &CrateConfig) -> Result<()> { if dioxus_tools.contains_key("binaryen") { let info = dioxus_tools.get("binaryen").unwrap(); let binaryen = crate::tools::Tool::Binaryen; + + if !binaryen.is_installed() { + log::error!("Binaryen tool not found, you can use `dioxus tool add binaryen` to install it."); + return Ok(()); + } + if let Some(sub) = info.as_table() { - println!("sub: {sub:?}"); if sub.contains_key("wasm_opt") && sub.get("wasm_opt").unwrap().as_bool().unwrap_or(false) { @@ -111,9 +117,15 @@ pub fn build(config: &CrateConfig) -> Result<()> { .join("assets") .join("dioxus") .join(format!("{}_bg.wasm", dioxus_config.application.name)); - println!("tf: {target_file:?}"); if target_file.is_file() { - binaryen.call("wasm-opt", vec![target_file.to_str().unwrap(), "--print"])?; + binaryen.call( + "wasm-opt", + vec![ + target_file.to_str().unwrap(), + "-o", + target_file.to_str().unwrap(), + ], + )?; } } } diff --git a/src/tools.rs b/src/tools.rs index b84cd5579..937063be0 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -158,7 +158,7 @@ impl Tool { Ok(()) } - pub fn call(&self, command: &str, args: Vec<&str>) -> anyhow::Result<()> { + pub fn call(&self, command: &str, args: Vec<&str>) -> anyhow::Result> { let bin_path = tools_path().join(self.name()).join(self.bin_path()); let command_file = match self { @@ -171,17 +171,17 @@ impl Tool { } }; - if !bin_path.join(command_file).is_file() { + if !bin_path.join(&command_file).is_file() { return Err(anyhow::anyhow!("Command file not found.")); } - let mut command = Command::new(bin_path.to_str().unwrap()); + let mut command = Command::new(bin_path.join(&command_file).to_str().unwrap()); - command + let output = command .args(&args[..]) .stdout(std::process::Stdio::inherit()) - .stderr(std::process::Stdio::inherit()); - - Ok(()) + .stderr(std::process::Stdio::inherit()) + .output()?; + Ok(output.stdout) } }