mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-24 05:03:06 +00:00
feat: commit code
This commit is contained in:
parent
3514e34112
commit
62a2292c16
2 changed files with 22 additions and 10 deletions
|
@ -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(),
|
||||
],
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
src/tools.rs
14
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<Vec<u8>> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue