feat: support desktop
This commit is contained in:
1 parent
bb69a04045
commit
d695777402
4 files changed
+110
-80
No files matched your search
+80
-1
@@ -3,7 +3,11 @@ use crate::{
|
|||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
DioxusConfig,
|
DioxusConfig,
|
||||||
};
|
};
|
||||||
use std::process::Command;
|
use std::{
|
||||||
|
fs::{copy, create_dir_all, remove_dir_all},
|
||||||
|
path::PathBuf,
|
||||||
|
process::Command,
|
||||||
|
};
|
||||||
use wasm_bindgen_cli_support::Bindgen;
|
use wasm_bindgen_cli_support::Bindgen;
|
||||||
|
|
||||||
pub fn build(config: &CrateConfig) -> Result<()> {
|
pub fn build(config: &CrateConfig) -> Result<()> {
|
||||||
@@ -116,6 +120,81 @@ pub fn build(config: &CrateConfig) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn build_desktop(config: &CrateConfig) -> Result<()> {
|
||||||
|
log::info!("🚅 Running build [Desktop] command...");
|
||||||
|
|
||||||
|
let mut cmd = Command::new("cargo");
|
||||||
|
cmd.current_dir(&config.crate_dir)
|
||||||
|
.arg("build")
|
||||||
|
.stdout(std::process::Stdio::inherit())
|
||||||
|
.stderr(std::process::Stdio::inherit());
|
||||||
|
|
||||||
|
if config.release {
|
||||||
|
cmd.arg("--release");
|
||||||
|
}
|
||||||
|
|
||||||
|
match &config.executable {
|
||||||
|
crate::ExecutableType::Binary(name) => cmd.arg("--bin").arg(name),
|
||||||
|
crate::ExecutableType::Lib(name) => cmd.arg("--lib").arg(name),
|
||||||
|
crate::ExecutableType::Example(name) => cmd.arg("--example").arg(name),
|
||||||
|
};
|
||||||
|
|
||||||
|
let output = cmd.output()?;
|
||||||
|
|
||||||
|
if output.status.success() {
|
||||||
|
if config.out_dir.is_dir() {
|
||||||
|
remove_dir_all(&config.out_dir)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let release_type = match config.release {
|
||||||
|
true => "release",
|
||||||
|
false => "debug",
|
||||||
|
};
|
||||||
|
|
||||||
|
let file_name: String;
|
||||||
|
let mut res_path = match &config.executable {
|
||||||
|
crate::ExecutableType::Binary(name) | crate::ExecutableType::Lib(name) => {
|
||||||
|
file_name = name.clone();
|
||||||
|
config
|
||||||
|
.target_dir
|
||||||
|
.join(format!("{}", release_type))
|
||||||
|
.join(format!("{}", name))
|
||||||
|
}
|
||||||
|
crate::ExecutableType::Example(name) => {
|
||||||
|
file_name = name.clone();
|
||||||
|
config
|
||||||
|
.target_dir
|
||||||
|
.join(format!("{}", release_type))
|
||||||
|
.join("examples")
|
||||||
|
.join(format!("{}", name))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let target_file;
|
||||||
|
if cfg!(windows) {
|
||||||
|
res_path.set_extension("exe");
|
||||||
|
target_file = format!("{}.exe", &file_name);
|
||||||
|
} else {
|
||||||
|
target_file = file_name.clone();
|
||||||
|
}
|
||||||
|
create_dir_all(&config.out_dir)?;
|
||||||
|
copy(res_path, &config.out_dir.join(target_file))?;
|
||||||
|
|
||||||
|
log::info!(
|
||||||
|
"🚩 Build completed: [./{}]",
|
||||||
|
config
|
||||||
|
.dioxus_config
|
||||||
|
.application
|
||||||
|
.out_dir
|
||||||
|
.clone()
|
||||||
|
.unwrap_or(PathBuf::from("dist"))
|
||||||
|
.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn gen_page(config: &DioxusConfig, serve: bool) -> String {
|
pub fn gen_page(config: &DioxusConfig, serve: bool) -> String {
|
||||||
let mut html = String::from(include_str!("./assets/index.html"));
|
let mut html = String::from(include_str!("./assets/index.html"));
|
||||||
|
|
||||||
|
|||||||
+2
-78
@@ -1,12 +1,6 @@
|
|||||||
use std::{
|
use std::{io::Write, path::PathBuf};
|
||||||
fs::{copy, create_dir_all},
|
|
||||||
io::Write,
|
|
||||||
path::PathBuf,
|
|
||||||
process::Command,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{cfg::ConfigOptsBuild, gen_page};
|
use crate::{cfg::ConfigOptsBuild, gen_page};
|
||||||
use std::fs::remove_dir_all;
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
/// Build the Rust WASM app and all of its assets.
|
/// Build the Rust WASM app and all of its assets.
|
||||||
@@ -30,77 +24,7 @@ impl Build {
|
|||||||
|
|
||||||
if self.build.platform.is_some() {
|
if self.build.platform.is_some() {
|
||||||
if self.build.platform.unwrap().to_uppercase() == "DESKTOP" {
|
if self.build.platform.unwrap().to_uppercase() == "DESKTOP" {
|
||||||
log::info!("🚅 Running build [Desktop] command...");
|
crate::builder::build_desktop(&crate_config)?;
|
||||||
|
|
||||||
let mut cmd = Command::new("cargo");
|
|
||||||
cmd.current_dir(&crate_config.crate_dir)
|
|
||||||
.arg("build")
|
|
||||||
.stdout(std::process::Stdio::inherit())
|
|
||||||
.stderr(std::process::Stdio::inherit());
|
|
||||||
|
|
||||||
if self.build.release {
|
|
||||||
cmd.arg("--release");
|
|
||||||
}
|
|
||||||
|
|
||||||
match &crate_config.executable {
|
|
||||||
crate::ExecutableType::Binary(name) => cmd.arg("--bin").arg(name),
|
|
||||||
crate::ExecutableType::Lib(name) => cmd.arg("--lib").arg(name),
|
|
||||||
crate::ExecutableType::Example(name) => cmd.arg("--example").arg(name),
|
|
||||||
};
|
|
||||||
|
|
||||||
let output = cmd.output()?;
|
|
||||||
|
|
||||||
if output.status.success() {
|
|
||||||
if crate_config.out_dir.is_dir() {
|
|
||||||
remove_dir_all(&crate_config.out_dir)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let release_type = match crate_config.release {
|
|
||||||
true => "release",
|
|
||||||
false => "debug",
|
|
||||||
};
|
|
||||||
|
|
||||||
let file_name: String;
|
|
||||||
let mut res_path = match &crate_config.executable {
|
|
||||||
crate::ExecutableType::Binary(name) | crate::ExecutableType::Lib(name) => {
|
|
||||||
file_name = name.clone();
|
|
||||||
crate_config
|
|
||||||
.target_dir
|
|
||||||
.join(format!("{}", release_type))
|
|
||||||
.join(format!("{}", name))
|
|
||||||
}
|
|
||||||
crate::ExecutableType::Example(name) => {
|
|
||||||
file_name = name.clone();
|
|
||||||
crate_config
|
|
||||||
.target_dir
|
|
||||||
.join(format!("{}", release_type))
|
|
||||||
.join("examples")
|
|
||||||
.join(format!("{}", name))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let target_file;
|
|
||||||
if cfg!(windows) {
|
|
||||||
res_path.set_extension("exe");
|
|
||||||
target_file = format!("{}.exe", &file_name);
|
|
||||||
} else {
|
|
||||||
target_file = file_name.clone();
|
|
||||||
}
|
|
||||||
create_dir_all(&crate_config.out_dir)?;
|
|
||||||
copy(res_path, &crate_config.out_dir.join(target_file))?;
|
|
||||||
|
|
||||||
log::info!(
|
|
||||||
"🏛 Build completed: [:{}]",
|
|
||||||
&crate_config
|
|
||||||
.dioxus_config
|
|
||||||
.application
|
|
||||||
.out_dir
|
|
||||||
.unwrap_or(PathBuf::from("dist"))
|
|
||||||
.display()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ pub struct ConfigOptsServe {
|
|||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub release: bool,
|
pub release: bool,
|
||||||
|
|
||||||
|
/// Build platform: support Web & Desktop [default: "web"]
|
||||||
|
#[structopt(long)]
|
||||||
|
pub platform: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensure the given value for `--public-url` is formatted correctly.
|
/// Ensure the given value for `--public-url` is formatted correctly.
|
||||||
|
|||||||
+24
-1
@@ -1,5 +1,5 @@
|
|||||||
use crate::{cfg::ConfigOptsServe, gen_page, server, CrateConfig};
|
use crate::{cfg::ConfigOptsServe, gen_page, server, CrateConfig};
|
||||||
use std::{io::Write, path::PathBuf};
|
use std::{io::Write, path::PathBuf, process::Command};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
/// Run the WASM project on dev-server
|
/// Run the WASM project on dev-server
|
||||||
@@ -21,6 +21,29 @@ impl Serve {
|
|||||||
crate_config.as_example(self.serve.example.unwrap());
|
crate_config.as_example(self.serve.example.unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.serve.platform.is_some() {
|
||||||
|
if self.serve.platform.unwrap().to_uppercase() == "DESKTOP" {
|
||||||
|
crate::builder::build_desktop(&crate_config)?;
|
||||||
|
|
||||||
|
match &crate_config.executable {
|
||||||
|
crate::ExecutableType::Binary(name)
|
||||||
|
| crate::ExecutableType::Lib(name)
|
||||||
|
| crate::ExecutableType::Example(name) => {
|
||||||
|
let mut file = crate_config.out_dir.join(name);
|
||||||
|
if cfg!(windows) {
|
||||||
|
file.set_extension("exe");
|
||||||
|
}
|
||||||
|
Command::new(format!(
|
||||||
|
"{}",
|
||||||
|
crate_config.out_dir.join(file).to_str().unwrap()
|
||||||
|
))
|
||||||
|
.output()?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
crate::builder::build(&crate_config).expect("build failed");
|
crate::builder::build(&crate_config).expect("build failed");
|
||||||
|
|
||||||
// generate dev-index page
|
// generate dev-index page
|
||||||
|
|||||||
Reference in new issue
Block a user