feat: commit code
This commit is contained in:
1 parent
2e83822d41
commit
3514e34112
4 files changed
+56
-8
No files matched your search
+1
-1
@@ -42,4 +42,4 @@ script = []
|
|||||||
|
|
||||||
# use binaryen.wasm-opt for output Wasm file
|
# use binaryen.wasm-opt for output Wasm file
|
||||||
# binaryen just will trigger in `web` platform
|
# binaryen just will trigger in `web` platform
|
||||||
binaryen = { wasm_opt = [".PROJECT_OUT"] }
|
binaryen = { wasm_opt = true }
|
||||||
+25
-2
@@ -82,19 +82,42 @@ pub fn build(config: &CrateConfig) -> Result<()> {
|
|||||||
|
|
||||||
bindgen_builder
|
bindgen_builder
|
||||||
.input_path(input_path)
|
.input_path(input_path)
|
||||||
.web(true).unwrap()
|
.web(true)
|
||||||
|
.unwrap()
|
||||||
.debug(true)
|
.debug(true)
|
||||||
.demangle(true)
|
.demangle(true)
|
||||||
.keep_debug(true)
|
.keep_debug(true)
|
||||||
.remove_name_section(false)
|
.remove_name_section(false)
|
||||||
.remove_producers_section(false)
|
.remove_producers_section(false)
|
||||||
.out_name(&dioxus_config.application.name)
|
.out_name(&dioxus_config.application.name)
|
||||||
.generate(&bindgen_outdir).unwrap();
|
.generate(&bindgen_outdir)
|
||||||
|
.unwrap();
|
||||||
});
|
});
|
||||||
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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check binaryen:wasm-opt tool
|
||||||
|
let dioxus_tools = dioxus_config.application.tools.clone().unwrap_or_default();
|
||||||
|
if dioxus_tools.contains_key("binaryen") {
|
||||||
|
let info = dioxus_tools.get("binaryen").unwrap();
|
||||||
|
let binaryen = crate::tools::Tool::Binaryen;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
let target_file = out_dir
|
||||||
|
.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"])?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// this code will copy all public file to the output dir
|
// this code will copy all public file to the output dir
|
||||||
let copy_options = fs_extra::dir::CopyOptions {
|
let copy_options = fs_extra::dir::CopyOptions {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ impl Build {
|
|||||||
pub fn build(self) -> Result<()> {
|
pub fn build(self) -> Result<()> {
|
||||||
let mut crate_config = crate::CrateConfig::new()?;
|
let mut crate_config = crate::CrateConfig::new()?;
|
||||||
|
|
||||||
|
|
||||||
// change the release state.
|
// change the release state.
|
||||||
crate_config.with_release(self.build.release);
|
crate_config.with_release(self.build.release);
|
||||||
|
|
||||||
|
|||||||
+29
-5
@@ -1,6 +1,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{create_dir_all, File},
|
fs::{create_dir_all, File},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
|
process::Command,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
@@ -47,7 +48,6 @@ pub fn tools_path() -> PathBuf {
|
|||||||
|
|
||||||
#[allow(clippy::should_implement_trait)]
|
#[allow(clippy::should_implement_trait)]
|
||||||
impl Tool {
|
impl Tool {
|
||||||
|
|
||||||
/// from str to tool enum
|
/// from str to tool enum
|
||||||
pub fn from_str(name: &str) -> Option<Self> {
|
pub fn from_str(name: &str) -> Option<Self> {
|
||||||
match name {
|
match name {
|
||||||
@@ -152,12 +152,36 @@ impl Tool {
|
|||||||
let mut archive = Archive::new(tar);
|
let mut archive = Archive::new(tar);
|
||||||
archive.unpack(&tool_path)?;
|
archive.unpack(&tool_path)?;
|
||||||
// println!("{:?} -> {:?}", tool_path.join(dir_name), tool_path.join(self.name()));
|
// println!("{:?} -> {:?}", tool_path.join(dir_name), tool_path.join(self.name()));
|
||||||
std::fs::rename(
|
std::fs::rename(tool_path.join(dir_name), tool_path.join(self.name()))?;
|
||||||
tool_path.join(dir_name),
|
|
||||||
tool_path.join(self.name()),
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
Tool::Binaryen => {
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
format!("{}.exe", command)
|
||||||
|
} else {
|
||||||
|
command.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
command
|
||||||
|
.args(&args[..])
|
||||||
|
.stdout(std::process::Stdio::inherit())
|
||||||
|
.stderr(std::process::Stdio::inherit());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user