浏览代码

feat: commit code

mrxiaozhuox 3 年之前
父节点
当前提交
62a2292c16
共有 2 个文件被更改,包括 22 次插入10 次删除
  1. 15 3
      src/builder.rs
  2. 7 7
      src/tools.rs

+ 15 - 3
src/builder.rs

@@ -95,6 +95,7 @@ pub fn build(config: &CrateConfig) -> Result<()> {
     });
     });
     if bindgen_result.is_err() {
     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.");
         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
     // check binaryen:wasm-opt tool
@@ -102,8 +103,13 @@ pub fn build(config: &CrateConfig) -> Result<()> {
     if dioxus_tools.contains_key("binaryen") {
     if dioxus_tools.contains_key("binaryen") {
         let info = dioxus_tools.get("binaryen").unwrap();
         let info = dioxus_tools.get("binaryen").unwrap();
         let binaryen = crate::tools::Tool::Binaryen;
         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() {
         if let Some(sub) = info.as_table() {
-            println!("sub: {sub:?}");
             if sub.contains_key("wasm_opt")
             if sub.contains_key("wasm_opt")
                 && sub.get("wasm_opt").unwrap().as_bool().unwrap_or(false)
                 && sub.get("wasm_opt").unwrap().as_bool().unwrap_or(false)
             {
             {
@@ -111,9 +117,15 @@ pub fn build(config: &CrateConfig) -> Result<()> {
                     .join("assets")
                     .join("assets")
                     .join("dioxus")
                     .join("dioxus")
                     .join(format!("{}_bg.wasm", dioxus_config.application.name));
                     .join(format!("{}_bg.wasm", dioxus_config.application.name));
-                println!("tf: {target_file:?}");
                 if target_file.is_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(),
+                        ],
+                    )?;
                 }
                 }
             }
             }
         }
         }

+ 7 - 7
src/tools.rs

@@ -158,7 +158,7 @@ impl Tool {
         Ok(())
         Ok(())
     }
     }
 
 
-    pub fn call(&self, command: &str, args: Vec<&str>) -> anyhow::Result<()> {
+    pub fn call(&self, command: &str, args: Vec<&str>) -> anyhow::Result<Vec<u8>> {
         let bin_path = tools_path().join(self.name()).join(self.bin_path());
         let bin_path = tools_path().join(self.name()).join(self.bin_path());
 
 
         let command_file = match self {
         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."));
             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[..])
             .args(&args[..])
             .stdout(std::process::Stdio::inherit())
             .stdout(std::process::Stdio::inherit())
-            .stderr(std::process::Stdio::inherit());
-
-        Ok(())
+            .stderr(std::process::Stdio::inherit())
+            .output()?;
+        Ok(output.stdout)
     }
     }
 }
 }